ultralytics / yolov5

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

Limit creation of super small object by mosaic #6646

Closed hoangkhoiLE closed 2 years ago

hoangkhoiLE commented 2 years ago

Search before asking

Description

Hello,

I do several training with yolo v5, with a support of wandb for visualization, I can see that mosaic help us to do amazing augmentation, but some of those creates super small bounding box. Based on my knowledge, a object classed as small object in coco dataset having size is about less than 32 x 32, and usually the performance with this kind of object is not good ( @m.ap0.5:0.95 of this kind of object is smaller than medium and big object ). So I assume that with this kind of bounding box, in the process of mosaic, we would create a super hard object ( size less than 16x16), and usually we are not interest in this kind of too small object. Maybe, a parameters that control the creation of object with mosaic (or any kind of data augmentation) but assuring that the size of object is not too small ( more than 16x 16 for example ) would make an improvement in final result. Because we don't need to train on the object with 3x3 pixel for example. I glad to hear from you @glenn-jocher about my idea, and some steps to begin with it if possible !

Best regard

Use case

No response

Additional

No response

Are you willing to submit a PR?

glenn-jocher commented 2 years ago

@hoangkhoiLE mosaic just tiles images. Scaling images larger or smaller is done by the scale hyperparameter. You can modify all hyperparameters directly in your hyp yaml file. To disable scaling for example just reduce it from 0.5 to 0.0:

https://github.com/ultralytics/yolov5/blob/ca0a00784d99df3a89bf73c0847016b0d81a8e3e/data/hyps/hyp.scratch.yaml#L13-L34

glenn-jocher commented 2 years ago

@hoangkhoiLE πŸ‘‹ 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!

hoangkhoiLE commented 2 years ago

@glenn-jocher Thank you a lot for your help !