Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
unikill066 opened this issue Jan 5, 2024 · 4 comments
Closed
1 task done

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

unikill066 opened this issue Jan 5, 2024 · 4 comments
Labels
question Further information is requested Stale Stale and schedule for closing soon

Comments

@unikill066
Copy link

Search before asking

Question

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?

  1. python train.py --img 512 --batch 16 --epochs 1000 --data consider.yaml --weights yolov5s.pt --hyp hyp.scratch-med.yaml --cache --cuda

  2. python train.py --img 512 --batch 16 --epochs 1000 --data consider.yaml --weights yolov5s.pt --cache --cuda

Additional

No response

@unikill066 unikill066 added the question Further information is requested label Jan 5, 2024
@glenn-jocher
Copy link
Member

@unikill066 hello! Great to see you're experimenting with Albumentations for augmenting your dataset. 👍

When you integrate Albumentations into your training pipeline, you don't necessarily need to use the --hyp flag unless you want to adjust the hyperparameters defined in a specific hyperparameter file. The --hyp flag is used to specify a YAML file containing hyperparameters for training, such as learning rate, weight decay, etc., which are separate from the image augmentations you've set up with Albumentations.

If you're satisfied with the default hyperparameters or if you've already set your desired hyperparameters within your training script, you can train without the --hyp flag. Your Albumentations will still be applied.

So, if you're looking to use the default hyperparameters, you can go with your second command:

python train.py --img 512 --batch 16 --epochs 1000 --data consider.yaml --weights yolov5s.pt --cache --cuda

If you want to customize the hyperparameters, then include the --hyp flag with the appropriate YAML file:

python train.py --img 512 --batch 16 --epochs 1000 --data consider.yaml --weights yolov5s.pt --hyp hyp.scratch-med.yaml --cache --cuda

Remember to monitor your training to ensure that the augmentations are having the desired effect on your model's performance. Happy training! 😊

@unikill066
Copy link
Author

Thank you @glenn-jocher, I have used various percentages of albumentations; p = 0.01, 0.1, 0.2, 0.5 and 1.0 which I edited in the /utils/augmentations.py file, as shown above. However, the performance metrics for the models generated are rather same:
image

@glenn-jocher
Copy link
Member

@unikill066, it's interesting to see that the performance metrics are similar across different probabilities of augmentation. This could be due to several factors:

  1. Dataset Robustness: If your dataset is already diverse and robust, additional augmentations might not contribute significantly to performance improvements.
  2. Augmentation Balance: Too much augmentation can sometimes harm performance if it introduces too much noise or unrealistic variations.
  3. Model Capacity: The model's capacity might be such that it has reached a performance plateau given the current dataset and task complexity.
  4. Evaluation Metrics: Ensure that the evaluation metrics are sensitive enough to capture small performance differences.

It might be helpful to conduct further experiments, such as:

  • Analyzing the loss curves to see if there are differences in how the model converges.
  • Visualizing the augmented images to ensure that the augmentations are being applied as expected and are meaningful for the task.
  • Experimenting with a smaller subset of augmentations to isolate their effects.
  • Using a validation set with different characteristics from the training set to see if augmentations improve generalization.

Remember, the goal of augmentations is to improve the model's ability to generalize to new, unseen data, so it's also crucial to evaluate the model on an external test set if possible. Keep iterating, and good luck with your experiments! 🚀

Copy link
Contributor

github-actions bot commented Feb 8, 2024

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale Stale and schedule for closing soon label Feb 8, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale Stale and schedule for closing soon
Projects
None yet
Development

No branches or pull requests

2 participants