Fix `check_anchor_order()` in pixel-space not grid-space (#7060)
* Update `check_anchor_order()` Use mean area per output layer for added stability. * Check in pixel-space not grid-space fix
This commit is contained in:
parent
529fbc1814
commit
f327eee614
|
|
@ -110,8 +110,8 @@ class Model(nn.Module):
|
||||||
s = 256 # 2x min stride
|
s = 256 # 2x min stride
|
||||||
m.inplace = self.inplace
|
m.inplace = self.inplace
|
||||||
m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(1, ch, s, s))]) # forward
|
m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(1, ch, s, s))]) # forward
|
||||||
|
check_anchor_order(m) # must be in pixel-space (not grid-space)
|
||||||
m.anchors /= m.stride.view(-1, 1, 1)
|
m.anchors /= m.stride.view(-1, 1, 1)
|
||||||
check_anchor_order(m)
|
|
||||||
self.stride = m.stride
|
self.stride = m.stride
|
||||||
self._initialize_biases() # only run once
|
self._initialize_biases() # only run once
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ PREFIX = colorstr('AutoAnchor: ')
|
||||||
|
|
||||||
def check_anchor_order(m):
|
def check_anchor_order(m):
|
||||||
# Check anchor order against stride order for YOLOv5 Detect() module m, and correct if necessary
|
# Check anchor order against stride order for YOLOv5 Detect() module m, and correct if necessary
|
||||||
a = m.anchors.prod(-1).view(-1) # anchor area
|
a = m.anchors.prod(-1).mean(-1).view(-1) # mean anchor area per output layer
|
||||||
da = a[-1] - a[0] # delta a
|
da = a[-1] - a[0] # delta a
|
||||||
ds = m.stride[-1] - m.stride[0] # delta s
|
ds = m.stride[-1] - m.stride[0] # delta s
|
||||||
if da.sign() != ds.sign(): # same order
|
if da.sign() != ds.sign(): # same order
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue