如题,float64类型不能被安全地转换成整型。版本的numpy不支持使用浮点数作为步长,numpy1.17.0下的版本可以。
Traceback (most recent call last):
File "/home/zmd/software/anaconda3/lib/python3.7/site-packages/numpy/core/function_base.py", line 117, in linspace
num = operator.index(num)
TypeError: 'numpy.float64' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "coco_validation.py", line 49, in <module>
main()
File "coco_validation.py", line 45, in main
coco_eval.evaluate_coco(dataset_val, retinanet)
File "/home/zmd/project/pytorch-retinanet/retinanet/coco_eval.py", line 76, in evaluate_coco
coco_eval = COCOeval(coco_true, coco_pred, 'bbox')
File "/home/zmd/.local/lib/python3.7/site-packages/pycocotools/cocoeval.py", line 76, in __init__
self.params = Params(iouType=iouType) # parameters
File "/home/zmd/.local/lib/python3.7/site-packages/pycocotools/cocoeval.py", line 527, in __init__
self.setDetParams()
File "/home/zmd/.local/lib/python3.7/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)
File "<__array_function__ internals>", line 6, in linspace
File "/home/zmd/software/anaconda3/lib/python3.7/site-packages/numpy/core/function_base.py", line 121, in linspace
.format(type(num)))
TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.
解决方法:
降低numpy的版本。
具体步骤如下:
查看自身numpy版本:
pip show numpy
降低numpy版本:
pip install -U numpy==1.17.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
后面加上 -i 是为了设置清华镜像源作为下载地址,速度飞快。
降低版本号后即可正常调用coco的api了。