在尝试复现pytorch官方语义分割教程时出现以下问题:
完整的错误如下:
Traceback (most recent call last):
File "/home/uzi/anaconda3/envs/pytorch-py3/lib/python3.5/site-packages/numpy/core/function_base.py", line 118, in linspace
num = operator.index(num)
TypeError: 'numpy.float64' object cannot be interpreted as an integer
self.params = Params(iouType=iouType) # parameters
File "/home/uzi/anaconda3/envs/pytorch-py3/lib/python3.5/site-packages/pycocotools/cocoeval.py", line 527, in __init__
self.setDetParams()
File "/home/uzi/anaconda3/envs/pytorch-py3/lib/python3.5/site-packages/pycocotools/cocoeval.py", line 507, in setDetParams
self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)#np.round((0.95 - .5) / .05) + 1)
File "<__array_function__ internals>", line 6, in linspace
File "/home/uzi/anaconda3/envs/pytorch-py3/lib/python3.5/site-packages/numpy/core/function_base.py", line 122, in linspace
.format(type(num)))
TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.
解决办法:
根据提示发现和pycocotools有关, 之前我使用了pip 安装pycocotools,
首先卸载原来安装的pycocotools
下载 这个 https://github.com/cocodataset/cocoapi
首先,切换到coco api下PythonAPI路径:
cd cocoapi/PythonAPI
然后安装 (python3.5.6版本)
python3 setup.py build_ext --inplace
python3 setup.py build_ext install
安装完成后,成功运行!