Is there a bug in multibox_loss.py?
when I train the model, there is a bug in layers/modules/multibox_loss.py In line 97, loss_c[pos]=0, the shape of mask [32,8732] ar index 0 not match the shape of the indexed tensor [270424,1] at index 0.
This problem may be caused by the version of pytorch here is the solution 1.add code before 'loss_c[pos] = 0' at multibox_loss.py loss_c = loss_c.view(pos.size()[0], pos.size()[1]) loss_c[pos] = 0 # filter out pos boxes for now 2.at train.py change loc_loss += loss_l.data[0] conf_loss += loss_c.data[0] to: loc_loss += loss_l.item() conf_loss += loss_c.item() 3. and mybe there will be a warning: UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead. warnings.warn(warning.format(ret)) change size_average=False to reduction='sum'
reference https://blog.csdn.net/qq_30614451/article/details/100137358
modification places are Line 90 and Line 111 in multibox_loss.py change loss_l = F.smooth_l1_loss(loc_p, loc_t, size_average=False) to loss_l = F.smooth_l1_loss(loc_p, loc_t, reduction='sum')
train.py: line 188, should also change
from
print('iter ' + repr(iteration) + ' || Loss: %.4f ||' % (loss.data[0]), end=' ')
to
print('iter ' + repr(iteration) + ' || Loss: %.4f ||' % (loss.item()), end=' ')
This problem may be caused by the version of pytorch here is the solution 1.add code before 'loss_c[pos] = 0' at multibox_loss.py loss_c = loss_c.view(pos.size()[0], pos.size()[1]) loss_c[pos] = 0 # filter out pos boxes for now 2.at train.py change loc_loss += loss_l.data[0] conf_loss += loss_c.data[0] to: loc_loss += loss_l.item() conf_loss += loss_c.item() 3. and mybe there will be a warning: UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead. warnings.warn(warning.format(ret)) change size_average=False to reduction='sum'
reference https://blog.csdn.net/qq_30614451/article/details/100137358
GREAT CSDN!!!
when I train the model, there is a bug in layers/modules/multibox_loss.py In line 97, loss_c[pos]=0, the shape of mask [32,8732] ar index 0 not match the shape of the indexed tensor [270424,1] at index 0.
Just changing the code order of line 97 and 98, it would work