ssd.pytorch icon indicating copy to clipboard operation
ssd.pytorch copied to clipboard

Is there a bug in multibox_loss.py?

Open kouyichi opened this issue 7 years ago • 5 comments

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.

kouyichi avatar Oct 22 '19 10:10 kouyichi

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

weidi1024 avatar Oct 24 '19 10:10 weidi1024

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')

zhaohao0404 avatar Nov 18 '19 14:11 zhaohao0404

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=' ')

Codermanok avatar Mar 04 '20 09:03 Codermanok

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!!!

ghost avatar May 27 '20 08:05 ghost

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

TalenWang-AIcv avatar Sep 16 '20 07:09 TalenWang-AIcv