问题描述
测试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) (恢复正常)