TypeError: ‘numpy.float64’ object cannot be interpreted as an integer
Traceback (most recent call last):
File "D:\ProgramData\Anaconda3\envs\torch\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "D:\ProgramData\Anaconda3\envs\torch\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\10172979\.vscode\extensions\ms-python.python-2021.2.582707922\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\10172979\.vscode\extensions\ms-python.python-2021.2.582707922\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\10172979\.vscode\extensions\ms-python.python-2021.2.582707922\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "D:\ProgramData\Anaconda3\envs\torch\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "D:\ProgramData\Anaconda3\envs\torch\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "D:\ProgramData\Anaconda3\envs\torch\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "d:\project\project5\code\python\yolov4\train.py", line 630, in <module>
device=device, )
File "d:\project\project5\code\python\yolov4\train.py", line 314, in train
evaluator = evaluate(eval_model, val_loader, config, device)
File "D:\ProgramData\Anaconda3\envs\torch\lib\site-packages\torch\autograd\grad_mode.py", line 26, in decorate_context
return func(*args, **kwargs)
File "d:\project\project5\code\python\yolov4\train.py", line 485, in evaluate
coco_evaluator = CocoEvaluator(coco, iou_types = ["bbox"], bbox_fmt='coco')
File "d:\project\project5\code\python\yolov4\tool\tv_reference\coco_eval.py", line 30, in __init__
self.coco_eval[iou_type] = COCOeval(coco_gt, iouType=iou_type)
File "D:\ProgramData\Anaconda3\envs\torch\lib\site-packages\pycocotools\cocoeval.py", line 76, in __init__
self.params = Params(iouType=iouType) # parameters
File "D:\ProgramData\Anaconda3\envs\torch\lib\site-packages\pycocotools\cocoeval.py", line 527, in __init__
self.setDetParams()
File "D:\ProgramData\Anaconda3\envs\torch\lib\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 "D:\ProgramData\Anaconda3\envs\torch\lib\site-packages\numpy\core\function_base.py", line 113, in linspace
num = operator.index(num)
TypeError: 'numpy.float64' object cannot be interpreted as an integer
原因:cocoeval.py文件中调用的了np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
函数。新版本的numpy要求num
为整数。
修改:修改Lib\site-packages\pycocotools
文件下cocoeval.py文件,修改507等行如下:
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)