WongKinYiu / yolov7

Implementation of paper - YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors
GNU General Public License v3.0
13.34k stars 4.2k forks source link

Re-parameterization have a bug #450

Closed JasonDu1993 closed 2 years ago

JasonDu1993 commented 2 years ago

https://github.com/WongKinYiu/yolov7/blob/main/tools/reparameterization.ipynb, I set conv m get the output through [(x+ia) m_weight + m_bias] im, so the new_weight of conv m is m_weight im.implicit, the new_bias is (ia m_weight im+ m_bias im),

but the file ipynb set new_weight is m_weight im.implicit, the new_bias is (im m_weight ia + m_bias ) im = (ia m_weight im im + m_bias im) ,

because the weight is changed after the for loop, so I think the result is wrong

# reparametrized YOLOR
for i in range((model.nc+5)*anchors):
    model.state_dict()['model.105.m.0.weight'].data[i, :, :, :] *= state_dict['model.105.im.0.implicit'].data[:, i, : :].squeeze()
model.state_dict()['model.105.m.0.bias'].data += state_dict['model.105.m.0.weight'].mul(state_dict['model.105.ia.0.implicit']).sum(1).squeeze()
model.state_dict()['model.105.m.0.bias'].data *= state_dict['model.105.im.0.implicit'].data.squeeze()

the state_dict['model.105.m.0.weight'] is old weight ,sorry I hadn't noticed it before

nemonameless commented 2 years ago

same question