解决在使用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)

问题成功解决

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值