今天尝试跑了一下SSD的pytorch版本的代码,根据代码说明的指示下载安装相应的文件和数据集之后,产生如下报错:
IndexError: The shape of the mask [32, 8732] at index 0does not match the shape of the indexed tensor [279424, 1] at index 0
此处应该是尺寸不匹配,可以在multibox_loss.py的
loss_c[pos] = 0 # filter out pos boxes for now
上一行加上
loss_c = loss_c.view(pos.size()[0], pos.size()[1])
之后,又产生如下报错:
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
此时需要对代码如下修改
loc_loss += loss_l.item()#原来的是loss_l.data[0]
conf_loss += loss_c.item()#原来的是loss_c.data[0]
if iteration % 10 == 0:
print('timer: %.4f sec.' % (t1 - t0))
print('iter ' + repr(iteration) + ' || Loss: %.4f ||' % (loss.item()), end=' ')#原来的是loss.data[0]