Closed matias-kovero closed 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.
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
YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
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.
@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.
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.
--weights
argument. Models download automatically from the latest YOLOv5 release.
python train.py --data custom.yaml --weights yolov5s.pt
yolov5m.pt
yolov5l.pt
yolov5x.pt
custom_pretrained.pt
--weights ''
argument:
python train.py --data custom.yaml --weights '' --cfg yolov5s.yaml
yolov5m.yaml
yolov5l.yaml
yolov5x.yaml
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.
--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
.--batch-size
that your hardware allows for. Small batch sizes produce poor batchnorm statistics and should be avoided.hyp['obj']
will help reduce overfitting in those specific loss components. For an automated method of optimizing these hyperparameters, see our Hyperparameter Evolution Tutorial.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/
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
--img 1280
--rect
when training?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?
@matias-kovero as the guide states questions are pointless without a baseline result first using default settings.
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?
1920x1080
500x500
Using cropped image from raw image for inference will give bad results if model trained with --img 1280
?
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.
@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!
π 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 β!
@rsomani95 I hope that you find the answer to your question. If is not to late see this comment for details.
β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
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?