遇到AttributeError: module 'numpy' has no attribute 'float'
报错信息:
Traceback (most recent call last): File "script/python/COCO/mAP.py", line 56, in <module> mAP = getmAP(args.detectResult, args.file5k, args.annotation) File "script/python/COCO/mAP.py", line 33, in getmAP coco_eval.accumulate() File "/usr/local/lib/python3.8/dist-packages/pycocotools-2.0-py3.8-linux-aarch64.egg/pycocotools/cocoeval.py", line 378, in accumulate tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float) File "/usr/local/lib/python3.8/dist-packages/numpy/__init__.py", line 305, in __getattr__ raise AttributeError(__former_attrs__[attr]) AttributeError: module 'numpy' has no attribute 'float'. `np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
原因:
numpy在1.24以后弃用了float类型。
解决:
重新安装numpy <1.24版本的
具体操作:
1.卸载
pip3 uninstall numpy
2.指定版本安装:
pip3 install numpy==1.23
参考资料:https://stackoverflow.com/questions/74844262/how-to-solve-error-numpy-has-no-attribute-float-in-python