[解决方法]mmdetection运行时出现AttributeError: module ‘numpy’ has no attribute ‘float’.

问题介绍

在进行faster-rcnn模型训练时出现了问题如下:


Traceback (most recent call last):
  File "tools/train.py", line 133, in <module>
    main()
  File "tools/train.py", line 129, in main
    runner.train()
  File "/home/wangbei/anaconda3/envs/Object_mmdetection/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1721, in train
    model = self.train_loop.run()  # type: ignore
  File "/home/wangbei/anaconda3/envs/Object_mmdetection/lib/python3.8/site-packages/mmengine/runner/loops.py", line 102, in run
    self.runner.val_loop.run()
  File "/home/wangbei/anaconda3/envs/Object_mmdetection/lib/python3.8/site-packages/mmengine/runner/loops.py", line 366, in run
    metrics = self.evaluator.evaluate(len(self.dataloader.dataset))
  File "/home/wangbei/anaconda3/envs/Object_mmdetection/lib/python3.8/site-packages/mmengine/evaluator/evaluator.py", line 79, in evaluate
    _results = metric.evaluate(size)
  File "/home/wangbei/anaconda3/envs/Object_mmdetection/lib/python3.8/site-packages/mmengine/evaluator/metric.py", line 133, in evaluate
    _metrics = self.compute_metrics(results)  # type: ignore
  File "/home/wangbei/mmdetection(coco)/mmdet/evaluation/metrics/coco_metric.py", line 512, in compute_metrics
    coco_eval.accumulate()
  File "/home/wangbei/anaconda3/envs/Object_mmdetection/lib/python3.8/site-packages/pycocotools-2.0-py3.8-linux-x86_64.egg/pycocotools/cocoeval.py", line 378, in accumulate
    tp_sum = np.cumsum(tps, axis=1).astype(dtype=np.float)
  File "/home/wangbei/anaconda3/envs/Object_mmdetection/lib/python3.8/site-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.

问题分析

这个错误信息显示在评估模型的过程中,出现了AttributeError: module ‘numpy’ has no attribute ‘float’。这意味着您的代码中使用了 numpy.float,但是在NumPy 1.20版本中,已经弃用了np.float的别名。

本人解决方法

为了解决这个问题,可以根据提示尝试修改python环境包里面的pycocotools包里面的cocoeval.py文件,将代码中所有使用np.float的地方都修改为float,并重新运行程序。
1)找到外部库
2)打开pycocotools-2.0-py3.8-linux-x86_64.egg文件夹
3)打开pycocotools文件夹
4)找到cocoeval.py文件并打开
5)查找(ctrl+F) float
6)删除前面的 np.
[解决方法]mmdetection运行时出现AttributeError: module ‘numpy’ has no attribute ‘float’._第1张图片修改后的文件:
[解决方法]mmdetection运行时出现AttributeError: module ‘numpy’ has no attribute ‘float’._第2张图片

你可能感兴趣的:(numpy,深度学习,视觉检测)