ultralytics / yolov5

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

[Custom Training] Dataset image size #4401

Closed matias-kovero closed 3 years ago

matias-kovero commented 3 years ago

❔Question

Hi, tried to find info on this on past issues, but can't really find anything - so I'll ask it here. Hopefully this will aid someone else if they are strugling with the same issue.

Choosing image size.

My case, I would like to detect objects from cctv feed. This feed is native 1920x1080. For speed(?) I could inference an section (point of intrest) of this feed, ex: an doorway etc. This section could be ex: 500x500 area of the original feed.

I have a bunch of legacy feed to create an dataset - this feed is in 1920x1080. What size images should I use in my dataset?

I know I have the ability to select image size when training with --img 'size'

Should I just label my images in 1920x1080 - then maybe scale them down to 1280x720 | 854x480 | 640x360 | 426x240

Scale down as much as possible to speed up training

However, if I have small objects in the dataset, I can't scale down that much as it will hinder accuracy, am I right? Also as my dataset images would be in 16:9 and not in 1:1, I should use --rect?

Finally, am I destroying my model with these image sizes, if ultimately I'm trying to inference on an 500x500 (point of intrest) section of the 1920x1080 feed?

github-actions[bot] commented 3 years ago

πŸ‘‹ Hello @matias-kovero, 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 3 years ago

@matias-kovero πŸ‘‹ 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/

matias-kovero commented 3 years ago

Hi @glenn-jocher, I have already read the Train Custom Data info. I know you are super busy, and these questions overflow this section.

Maybe it is because I'm not native english, but my earlier questions was aimed on this section that I don't fully grasp

COCO trains at native resolution of --img 640, though due to the high amount of small objects in the dataset it can benefit from training at higher resolutions such as --img 1280. If there are many small objects then custom datasets will benefit from training at native or higher resolution. Best inference results are obtained at the same --img as the training was run at, i.e. if you train at --img 1280 you should also test and detect at --img 1280.

My dataset images are 1920x1080

Best inference results are obtained at the same --img as the training was run

So I should give 1280x720 images to inference for best results?

But to reduce unnecessary data given to inference I could provide an cropped section from the original feed (1920x1080) to the inference.

This cropped section would be in 1920x1080 resolution, but cropped to ex. 500x500 (1:1) or an smaller (16:9) section. Will I hinder my inference results if I use an cropped image (Point of intrest) to inferece or should I just provide it the raw feed?

glenn-jocher commented 3 years ago

@matias-kovero as the guide states questions are pointless without a baseline result first using default settings.

matias-kovero commented 3 years ago

Those questions where more on the theory, as if is my process fundamentally flawed?

When using 16:9 images, should you use --rect on train.py <- baseline needed for this?

Using cropped image from raw image for inference will give bad results if model trained with --img 1280?

glenn-jocher commented 3 years ago

I recommend following our published guidance

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.

rsomani95 commented 3 years ago

@glenn-jocher FWIW I think it would be useful to know how to train with rectangular images without establishing a baseline first too. You may be using the same model for multiple tasks, and if other tasks require a specific image size, it'd be useful to know how to do that from the get go.

Intuitively, images that may be at odd aspect ratios like 2.39:1 make no sense to train at 640x640 because a tall box could get squished beyond comprehension. Given resource constraints, one may not have the time to try the recommended 640x first too.

The train.py's argparser help message (and info from previous issues) tells me that you can pass --rect to train with rectangular images, but the --img-size argument only seems to accept a single number for train/test size. Is this the shorter side of the image? Glancing through the dataset.py code here left me a little confused on how this is handled.

TLDR: Regardless of recommendation, can you force the training image size to be a specific height and width for all images?

Many thanks!

github-actions[bot] commented 3 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 ⭐!

Camilochiang commented 2 years ago

@rsomani95 I hope that you find the answer to your question. If is not to late see this comment for details.