ultralytics / yolov5

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

augmentation process and focal loss #6503

Closed DP1701 closed 2 years ago

DP1701 commented 2 years ago

Search before asking

Question

Hello all, is it possible to see how many images the dataset has grown by after the augmentation process?

Additional

No response

glenn-jocher commented 2 years ago

@DP1701 πŸ‘‹ 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.yaml

https://github.com/ultralytics/yolov5/blob/90b7895d652c3bd3d361b2d6e9aee900fd67f5f7/data/hyp.scratch.yaml#L1-L33

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!

DP1701 commented 2 years ago

@glenn-jocher Thank you for the detailed explanation. This helps!

However, I still have a question: What do the values (fraction) for HSV-Hue, HSV-Saturation and HSV-Value augmentation mean? Unfortunately, I have not yet found an answer to this question.

glenn-jocher commented 2 years ago

@DP1701 these are fractional gains on each of the image HSV channels. The augmentation function in here: https://github.com/ultralytics/yolov5/blob/4c409332667477560200958b513b958bb8fdef71/utils/augmentations.py#L47-L61

DP1701 commented 2 years ago

@glenn-jocher Thank you for the explanation and the hint.

I have another question about focal loss. In the hyperparameterset I can change the gamma value, but where can I set the alpha values?

glenn-jocher commented 2 years ago

@DP1701 Focal Loss function with alpha is here: https://github.com/ultralytics/yolov5/blob/9bc72a3ac2253b96b006baaacf099ca4ace31a61/utils/loss.py#L35-L63

DP1701 commented 2 years ago

@glenn-jocher Ok, if I set the gamma value in the hyperparameterset to 0, then the default value of 1.5 is set to 0. But I have to change the alpha value directly in the function in line 37?

glenn-jocher commented 2 years ago

@DP1701 yes you just update alpha in the code if you want, it's not a hyperparameter.

DP1701 commented 2 years ago

@glenn-jocher Thanks for the clarification.

I have an unbalanced data set. So the option I think will help to compensate this. Or is there another better option?

Akshaysharma29 commented 2 years ago

Hi @glenn-jocher thanks for the explanations. I have two question

  1. if I do degrees: 90 in this file yolov5/data/hyp.scratch.yaml then the image will rotate from -90 to +90?
  2. What will be the probability of rotation?
glenn-jocher commented 2 years ago

@Akshaysharma29 yes, probability is 1.0

Akshaysharma29 commented 2 years ago

@glenn-jocher thanks for the responseπŸ™‚. what should I do if I only required 0,90,180 rotation, not any other rotation? any suggestion?

glenn-jocher commented 2 years ago

@Akshaysharma29 uncomment L145 here: https://github.com/ultralytics/yolov5/blob/07221f1591c0ce7544bd5abf343dac2987e1614e/utils/augmentations.py#L142-L149

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