ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.54k stars 16.3k forks source link

A question about augmentation yolov5/utils/augmentations.py and yolov5/data/hyp.*.yaml files #9761

Closed frabob2017 closed 1 year ago

frabob2017 commented 2 years ago

Search before asking

Question

I check the yolov5/utils/augmentations.py. It looks that by default, there is a rotation of 10 degree for data augmentation. However, in yolov5/data/hyp.*.yaml files, I found that the rotation degree is 0 degree. In this situation, which one determine rotation will be used for augmentation? If I want to change rotation degree to 20 degree, do I need to change yolov5/utils/augmentations.py to set degrees=20 or how can I change it in command line?

def random_perspective(im, targets=(), segments=(), degrees=10, translate=.1, scale=.1, shear=10, perspective=0.0, border=(0, 0)):

Additional

No response

glenn-jocher commented 2 years ago

@frabob2017 hyp file sets rotation, yes you can just change to 20 deg and it will apply to training.

frabob2017 commented 2 years ago

@frabob2017 hyp file sets rotation, yes you can just change to 20 deg and it will apply to training.

There are multiple yolov5/data/hyp.*.yaml files, which one should I use? Does it depend on the model I use yolo5s, yolo5m, yolo5x etc? Now I use my own pre-trained weight. If I prefer to use yolov5/utils/augmentations.py? How to use this? I just set degrees=20 directly in this file?

image

glenn-jocher commented 2 years ago

You can see the default hyp file (low) used in train.py argparser. Higher augmentation reduces overfitting.

frabob2017 commented 2 years ago

You can see the default hyp file (low) used in train.py argparser. Higher augmentation reduces overfitting.

Is there any tutorials how to use yolov5/utils/augmentations.py, it seems that you recommend to use yolov5/data/hyp.*.yaml.

glenn-jocher commented 2 years ago

👋 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!

github-actions[bot] commented 1 year 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 ⭐!