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

High resolution training #8843

Closed abbasmammadov closed 2 years ago

abbasmammadov commented 2 years ago

Search before asking

Question

First of all thank you very much for such an amazing work and your efforts to keep the model up to date with consistent updates.

Currently I am working on a dataset of images with the resolution of 2160*3360. There around 5 classes, and these objects are quite large in the all the images. First I used the below setting after processing my data into desired format: !python3 train.py --data splitted/data.yaml --cfg yolov5s.yaml --weights yolov5s.pt Even on 60th epoch I terminated the code and I was able to achieve 88mAP, which was quite reasonable.

But to be honest I can not understand the image resolutions in this project/model. Above code due to the default setting was run on size of 640. But the results were accurate and at inference and validation time it is also quite good.

Then I wanted to change --img-size to my data resolution but it takes only 1 argument and make it square of that size (e.g. 640*640). I changed it to the largest side i.e. 3360 but the training time was slow and size was 3360 3360 not 2160 3360. I am not sure I am doing it correctly since this part is quite confusing for me.

I would be glad if you can elaborate this size issues a bit more. And also I would like to ask for advice that which settings should I train my data described above (imgs of 2160*3360 annotated according to the yolov5 format and object are large with at most 5 classes).

Thanks in advance for your attention!

Additional

No response

github-actions[bot] commented 2 years ago

👋 Hello @abbasmammadov, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email support@ultralytics.com.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on macOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 2 years ago

@abbasmammadov 👋 Hello! Thanks for asking about improving YOLOv5 🚀 training results.

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!

bit-scientist commented 2 years ago

@abbasmammadov you would use larger models of yolo such as l or x and provide --img-size 3360 with --rect . The smaller side of the image is handled automatically.

abbasmammadov commented 2 years ago

@bit-scientist I solved the issue, but thank you very much for suggestion! 👍

glenn-jocher commented 8 months ago

@ChengGong0602 Great to hear you've resolved your issue! 🎉

@bit-scientist For high-resolution images where the object of interest is small, like a football in a panoramic image, you might want to consider the following:

  1. Use a larger model: YOLOv5 l or x models have more capacity to learn from high-resolution images.
  2. Adjust the --img-size: Use a larger --img-size that is closer to your native image resolution, such as --img-size 2048 or higher if your hardware allows it.
  3. Enable --rect training: This flag allows for rectangular training, which can be beneficial for non-square images. It will adjust the smaller dimension of the image automatically while keeping the aspect ratio.
  4. Increase the number of anchors: If the default anchors are not suitable for detecting small objects in your images, you might need to adjust them. You can use the --autoanchor flag to recalculate anchors based on your dataset.

Remember to monitor your validation mAP to ensure that the model is improving and not overfitting. If you're still not getting satisfactory results, consider using mosaic and mixup augmentations, or manually tuning hyperparameters to better suit small object detection.

Good luck with your training, and if you have further issues, don't hesitate to ask! 🚀