-
-
Notifications
You must be signed in to change notification settings - Fork 16.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About not being able to customize the anchors #7015
Comments
@jayer95 YOLOv5 🚀 anchors are saved as Detect() layer attributes on model creation, and updated as necessary by AutoAnchor before training starts. Their exact location is here: Line 45 in f17c86b
You can examine the anchors of any trained YOLOv5 model like this: Inputimport torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False) # official model
model = torch.hub.load('ultralytics/yolov5', 'custom', 'path/to/best.pt', autoshape=False) # custom model
# Anchors
m = model.model.model[-1] # Detect() layer
print(m.anchors * m.stride.view(-1, 1, 1)) # print anchors OutputYOLOv5 🚀 2021-11-22 torch 1.10.0+cu111 CUDA:0 (Tesla V100-SXM2-16GB, 16160MiB)
# x y
tensor([[[ 10., 13.],
[ 16., 30.],
[ 33., 23.]], # P3/8-small
[[ 30., 61.],
[ 62., 45.],
[ 59., 119.]], # P4/16-medium
[[116., 90.],
[156., 198.],
[373., 326.]]], dtype=torch.float16) # P5/32-large ExampleGood luck 🍀 and let us know if you have any other questions! |
Hi, I have deleted the default anchors in "yolov5/models/yolov5n.yaml", as follows, Replaced my own defined anchors, as follows, [17,21, 19,35, 18,40] # P3/8 When training the model, the model also correctly read my new anchors, and also set the "--noautoanchor" parameter. I checked the training diary and wrote noautoanchor=true, What I want to express is the above situation, I don't want to recalculate the anchors during training. In addition, I also experimented with the above situation. I did not set the "--noautoanchor" parameter. During training, noautoanchor=false, the program called the autoanchor function and returned "There is no need to recalculate the anchors, because the original anchors are already very perfect", then the model also correctly reads my custom anchors, as follows, [17,21, 19,35, 18,40] # P3/8 But the model generated by training has a third case of its anchors, neither the preset anchors nor my custom anchors? |
The third anchors, as follows, are neither preset anchors nor my custom anchors. [6,11, 7,10, 7,13] # P3/8 |
@jayer95 our team is very small and very busy. If you believe you have an issue please verify it is reproducible before asking us to assist. We do not have time to pursue non-reproducible issues.
How to create a Minimal, Reproducible ExampleWhen asking a question, people will be better able to provide help if you provide code that they can easily understand and use to reproduce the problem. This is referred to by community members as creating a minimum reproducible example. Your code that reproduces the problem should be:
For Ultralytics to provide assistance your code should also be:
If you believe your problem meets all the above criteria, please close this issue and raise a new one using the 🐛 Bug Report template with a minimum reproducible example to help us better understand and diagnose your problem. Thank you! 😃 |
@glenn-jocher I confirmed he met same problem like me. |
@glenn-jocher |
@jayer95 @PonyPC good news 😃! Your original issue may now be fixed ✅ in PR #7060. I investigated AutoAnchor behavior when started with To receive this update:
Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀! |
@glenn-jocher |
@jayer95 awesome! Thanks for the your feedback. |
Search before asking
Question
I'm training a model for license plate character detection, this is the training command I use,
When the training is completed, I found that its anchors use the default anchors, and there is no automatic recalculation.
anchors:
I don't think it's reasonable, this model is very bad at detecting small objects,
Since there are no autoanchors during training, I recalculate the anchors on my dataset,
Get the following new anchors,
I go to yolov5/models/yolov5n.yaml,
anchors:
replace with
and retrain,
After the training, I re-checked best.pt/last.pt and got:
I used "--noautoanchor" during training, but the model was not constructed based on the anchors I specified? The model also recomputed a new set of anchors?
I refer to #6966
The text was updated successfully, but these errors were encountered: