这两天下载了Github上一个关于SSD目标检测的项目,训练和测试过程中遇到了一些问题,在此记录一下:
项目地址: https://github.com/amdegroot/ssd.pytorch
1 关于pip install
在使用 pip install xxx 时,有时可能会出现 ‘Could not fetch URL
https://pypi.python.org’的问题。
解决方法:输入 pip install xxx -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
其中 xxx 就是你想要安装的库,如numpy。
2 GPU和CPU
项目源代码写的是GPU版本,用到了CUDA。如果你没有GPU,则需要将代码转化为CPU版本。这大致需要两个步骤:
(1)将所有的torch.load(xxx),改为torch.load(xxx, map_location=‘cpu’)
(2)去除掉所有张量后面的.cuda(),类似于下图,注释掉的是源代码,添加了后面不加.cuda()的代码,ctrl+F寻找cuda即可。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200209125721823.png
3 索引问题
IndexError: The shape of the mask [32, 8732] at index 0does not match
the shape of the index