DetectionEngine.fit_anchors

DetectionEngine.fit_anchors(model)

k-means with an IoU distance over the training boxes, or nothing to do.

Euclidean distance on (width, height) is scale-blind - (0.02, 0.02) and (0.04, 0.04) sit the same distance apart as (0.50, 0.50) and (0.52, 0.52), while their overlaps are 0.25 and 0.93 - so the distance is 1 - IoU, which is what the anchors are for.

Parameters

Name Type Description Default
model DetectionModel Which model’s boxes to fit against. required

Returns

Name Type Description
AnchorFit | None An AnchorFit, or None when the model already declares anchors - the
AnchorFit | None difference between “fitted these” and “nothing to do”.

Fitting is worth about 0.23 of mean overlap on BCCD: COCO’s nine anchors cover its boxes at 0.6473, fitted ones at 0.8751 to 0.8802 across three seeds.