ultralytics / yolov5

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

Small objects detection with custom dataset #6634

Closed litaldavar closed 2 years ago

litaldavar commented 2 years ago

Search before asking

Question

Hello

I'm trying to train a dataset with images of small beetles. after training I tried to detect a small beetle but got not detected Is there any way to use the model to train on small objects?

Thanks

Additional

No response

Sukeysun commented 2 years ago

Maybe you can try yolov5-p2 https://github.com/ultralytics/yolov5/blob/master/models/hub/yolov5-p2.yaml

litaldavar commented 2 years ago

Didn't work. still can't detect anything

glenn-jocher commented 2 years ago

@litaldavar ๐Ÿ‘‹ Hello! Thanks for asking about improving YOLOv5 ๐Ÿš€ training results. Detecting small objects is a default use case.

Most of the time good results can be obtained with no changes to the models or training settings, provided your dataset is sufficiently large and well labelled. If at first you don't get good results, there are steps you might be able to take to improve, but we always recommend users first train with all default settings before considering any changes. This helps establish a performance baseline and spot areas for improvement.

If you have questions about your training results we recommend you provide the maximum amount of information possible if you expect a helpful response, including results plots (train losses, val losses, P, R, mAP), PR curve, confusion matrix, training mosaics, test results and dataset statistics images such as labels.png. All of these are located in your project/name directory, typically yolov5/runs/train/exp.

We've put together a full guide for users looking to get the best results on their YOLOv5 trainings below.

Dataset

COCO Analysis

Model Selection

Larger models like YOLOv5x and YOLOv5x6 will produce better results in nearly all cases, but have more parameters, require more CUDA memory to train, and are slower to run. For mobile deployments we recommend YOLOv5s/m, for cloud deployments we recommend YOLOv5l/x. See our README table for a full comparison of all models.

YOLOv5 Models

Training Settings

Before modifying anything, first train with default settings to establish a performance baseline. A full list of train.py settings can be found in the train.py argparser.

Further Reading

If you'd like to know more a good place to start is Karpathy's 'Recipe for Training Neural Networks', which has great ideas for training that apply broadly across all ML domains: http://karpathy.github.io/2019/04/25/recipe/

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

UygarUsta99 commented 2 years ago

Usually when it comes to small object detection training and inferencing with high resolution works.You can try models that was trained on high resolutions like s6,m6 etc. Also I would recommend you to take a look at tensorflow's Help Protect the Great Barrier Reef competition on Kaggle where objects are so small that they are barely detectable.As far as I know top solutions are yolov5 with high resolution training and inferencing.I think taking a look at some notebooks and discussions may help.

VincentDecospan commented 2 years ago

The minimum area of boundingboxes is set with a threshold, please look at utils > augmentations.py > def box_candidates area_thr parameter & change it accordingly, this will ensure good training and interferece on small objects

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 โญ!

ybonzou commented 2 years ago

Hi Gleen๏ผwhat's up!! n Happy belated 41st birthday! Wishing you a very lucky year!

Tell me please, you said, ใ€ŽBackground images are images with no objectsใ€ "Background images. ใ€ŽBackground images are images with no objectsใ€ that are added to a dataset to reduce False Positives (FP). We recommend about 0-10% background images to help reduce FPs (COCO has 1000 background images for reference, 1% of the total). No labels are required for background images."
is mean "Is it an image without objects?" Or, "Is it an image part that does not contain an object?"

And "Is it an image without objects?"ใŒใ€ๆญฃใ—ใ„ๅ ดๅˆใ€ can yolov5 data text be learned in blank?

glenn-jocher commented 2 years ago

@ybonzou thank you! A background image just contains no objects from the dataset you are training. So for example if you train on people, a background image is any image that has no people.

ybonzou commented 2 years ago

Hi Mr.Glenn, thank you for your reply!!

Cong-Wan commented 1 year ago

dear sir, Borrowing from this question, I would like to know whether images with empty labels are classified as background images or not.

Secondly, after data augmented, will the original image also be treated as the training image?

like this data augmentation tips๏ผš

perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 flipud: 0.0 # image flip up-down (probability) fliplr: 0.5 # image flip left-right (probability) mosaic: 1.0 # image mosaic (probability) mixup: 0.0 # image mixup (probability)

glenn-jocher commented 1 year ago

@Cong-Wan ๐Ÿ‘‹ 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!

Cong-Wan commented 1 year ago

@Cong-Wan ๐Ÿ‘‹ 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 ) defined when training:data/hyp.scratch.yaml

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 #3882 implements this integration, which will automatically apply Albumentations transforms during YOLOv5 training if is installed in your environment. See #3882 for full details.albumentations>=1.0.3

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

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

Dear glenn,

Good morning ,sir! Thank you for your answer!

I have two other questions for you๐Ÿ˜Š.

First, how do I save all train_batch*.jpg?

Next, a image have itself label, but the label (*.txt) file is empty, will yolov5 use it as a background image?

Looking forward to your reply!

BR,

glenn-jocher commented 1 year ago

@litaldavar train_batch*.jpg are created automatically in your runs/train/exp directory on train start.

Yes you can just add background images to your dataset without needing any label txt file.