ultralytics / yolov5

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

Reduce input img size when my custom object is big #6063

Closed fire717 closed 2 years ago

fire717 commented 2 years ago

Search before asking

Question

Hi, I'm using awsome yolov5s(v5.0) with my dataset which has only one class and the object is always big (the min size is more than 40pix at size 640, and most object size is range from 100px to 300px).

And in order to reduce the model size and speed up inference, I am trying to using smaller input img size, such as from 640 to 448 or 320.

Because my object is big, so I thought I can get almost the same performance as 640, however I found that the mAP of 448 is lower than 640.

So do you have any suggestions? Such as should I change the model structure to reduce the Receptive field or something like that?

Thx!

Additional

No response

github-actions[bot] commented 2 years ago

👋 Hello @fire717, 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 Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

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

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

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

@fire717 if you want the best results at 320 you should train directly at 320. Training at 640 but running at 320 will not be quite as accurate, even though it will still work.

fire717 commented 2 years ago

@fire717 if you want the best results at 320 you should train directly at 320. Training at 640 but running at 320 will not be quite as accurate, even though it will still work.

Yes! Of course I train at 320.Let me make the question more clear: My custom dataset only have one class and is big enough at 320 size. When I train at 640 and test at 640, I can get AP around 0.97, But if I train at 320 and test at 320, I can get only 0.95 AP.

I thought at 320 it should get 0.97,too. Because my object is easy and big.

So, if the drop from 0.97 to 0.95 is normal, why ? ( Because my object is easy and big) if not, what should I do to get better performance?

glenn-jocher commented 2 years ago

@fire717 👋 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/](https://github.com/ultralytics/yolov5/issues/2844#issuecomment-851338384)

Good luck 🍀 and let us know if you have any other questions!

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

zhiqwang commented 2 years ago

Hi @fire717

So, if the drop from 0.97 to 0.95 is normal, why ? ( Because my object is easy and big)

This result is quite interesting, what is the map if you test at 640 scale using 320 scale training?

fire717 commented 2 years ago

@zhiqwang Indeed I did not test that, but I have a similar test to share if you are interested in: train at 448, test at 448, got 0.974 train at 448, test at 640, got 0.975 train at 640, test at 640, got 0.981 (and I forget the result of training at 640, test at448, but I remember its not good because I didn't use it after the test. )

Finally I give up trying to reduce the img size, and now I trim a smaller model than yolov5s to speed up inference.

As to the reason for the test, I guess using small size may affect the ability of the model to extract features, even if for big object.

zhiqwang commented 2 years ago

Thanks @fire717 , the results look reasonable.

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