目标检测实验问题记录(6)TypeError: ‘<‘ not supported between instances of ‘int‘ and ‘list‘

问题描述

测试PointOBB模型,一开始运行正常,也得到了评估结果mAP和标签文件,但是最后报错:

Traceback (most recent call last):
  File "tools/train.py", line 194, in <module>
    main()
  File "tools/train.py", line 183, in main
    train_detector(
  File "/data/lxy1/pointobb-main/PointOBB/mmdet/apis/train.py", line 179, in train_detector
    runner.run(data_loaders, cfg.workflow)  #开始训练
  File "/data/lxy1/Anaconda3/envs/openmmlab/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 119, in run
    while self.epoch < self._max_epochs:
TypeError: '<' not supported between instances of 'int' and 'list'

模型配置文件中对runner的定义:

runner = dict(type='EpochBasedRunner', max_epochs=12*training_time)

由于是测试,所以只运行一个epoch,命令行中配置了max_epochs如下

python tools/train.py \
    --config configs2/pointobb/pointobb_r50_fpn_2x_dota10.py \
    --work-dir xxx/work_dir/test_pointobb_r50_fpn_2x_dota10/ \
    --cfg-options evaluation.save_result_file='xxx/work_dir/test_pointobb_r50_fpn_2x_dota10/pseudo_obb_result.json', \
    evaluation.do_first_eval=True, \
    runner.max_epochs=0, \
    load_from='xxx/work_dir/pointobb_r50_fpn_2x_dota10_dist/epoch_24.pth'

在运行日志中打印的runner:runner = dict(type='EpochBasedRunner', max_epochs=[0])

需要的结果倒是都拿到了,这个问题好像没什么影响,不过还是解决一下。

解决方法

方法一:

改/data/lxy1/Anaconda3/envs/openmmlab/lib/python3.8/sitepackages/mmcv/runner/base_runner.py

        if max_epochs is not None and max_iters is not None:
            raise ValueError(
                'Only one of `max_epochs` or `max_iters` can be set.')
        # 如果 max_epochs 是列表,取第一个元素
        if isinstance(max_epochs,list):
            self._max_epochs = max_epochs[0]
            print(f"Using first element of max_epochs: {max_epochs[0]}"
        if isinstance(max_epochs,int):
            self._max_epochs = max_epochs
        # self._max_epochs = max_epochs

在max_epochs直接赋值语句前加上类型判断,解决。

方法二:

偶然看到日志文件里记录的另一个参数:do_first_eval=[True]。这也是我在命令行传入的,也变成了奇怪的列表。所以想到了方法二:不通过命令行传入,直接在模型配置文件中改参数。

## Inference command
python tools/train.py \
    --config configs2/pointobb/pointobb_r50_fpn_2x_dota10.py \
    --work-dir xxx/work_dir/test_pointobb_r50_fpn_2x_dota10/ \
    --cfg-options evaluation.save_result_file='xxx/work_dir/test_pointobb_r50_fpn_2x_dota10/pseudo_obb_result.json'


## 在模型配置文件加上:
# Inference
load_from = 'xxx/work_dir/pointobb_r50_fpn_2x_dota10_dist/epoch_24.pth'

evaluation = dict(
    save_result_file='../TOV_mmdetection_cache/work_dir/dota/test/test_debug_result.json',
    do_first_eval=True
)
runner = dict(type='EpochBasedRunner',max_epochs=0)

日志中的记录:runner = dict(type='EpochBasedRunner', max_epochs=0)  (恢复正常)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值