pythonpython-3.xyoloyolov5

Do I use the `--hyp` for training YOLO-v5 model with Albumentations?


I have integrated various Albumentations into my YOLO-v5 model by modifying the augmentations.py file. In the Albumentations class, I have included a list of transformations.

Here is my code in the Albumentations class(/utils/augmentations.py):

class Albumentations:
    # YOLOv5 Albumentations class (optional, only used if package is installed)
    def __init__(self, size=640):
        self.transform = None
        prefix = colorstr('albumentations: ')
        try:
            import albumentations as A
            check_version(A.__version__, '1.0.3', hard=True)  # version requirement

            T = [
                A.RandomResizedCrop(height=size, width=size, scale=(0.8, 1.0), ratio=(0.9, 1.11), p=0.1),
                A.Blur(p=0.1),
                A.MedianBlur(p=0.1),
                A.ToGray(p=0.1),
                A.CLAHE(p=0.1),
                A.RandomBrightnessContrast(p=0.1),
                A.RandomGamma(p=0.1),
                A.ImageCompression(quality_lower=75, p=0.1),
                A.HueSaturationValue(hue_shift_limit=25, sat_shift_limit=40, val_shift_limit=0, p=0.1),
                A.ColorJitter(p=0.1), A.Defocus(p=0.1), A.Downscale(p=0.1), A.Emboss(p=0.1), 
                A.FancyPCA(p=0.1), A.GaussNoise(p=0.1), A.HueSaturationValue(p=0.1), A.ToRGB(p=0.1),
                A.ISONoise(p=0.1), A.ImageCompression(p=0.1), A.MultiplicativeNoise(p=0.1), 
                A.Posterize(p=0.1), A.RGBShift(p=0.1), A.RandomBrightnessContrast(p=0.1), A.CLAHE(p=0.1),
                A.RandomGamma(p=0.1), A.RingingOvershoot(p=0.1), A.Sharpen(p=0.1), A.UnsharpMask(p=0.1)
        ]  # transforms
            self.transform = A.Compose(T, bbox_params=A.BboxParams(format='yolo', label_fields=['class_labels']))

            LOGGER.info(prefix + ', '.join(f'{x}'.replace('always_apply=False, ', '') for x in T if x.p))
        except ImportError:  # package not installed, skip
            pass
        except Exception as e:
            LOGGER.info(f'{prefix}{e}')

When training a YOLO model with these Albumentations, do I need to include the --hyp option, or can I train without it while still incorporating the Albumentations into the training process?


Solution

  • The flag --hyp is basically used for adjusting the hyperparameters specified in the hyperparameter(.YAML) file.

    Command: python train.py --img 512 --batch 16 --epochs 1000 --data consider.yaml --weights yolov5s.pt --cache --cuda is enough to apply the albumentations, and respective p value should be edited in yolo-v5/utils/augmentations.py file - Albumentations class.

    The --hyp flag is used to specifically to set hyperparameters such as learning rate, etc. Here is the command for the same: python train.py --img 512 --batch 16 --epochs 1000 --data consider.yaml --weights yolov5s.pt --hyp hyp.scratch-med.yaml --cache --cuda.