解决在使用mmdetection时,验证遇到的TypeError: ‘numpy.float64‘ object cannot be interpreted as an integer错误

使用solov2训练时,训练遇到的问题

[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 665/665, 30.4 task/s, elapsed: 22s, ETA:     0s2023-01-12 14:01:00,528 - mmdet - INFO - Evaluating bbox...
Loading and preparing results...
DONE (t=0.01s)
creating index...
index created!
Traceback (most recent call last):
  File "tools/train.py", line 221, in <module>
    main()
  File "tools/train.py", line 210, in main
    train_detector(
  File "/opt/conda/lib/python3.8/site-packages/mmdet/apis/train.py", line 244, in train_detector
    runner.run(data_loaders, cfg.workflow)
  File "/opt/conda/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 127, in run
    epoch_runner(data_loaders[i], **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 54, in train
    self.call_hook('after_train_epoch')
  File "/opt/conda/lib/python3.8/site-packages/mmcv/runner/base_runner.py", line 309, in call_hook
    getattr(hook, fn_name)(self)
  File "/opt/conda/lib/python3.8/site-packages/mmcv/runner/hooks/evaluation.py", line 267, in after_train_epoch
    self._do_evaluate(runner)
  File "/opt/conda/lib/python3.8/site-packages/mmdet/core/evaluation/eval_hooks.py", line 63, in _do_evaluate
    key_score = self.evaluate(runner, results)
  File "/opt/conda/lib/python3.8/site-packages/mmcv/runner/hooks/evaluation.py", line 363, in evaluate
    eval_res = self.dataloader.dataset.evaluate(
  File "/opt/conda/lib/python3.8/site-packages/mmdet/datasets/coco.py", line 642, in evaluate
    eval_results = self.evaluate_det_segm(results, result_files, coco_gt,
  File "/opt/conda/lib/python3.8/site-packages/mmdet/datasets/coco.py", line 483, in evaluate_det_segm
    cocoEval = COCOeval(coco_gt, coco_det, iou_type)
  File "/opt/conda/lib/python3.8/site-packages/pycocotools/cocoeval.py", line 76, in __init__
    self.params = Params(iouType=iouType) # parameters
  File "/opt/conda/lib/python3.8/site-packages/pycocotools/cocoeval.py", line 527, in __init__
    self.setDetParams()
  File "/opt/conda/lib/python3.8/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 180, in linspace
  File "/opt/conda/lib/python3.8/site-packages/numpy/core/function_base.py", line 120, in linspace
    num = operator.index(num)
TypeError: 'numpy.float64' object cannot be interpreted as an integer

解决办法

进入/opt/conda/lib/python3.8/site-packages/pycocotools/cocoeval.py中507行
将以下内容修改

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)

修改为:

self.iouThrs = np.linspace(.5, 0.95, 10, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, 101, endpoint=True)

问题成功解决

你可能感兴趣的:(numpy,python,深度学习,人工智能)