-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
How to get our own anchors? #2585
Comments
@BrianKenobi 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: Lines 34 to 35 in fab5085
You can examine the anchors of any trained YOLOv5 model like this: Inputimport torch
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False) # hub model
# -- or --
model = torch.load('yolov5s.pt')['model'] # local model
# Anchors
m = model.model[-1] # Detect() layer
print(m.anchor_grid.squeeze()) # print anchors Output# 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 |
@glenn-jocher thank you! model = torch.load('yolov5s.pt')['model'] # local model I'm not sure what should I put in ['model']. |
I solved the problem by put the code in the YoloV5 folder. Thank you @glenn-jocher again! But as the result, I still get the default anchor. |
@BrianKenobi yes this is true. YOLOv5 models must either be loaded within the yolov5/ directory or via PyTorch Hub to enabled access to required module imports. To load from anywhere via PyTorch Hub: model = torch.hub.load('ultralytics/yolov5', 'custom', path_or_model='best.pt') # custom model |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I have the same problem as issue #2394. Without autoanchor, I can't get my recall more than 0.663. So I am thinking about how to get my own data's anchor so I can have a better result. Thanks.
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
Originally posted by @glenn-jocher in #2394 (comment)
The text was updated successfully, but these errors were encountered: