File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,7 +40,8 @@ def metric(k): # compute metric
4040 bpr = (best > 1 / thr ).float ().mean () # best possible recall
4141 return bpr , aat
4242
43- anchors = m .anchors .clone () * m .stride .to (m .anchors .device ).view (- 1 , 1 , 1 ) # current anchors
43+ stride = m .stride .to (m .anchors .device ).view (- 1 , 1 , 1 ) # model strides
44+ anchors = m .anchors .clone () * stride # current anchors
4445 bpr , aat = metric (anchors .cpu ().view (- 1 , 2 ))
4546 s = f'\n { PREFIX } { aat :.2f} anchors/target, { bpr :.3f} Best Possible Recall (BPR). '
4647 if bpr > 0.98 : # threshold to recompute
@@ -55,8 +56,9 @@ def metric(k): # compute metric
5556 new_bpr = metric (anchors )[0 ]
5657 if new_bpr > bpr : # replace anchors
5758 anchors = torch .tensor (anchors , device = m .anchors .device ).type_as (m .anchors )
58- m .anchors [:] = anchors .clone ().view_as (m .anchors ) / m .stride .to (m .anchors .device ).view (- 1 , 1 , 1 ) # loss
59- check_anchor_order (m )
59+ m .anchors [:] = anchors .clone ().view_as (m .anchors )
60+ check_anchor_order (m ) # must be in pixel-space (not grid-space)
61+ m .anchors /= stride
6062 s = f'{ PREFIX } Done ✅ (optional: update model *.yaml to use these anchors in the future)'
6163 else :
6264 s = f'{ PREFIX } Done ⚠️ (original anchors better than new anchors, proceeding with original anchors)'
You can’t perform that action at this time.
0 commit comments