- 遇到的问题:在使用COCO API评估检测器性能时,出现了错误——TypeError: object of type class numpy.float64 cannot be safely interpreted as an integer
- 解决办法:
- (不推荐) 降低numpy版本,如我的是1.18.1,可以尝试降到1.16.0,不过这种方法不一定适用,也没有必要
- (推荐) 修改几处COCO API的源码,打开源码中的cocoeval.py,找到下面两行代码,对其进行简单地修改,即将出错处的浮点数转换为int:
# original
self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)
# after modifying
self.iouThrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, int(np.round((1.00 - .0) / .01)) + 1, endpoint=True)
ps:这个问题好像coco官方修复了,如果不是最新版本的pycocotools可以尝试下载最新的源码看看是否会遇到同样的问题。
推荐的解决方法可以参考如下链接:
使用COCOAPI操作COCO数据集 遇到的问题 TypeError: ‘numpy.float64’ object cannot be interpreted
————————————————
版权声明:本文为优快云博主「flyfish1986」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/flyfish1986/article/details/104513632