ultralytics / yolov3

YOLOv3 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
10.18k stars 3.44k forks source link

custom dataset anchor size calculate #1770

Closed caihaunqai closed 3 years ago

caihaunqai commented 3 years ago

Hello, I want to use custom dataset and add to 15 anchors output. However, my precision and MAP falls when I use default P3 anchor size as P1 and P2's anchor sizes. image Is it the problem that my results worse? Do I have to calculate the custom dataset anchor size and how can I calculate them? Any demo is done provided? Thank you very much!

glenn-jocher commented 3 years ago

๐Ÿ‘‹ Hello! Thanks for asking about model anchors. YOLOv5 ๐Ÿš€ uses a new Ultralytics algorithm called autoanchor for anchor verification and generation before training starts.

Autoanchor will analyse your anchors against your dataset and training settings (like --img-size), and will adjust your anchors as necessary if it determines the original anchors are a poor fit, or if an anchor count was specified in your model.yaml rather than anchor values, i.e.

# Specify anchor count (per layer)
anchors: 3

# --OR-- Specify anchor values manually
anchors:
  - [10,13, 16,30, 33,23]  # P3/8
  - [30,61, 62,45, 59,119]  # P4/16
  - [116,90, 156,198, 373,326]  # P5/32

When generating new anchors, autoanchor first applies a kmeans function against your dataset labels (scaled to your training --img-size), and then uses these kmeans centroids as initial conditions for a Genetic Evolution (GE) algorithm. The GE algorithm will evolve all anchors for 1000 generations under default settings, using the CIoU loss (same one used during training) combined with Best Possible Recall (BPR) as its fitness function.

No action is required on your part to use autoanchor. If you would like to force manual anchors for any reason, you can skip autoanchor with the --noautoanchor flag:

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

Thanks! Can I use autoanchor in yolov3?

------------------ ๅŽŸๅง‹้‚ฎไปถ ------------------ ๅ‘ไปถไบบ: "ultralytics/yolov3" @.>; ๅ‘้€ๆ—ถ้—ด: 2021ๅนด5ๆœˆ23ๆ—ฅ(ๆ˜ŸๆœŸๅคฉ) ๆ™šไธŠ9:22 @.>; @.**@.>; ไธป้ข˜: Re: [ultralytics/yolov3] custom dataset anchor size calculate (#1770)

๐Ÿ‘‹ Hello! Thanks for asking about model anchors. YOLOv5 ๐Ÿš€ uses a new Ultralytics algorithm called autoanchor for anchor verification and generation before training starts.

Autoanchor will analyse your anchors against your dataset and training settings (like --img-size), and will adjust your anchors as necessary if it determines the original anchors are a poor fit, or if an anchor count was specified in your model.yaml rather than anchor values, i.e.

Specify anchor count (per layer) anchors: 3 # --OR-- Specify anchor values manually anchors: - [10,13, 16,30, 33,23] # P3/8 - [30,61, 62,45, 59,119] # P4/16 - [116,90, 156,198, 373,326] # P5/32

When generating new anchors, autoanchor first applies a kmeans function against your dataset labels (scaled to your training --img-size), and then uses these kmeans centroids as initial conditions for a Genetic Evolution (GE) algorithm. The GE algorithm will evolve all anchors for 1000 generations under default settings, using the CIoU loss (same one used during training) combined with Best Possible Recall (BPR) as its fitness function.

No action is required on your part to use autoanchor. If you would like to force manual anchors for any reason, you can skip autoanchor with the --noautoanchor flag: python train.py --noautoanchor

โ€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

glenn-jocher commented 3 years ago

@caihaunqai yes, we've updated https://github.com/ultralytics/yolov3 with many of our YOLOv5 advances including autoanchor, so everything in my note above applies to this repo as well!

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 YOLOv3 ๐Ÿš€ 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 YOLOv3 ๐Ÿš€ and Vision AI โญ!