You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm a rookie in object detection, I setup yolov5 environment completely and yolov5 can run successfully on dataset COCO128. (train, test, detect)
When I use my own dataset, a problem occurred and I don't know why and how to solve it.
My command setting is below:
Picture size are all 640x480 (original size is 4000x3000).
Model config is copied from yolov5s.yaml, but the number of classes is 89
python train.py
--weights "none"
--cfg "copy_from_5s.yaml"
--data "my_dataset.yaml"
--img_size 640 640
--name "my_dataset_test"
The settings which aren't desplay here are default.
👋 Hello @GaryXXD, 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.
Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:
$ 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):
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), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.
@GaryXXD 👋 Hello, thank you for your interest in our work! This issue seems to lack the minimum requirements for a proper response, or is insufficiently detailed for us to help you. Please note that most technical problems are due to:
Your modified or out-of-date code. If your issue is not reproducible in a new git clone version of this repo we can not debug it. Before going further run this code and verify your issue persists:
$ git clone https://github.com/ultralytics/yolov5 yolov5_new # clone latest
$ cd yolov5_new
$ python detect.py # verify detection# CODE TO REPRODUCE YOUR ISSUE HERE
Your custom data. If your issue is not reproducible in one of our 3 common datasets (COCO, COCO128, or VOC) we can not debug it. Visit our Custom Training Tutorial for guidelines on training your custom data. Examine train_batch0.jpg and test_batch0.jpg for a sanity check of your labels and images.
Your environment. If your issue is not reproducible in one of the verified environments below we can not debug it. If you are running YOLOv5 locally, verify your environment meets all of the requirements.txt dependencies specified below. If in doubt, download Python 3.8.0 from https://www.python.org/, create a new venv, and install requirements.
If none of these apply to you, we suggest you close this issue and raise a new one using the 🐛 Bug Report template, providing screenshots and a minimum reproducible example of your issue. Thank you!
Requirements
Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:
$ 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):
If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are passing. These tests evaluate proper operation of basic YOLOv5 functionality, including training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu.
@glenn-jocher Thanks for your response. I clone yoloV5 and check my environment again, but this problem still happens.
Sadly, I can't reproduce the problem with dataset you mentioned.
So, I trace the code in utils autoanchor.py and find out the problem is probably on scipy kmeans function.
In utils.antoanchor, function kmean_anchors, row 121, the line of code is below
k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
the scipy kmeans function cause the problem,
e.g. In my case, probably because of lack of my own data, the labels are less various.
When run the code above, n=9, the function output k only contains 6 points.
This situation may cause the code in utils.antoanchor, row 49, which is below,
m.anchor_grid[:] = new_anchors.clone().view_as(m.anchor_grid) # for inference
to make mistake on reshaping from tensor(12 elements) to tensor(18 elements).
I'm not sure whether it is bug or not.
@GaryXXD oh, thanks for the details, interesting edge case failure mode.
If there are 9 points requested but the scipy kmeans function only returns 6 points then yes autoanchor will break. Can you submit your labels.jpg and labels_correlogram.jpg? How many instances does your dataset have? Are most instances the same shape?
@GaryXXD maybe we could add an assert to at least better clarify the origin of the error:
s=wh.std(0) # sigmas for whiteningk, dist=kmeans(wh/s, n, iter=30) # points, mean distanceassertlen(k) ==n, print(f'{prefix}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}')
There is no good solution, as an incident like this is mainly an indicator of underlying data issues. The data appears suitable to the number of anchors requested, and the current architecture (3 or 4 output layers) may not be appropriate for monotonically sized data.
The only real quick fix available is to skip autoanchor with python train.py --noautoanchor
There are 350 images, each image contains one object.
These images are about screen dialoguebox detect, some of them are similar.
I think it is the point which you mentioned.
Thanks for your help.
@GaryXXD ok, well that's an improvement at least. Though I see your BPR is only 0.65, which means that your recall and mAP will never be higher than 0.65. You should try to supply your own manual anchors in your yolov5s.yaml file if possible to better match your data:
Activity
github-actions commentedon Mar 8, 2021
👋 Hello @GaryXXD, 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://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.
Requirements
Python 3.8 or later with all requirements.txt dependencies installed, including
torch>=1.7. To install run: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
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), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.
glenn-jocher commentedon Mar 8, 2021
@GaryXXD 👋 Hello, thank you for your interest in our work! This issue seems to lack the minimum requirements for a proper response, or is insufficiently detailed for us to help you. Please note that most technical problems are due to:
git cloneversion of this repo we can not debug it. Before going further run this code and verify your issue persists:Your custom data. If your issue is not reproducible in one of our 3 common datasets (COCO, COCO128, or VOC) we can not debug it. Visit our Custom Training Tutorial for guidelines on training your custom data. Examine
train_batch0.jpgandtest_batch0.jpgfor a sanity check of your labels and images.Your environment. If your issue is not reproducible in one of the verified environments below we can not debug it. If you are running YOLOv5 locally, verify your environment meets all of the requirements.txt dependencies specified below. If in doubt, download Python 3.8.0 from https://www.python.org/, create a new venv, and install requirements.
If none of these apply to you, we suggest you close this issue and raise a new one using the 🐛 Bug Report template, providing screenshots and a minimum reproducible example of your issue. Thank you!
Requirements
Python 3.8 or later with all requirements.txt dependencies installed, including
torch>=1.7. To install run: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
If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are passing. These tests evaluate proper operation of basic YOLOv5 functionality, including training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu.
GaryXXD commentedon Mar 15, 2021
@glenn-jocher Thanks for your response. I clone yoloV5 and check my environment again, but this problem still happens.
Sadly, I can't reproduce the problem with dataset you mentioned.
So, I trace the code in utils autoanchor.py and find out the problem is probably on scipy kmeans function.
In utils.antoanchor, function kmean_anchors, row 121, the line of code is below
k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
the scipy kmeans function cause the problem,
e.g. In my case, probably because of lack of my own data, the labels are less various.
When run the code above, n=9, the function output k only contains 6 points.
This situation may cause the code in utils.antoanchor, row 49, which is below,
m.anchor_grid[:] = new_anchors.clone().view_as(m.anchor_grid) # for inference
to make mistake on reshaping from tensor(12 elements) to tensor(18 elements).
I'm not sure whether it is bug or not.
Thanks for spending time reading this
glenn-jocher commentedon Mar 15, 2021
@GaryXXD oh, thanks for the details, interesting edge case failure mode.
If there are 9 points requested but the scipy kmeans function only returns 6 points then yes autoanchor will break. Can you submit your labels.jpg and labels_correlogram.jpg? How many instances does your dataset have? Are most instances the same shape?
glenn-jocher commentedon Mar 15, 2021
@GaryXXD maybe we could add an assert to at least better clarify the origin of the error:
There is no good solution, as an incident like this is mainly an indicator of underlying data issues. The data appears suitable to the number of anchors requested, and the current architecture (3 or 4 output layers) may not be appropriate for monotonically sized data.
The only real quick fix available is to skip autoanchor with
python train.py --noautoanchorScipy kmeans-robust autoanchor update
GaryXXD commentedon Mar 15, 2021
@glenn-jocher Thanks for your response again. My label examples are below,
concat_outcome.txt
There are 350 images, each image contains one object.
These images are about screen dialoguebox detect, some of them are similar.
I think it is the point which you mentioned.
Thanks for your help.
glenn-jocher commentedon Mar 15, 2021
@GaryXXD I've created a PR that should solve this in #2470
Can you clone this branch and see if your issue is fixed with it?
git clone https://github.com/ultralytics/yolov5 -b glenn-jocher-patch-1 # clone PR branchGaryXXD commentedon Mar 15, 2021
@glenn-jocher It works. Now, it automatically skip anchor calcutlation if the length is not match.

Thanks a lot.
glenn-jocher commentedon Mar 15, 2021
@GaryXXD ok, well that's an improvement at least. Though I see your BPR is only 0.65, which means that your recall and mAP will never be higher than 0.65. You should try to supply your own manual anchors in your yolov5s.yaml file if possible to better match your data:
yolov5/models/yolov5s.yaml
Lines 6 to 11 in 38ff499
Scipy kmeans-robust autoanchor update (#2470)
Scipy kmeans-robust autoanchor update (ultralytics#2470)
pull updates from original repo (release v5) + reimplement UI (#21)
Scipy kmeans-robust autoanchor update (ultralytics#2470)
Scipy kmeans-robust autoanchor update (#2470)
Scipy kmeans-robust autoanchor update (#2470)