在此先感谢Windows下自己训练数据集,在pytorch上实现基于SSD的物体检测一文作者,根据此文得以顺利实现目标检测;
在根据此文进行调试之后,在训练过程中遇到两个错误:
- IndexError: The shape of the mask [14, 8732] at index 0does not match the shape of the indexed tensor [122248, 1] at index 0
IndexError: The shape of the mask [14, 8732] at index 0does not match the shape of the indexed tensor [122248, 1] at index 0
张量不匹配
应该是layers/modules/multibox_loss中97与98行处loss_c与它的索引pos大小不同引起,将两行互换
- div_(): argument ‘other’ (position 1) must be Tensor, not builtin_function_or_method
div_(): argument 'other' (position 1) must be Tensor, not builtin_function_or_method
解决方法是将layers/modules/multibox_loss最后改为
N = num_pos.data.sum()
N = N.type(torch.cuda.FloatTensor)
# loss_l = loss_l.double()
# loss_c = loss_c.double()
loss_l /= N
loss_c /= N
return loss_l, loss_c
感谢ssd.pytorch源码迁移实现(pytorch版本从0.2迁移到0.4(1.0))作者提出的解决方法