ultralytics / yolov5

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

How to get anchors for custom datasets? #3097

Closed Fred199683 closed 3 years ago

Fred199683 commented 3 years ago

❔Question

My datasets is completely about small objects, but the default number of anchors is 9, and the number of layers is 3. So for small objects datasets, what should i do, can anyone give me some advices? I think i may try 6 anchors and 2 layers(each layer have 3 anchors), or even 3 anchors and one layer?? My datasets is totally about small objects, I think the default anchors which size is too big for my datasets....But i am very confused about how to choose the number K in kmeans and also the number of layers(something about receptive field??) Hope anyone can give me some advice!!THX!!!! plus: anchor_t: 4.0 # anchor-multiple threshold should i change this hyper-param???

Additional context

glenn-jocher commented 3 years ago

@Fred199683 before you modify anything I would first train with the default settings to establish a performance baseline that you can compare to.

YOLOv5 use autoanchor. autoanchor verifies your anchors against your dataset and training settings and adjusts them as necessary if it sees a bad fit. It works well in most cases, though if it causes problems you can always disable it with

python train.py --noautoanchor
Fred199683 commented 3 years ago

@glenn-jocher

Thanks for ur reply. I've already train for first time with default setting. It works well. And because my datasets is totally about small objects, there is no objects bigger than 60 pixels. So i am wondering if i should try to modified the anchors to fit my dataset? And in ur autoanchor, i think only 3 anchors fit for my datasets, so the bpr is 100%, but i think the large anchors is useless? Am i clear.....I just want try to get better results...should i modified this?

glenn-jocher commented 3 years ago

@Fred199683 ok, then sure, you can remove output layers by not passing them to the Detect() layer in your model.yaml file: https://github.com/ultralytics/yolov5/blob/25f8ab835ef82a5664f6434934c7f40088117f65/models/yolov5s.yaml#L47

And you can remove or adjust anchors also in your model.yaml file: https://github.com/ultralytics/yolov5/blob/25f8ab835ef82a5664f6434934c7f40088117f65/models/yolov5s.yaml#L6-L11

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 ⭐!