SSD代码运行时报错的解决

今天尝试跑了一下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]

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容