pycocotools报TypeError: object of type class numpy.float64 cannot be safely interpreted as an int

错误详情

在使用pycocotools的时候报TypeError: object of type cannot be safely interpreted as an integer.错误详细信息如下

  File "/home/disk0/zw/workspace/models/research/object_detection/metrics/coco_evaluation.py", line 415, in first_value_func
    self._metrics = self.evaluate()

  File "/home/disk0/zw/workspace/models/research/object_detection/metrics/coco_evaluation.py", line 246, in evaluate
    coco_wrapped_groundtruth, coco_wrapped_detections, agnostic_mode=False)

  File "/home/disk0/zw/workspace/models/research/object_detection/metrics/coco_tools.py", line 177, in __init__
    cocoeval.COCOeval.__init__(self, groundtruth, detections, iouType=iou_type)

  File "/home/zw/anaconda3/envs/competition/lib/python3.6/site-packages/pycocotools/cocoeval.py", line 76, in __init__
    self.params = Params(iouType=iouType) # parameters

  File "/home/zw/anaconda3/envs/competition/lib/python3.6/site-packages/pycocotools/cocoeval.py", line 527, in __init__
    self.setDetParams()

  File "/home/zw/anaconda3/envs/competition/lib/python3.6/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/zw/anaconda3/envs/competition/lib/python3.6/site-packages/numpy/core/function_base.py", line 121, in linspace
    .format(type(num)))

解决办法

通过上面的信息可以看到,错误原因是cocoeval.py中的np.linspace函数导致的,发生这个原因是因为np.linspace函数的num参数不支持float类型导致的,找到lib/python3.6/site-packages/pycocotools下的cocoeval.py文件,将507行改成如下

self.iouThrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)

或者安装numpy的1.11.0的版本,可能无法兼容TensorFlow的版本,导致无法使用TensorFlow,最好还是修改coceval.py文件

你可能感兴趣的:(tensorflow实战)