How to add additional augmentation to yolov8 model training

1.3k Views Asked by At

I have tried to modify existig augument.py code in yolov8 repository but it is still implementing the default albumentations while training. Is there any method to add additonal albumentations.

This is what i have tried to add additonal albumentations.

def __init__(self, p=1.0):
    """Initialize the transform object for YOLO bbox formatted params."""
    self.p = p
    self.transform = None
    prefix = colorstr('albumentations: ')
    try:
        import albumentations as A

        check_version(A.__version__, '1.0.3', hard=True)  # version requirement

        T = [
            A.Blur(p=0.01),
            A.MedianBlur(p=0.01),
            A.ToGray(p=0.01),
            A.CLAHE(p=0.01),
            A.RandomBrightnessContrast(p=0.5),
            A.RandomGamma(p=0.5),
            A.ImageCompression(quality_lower=75, p=0.5),
            A.MotionBlur(p=0.5, blur_limit=(3,9), always_apply=False)]  # 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}')

But i don't see "ImageCompression" and "MotionBlur" albumentation in training process.

2

There are 2 best solutions below

3
James Moore On
T = [
        A.Blur(p=0.01),
        A.MedianBlur(p=0.01),
        A.ToGray(p=0.01),
        A.CLAHE(p=0.01),
        A.RandomBrightnessContrast(p=0.5),
        A.RandomGamma(p=0.5),
        A.ImageCompression(quality_lower=75, p=0.5),
        A.MotionBlur(p=0.5, blur_limit=(3,9), always_apply=False)]  # transforms
]

Try changing the code above to the following.

T = [
         A.ImageCompression(quality_lower=75, p=0.5),
         A.MotionBlur(p=0.5, blur_limit=(3, 9), always_apply=False)
]
            
T += [
          A.Blur(p=0.01),
          A.MedianBlur(p=0.01),
          A.ToGray(p=0.01),
          A.CLAHE(p=0.01),
          A.RandomBrightnessContrast(p=0.5),
          A.RandomGamma(p=0.5)
]
0
bhavesh wadibhasme On

I have found the solution to the above problem.

step1:- Clone the yolov8 repository.

step2:- add change in augment.py file

step3:- run pip install e .

Step 4:- run the model training command given in the documentation of yolov8.