ultralytics / yolov5

YOLOv5 πŸš€ in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.23k stars 16.44k forks source link

How to find how many images are generated after default data augmentation(mosaic) in yolov5 #9565

Closed ThiwankiDias closed 2 years ago

ThiwankiDias commented 2 years ago

Search before asking

Question

@glenn-jocher

Dear sir,

I m a begginer to yolov5 and object detection. I know yolov5 used data augmentation(mosaic) by defalt during training. but I have a question how to count how many images are generated during default data augmentation. Please help

Thank you so much

Additional

No response

glenn-jocher commented 2 years ago

@ThiwankiDias πŸ‘‹ Hello! Thanks for asking about image augmentation. YOLOv5 πŸš€ applies online imagespace and colorspace augmentations in the trainloader (but not the val_loader) to present a new and unique augmented Mosaic (original image + 3 random images) each time an image is loaded for training. Images are never presented twice in the same way.

YOLOv5 augmentation

Augmentation Hyperparameters

The hyperparameters used to define these augmentations are in your hyperparameter file (default data/hyp.scratch.yaml) defined when training:

python train.py --hyp hyp.scratch-low.yaml

https://github.com/ultralytics/yolov5/blob/b94b59e199047aa8bf2cdd4401ae9f5f42b929e6/data/hyps/hyp.scratch-low.yaml#L6-L34

Augmentation Previews

You can view the effect of your augmentation policy in your train_batch*.jpg images once training starts. These images will be in your train logging directory, typically yolov5/runs/train/exp:

train_batch0.jpg shows train batch 0 mosaics and labels:

YOLOv5 Albumentations Integration

YOLOv5 πŸš€ is now fully integrated with Albumentations, a popular open-source image augmentation package. Now you can train the world's best Vision AI models even better with custom Albumentations πŸ˜ƒ!

PR https://github.com/ultralytics/yolov5/pull/3882 implements this integration, which will automatically apply Albumentations transforms during YOLOv5 training if albumentations>=1.0.3 is installed in your environment. See https://github.com/ultralytics/yolov5/pull/3882 for full details.

Example train_batch0.jpg on COCO128 dataset with Blur, MedianBlur and ToGray. See the YOLOv5 Notebooks to reproduce: Open In Colab Open In Kaggle

Good luck πŸ€ and let us know if you have any other questions!

ThiwankiDias commented 2 years ago

Sir @glenn-jocher , It means like when we train yolov5 model if I have 50 train images after (mosaic) augmentation during training it will transform the training dataset into 200 images ?

github-actions[bot] commented 2 years ago

πŸ‘‹ Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 πŸš€ resources:

Access additional Ultralytics ⚑ resources:

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 YOLOv5 πŸš€ and Vision AI ⭐!

glenn-jocher commented 1 year ago

@ThiwankiDias yes, that’s correct! When training with the mosaic augmentation, YOLOv5 will virtually transform each original training image into 4 images (the original image plus 3 additional random images) for each iteration of training. This effectively increases the effective dataset size by 4x, meaning that your model will be able to learn from a much larger and more varied dataset during training. Let me know if you have any other questions!

AlejandroSilvaSerelabs commented 7 months ago

Hi! Can I set the number of the additional random images? Why three?

glenn-jocher commented 7 months ago

Hi there! πŸ‘‹

The choice of three additional images for the mosaic augmentation in YOLOv5 is based on the original design to form a 2x2 grid, hence one quadrant for the original and three for the randomly selected images.

Changing the number isn't directly supported without altering the source code. If you're interested in experimenting with a different setup, you would need to dive into the code where the mosaic is implemented and adjust the logic accordingly.

Happy experimenting, and feel free to share your findings or ask more questions if you need! 😊

AlejandroSilvaSerelabs commented 7 months ago

Hi @glenn-jocher

I think I didn't explain myself well, I understand that the mosaic is made with 4 images.

My question is, if I have a training dataset of N images, with the default data augmentation settings, how many images is the model trained with?

glenn-jocher commented 7 months ago

Hi there! 😊

Understood! With YOLOv5's mosaic augmentation, because it creates combinations in real-time during training (not pre-saving augmented images), the "number" of unique images the model is effectively trained on isn’t fixed. Each epoch can technically present your model with entirely unique combinations due to the random selection nature of mosaic augmentation.

If your dataset has N original images, instead of thinking in terms of a fixed number of augmented images, it's more accurate to say that your model will see a vast, dynamically generated set of image combinations across epochs. The exact number is not finite since the augmentation is on-the-fly and depends on the randomness of each epoch’s training iterations.

Hope that clarifies things! Let me know if you have more questions.