open-mmlab / mmrotate

OpenMMLab Rotated Object Detection Toolbox and Benchmark
https://mmrotate.readthedocs.io/en/latest/
Apache License 2.0
1.83k stars 540 forks source link

[Bug] TypeError: add_datasample() got an unexpected keyword argument 'pred_score_thr' in <mmdet.engine.hooks.visualization_hook.DetVisualizationHook object at 0x000001F34568C9D0> #875

Open 2121qqq opened 1 year ago

2121qqq commented 1 year ago

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

master branch https://github.com/open-mmlab/mmrotate

Environment

D:\Anaconda3\envs\mmr2\python.exe D:/1rotate/mmrotate-1.0.0rc1/tools/test.py 06/09 21:20:27 - mmengine - INFO -

System environment: sys.platform: win32 Python: 3.8.16 (default, Mar 2 2023, 03:18:16) [MSC v.1916 64 bit (AMD64)] CUDA available: True numpy_random_seed: 1317619422 GPU 0: NVIDIA GeForce RTX 3050 Laptop GPU CUDA_HOME: None MSVC: 用于 x64 的 Microsoft (R) C/C++ 优化编译器 19.16.27048 版 GCC: n/a PyTorch: 2.0.1+cu117 PyTorch compiling details: PyTorch built with:

Runtime environment: cudnn_benchmark: False mp_cfg: {'mp_start_method': 'fork', 'opencv_num_threads': 0} dist_cfg: {'backend': 'nccl'} seed: 1317619422 Distributed launcher: none Distributed training: False GPU number: 1

06/09 21:20:27 - mmengine - INFO - Config: dataset_type = 'DOTADataset' data_root = 'D:/cv_code/rotate/mmrotate-1.0.0rc1/datasets/' file_client_args = dict(backend='disk') train_pipeline = [ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict(type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict(type='mmdet.Resize', scale=(1536, 864), keep_ratio=True), dict( type='mmdet.RandomFlip', prob=0.75, direction=['horizontal', 'vertical', 'diagonal']), dict(type='mmdet.PackDetInputs') ] val_pipeline = [ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.Resize', scale=(1536, 864), keep_ratio=True), dict(type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict(type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict( type='mmdet.PackDetInputs', meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor')) ] test_pipeline = [ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.Resize', scale=(1536, 864), keep_ratio=True), dict( type='mmdet.PackDetInputs', meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor')) ] train_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=True), batch_sampler=None, dataset=dict( type='DOTADataset', data_root='D:/cv_code/rotate/mmrotate-1.0.0rc1/datasets/', ann_file='train/annfiles/', data_prefix=dict(img='train/images/'), img_shape=(1536, 864), filter_cfg=dict(filter_empty_gt=True), pipeline=[ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict( type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict( type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict(type='mmdet.Resize', scale=(1536, 864), keep_ratio=True), dict( type='mmdet.RandomFlip', prob=0.75, direction=['horizontal', 'vertical', 'diagonal']), dict(type='mmdet.PackDetInputs') ])) val_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='DOTADataset', data_root='D:/cv_code/rotate/mmrotate-1.0.0rc1/datasets/', ann_file='val/annfiles/', data_prefix=dict(img='val/images/'), img_shape=(1536, 864), test_mode=True, pipeline=[ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.Resize', scale=(1536, 864), keep_ratio=True), dict( type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict( type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict( type='mmdet.PackDetInputs', meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor')) ])) test_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, drop_last=False, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='DOTADataset', data_root='D:/cv_code/rotate/mmrotate-1.0.0rc1/datasets/', ann_file='val/annfiles/', data_prefix=dict(img='val/images/'), img_shape=(1536, 864), test_mode=True, pipeline=[ dict( type='mmdet.LoadImageFromFile', file_client_args=dict(backend='disk')), dict(type='mmdet.Resize', scale=(1536, 864), keep_ratio=True), dict( type='mmdet.LoadAnnotations', with_bbox=True, box_type='qbox'), dict( type='ConvertBoxType', box_type_mapping=dict(gt_bboxes='rbox')), dict( type='mmdet.PackDetInputs', meta_keys=('img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor')) ])) val_evaluator = dict(type='DOTAMetric', metric='mAP') test_evaluator = dict(type='DOTAMetric', metric='mAP') train_cfg = dict(type='EpochBasedTrainLoop', max_epochs=24, val_interval=1) val_cfg = dict(type='ValLoop') test_cfg = dict(type='TestLoop') param_scheduler = [ dict( type='LinearLR', start_factor=0.3333333333333333, by_epoch=False, begin=0, end=500), dict( type='MultiStepLR', begin=0, end=24, by_epoch=True, milestones=[14, 20], gamma=0.1) ] optim_wrapper = dict( type='OptimWrapper', optimizer=dict(type='SGD', lr=0.005, momentum=0.9, weight_decay=0.0001), clip_grad=dict(max_norm=35, norm_type=2)) default_scope = 'mmrotate' default_hooks = dict( timer=dict(type='IterTimerHook'), logger=dict(type='LoggerHook', interval=50), param_scheduler=dict(type='ParamSchedulerHook'), checkpoint=dict(type='CheckpointHook', interval=4), sampler_seed=dict(type='DistSamplerSeedHook'), visualization=dict( type='mmdet.DetVisualizationHook', draw=True, test_out_dir='D:\1rotate\mmrotate-1.0.0rc1\tools\run2\1', show=True, wait_time=2)) env_cfg = dict( cudnn_benchmark=False, mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0), dist_cfg=dict(backend='nccl')) vis_backends = [dict(type='TensorboardVisBackend')] visualizer = dict( type='Visualizer', vis_backends=[dict(type='TensorboardVisBackend')]) log_processor = dict(type='LogProcessor', window_size=50, by_epoch=True) log_level = 'INFO' load_from = 'D:\1rotate\mmrotate-1.0.0rc1\tools\run2\epoch_4.pth' resume = False angle_version = 'le90' model = dict( type='mmdet.FasterRCNN', data_preprocessor=dict( type='mmdet.DetDataPreprocessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_size_divisor=32, boxtype2tensor=False), backbone=dict( type='mmdet.ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=1, norm_cfg=dict(type='BN', requires_grad=True), norm_eval=True, style='pytorch', init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')), neck=dict( type='mmdet.FPN', in_channels=[256, 512, 1024, 2048], out_channels=256, num_outs=5), rpn_head=dict( type='OrientedRPNHead', in_channels=256, feat_channels=256, anchor_generator=dict( type='mmdet.AnchorGenerator', scales=[8], ratios=[0.5, 1.0, 2.0], strides=[4, 8, 16, 32, 64], use_box_type=True), bbox_coder=dict( type='MidpointOffsetCoder', angle_version='le90', target_means=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0], target_stds=[1.0, 1.0, 1.0, 1.0, 0.5, 0.5]), loss_cls=dict( type='mmdet.CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0), loss_bbox=dict( type='mmdet.SmoothL1Loss', beta=0.1111111111111111, loss_weight=1.0)), roi_head=dict( type='mmdet.StandardRoIHead', bbox_roi_extractor=dict( type='RotatedSingleRoIExtractor', roi_layer=dict( type='RoIAlignRotated', out_size=7, sample_num=2, clockwise=True), out_channels=256, featmap_strides=[4, 8, 16, 32]), bbox_head=dict( type='mmdet.Shared2FCBBoxHead', predict_box_type='rbox', in_channels=256, fc_out_channels=1024, roi_feat_size=7, num_classes=4, reg_predictor_cfg=dict(type='mmdet.Linear'), cls_predictor_cfg=dict(type='mmdet.Linear'), bbox_coder=dict( type='DeltaXYWHTRBBoxCoder', angle_version='le90', norm_factor=None, edge_swap=True, proj_xy=True, target_means=(0.0, 0.0, 0.0, 0.0, 0.0), target_stds=(0.1, 0.1, 0.2, 0.2, 0.1)), reg_class_agnostic=True, loss_cls=dict( type='mmdet.CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0), loss_bbox=dict( type='mmdet.SmoothL1Loss', beta=1.0, loss_weight=1.0))), train_cfg=dict( rpn=dict( assigner=dict( type='mmdet.MaxIoUAssigner', pos_iou_thr=0.7, neg_iou_thr=0.3, min_pos_iou=0.3, match_low_quality=True, ignore_iof_thr=-1, iou_calculator=dict(type='RBbox2HBboxOverlaps2D')), sampler=dict( type='mmdet.RandomSampler', num=256, pos_fraction=0.5, neg_pos_ub=-1, add_gt_as_proposals=False), allowed_border=0, pos_weight=-1, debug=False), rpn_proposal=dict( nms_pre=2000, max_per_img=2000, nms=dict(type='nms', iou_threshold=0.8), min_bbox_size=0), rcnn=dict( assigner=dict( type='mmdet.MaxIoUAssigner', pos_iou_thr=0.5, neg_iou_thr=0.5, min_pos_iou=0.5, match_low_quality=False, iou_calculator=dict(type='RBboxOverlaps2D'), ignore_iof_thr=-1), sampler=dict( type='mmdet.RandomSampler', num=512, pos_fraction=0.25, neg_pos_ub=-1, add_gt_as_proposals=True), pos_weight=-1, debug=False)), test_cfg=dict( rpn=dict( nms_pre=2000, max_per_img=2000, nms=dict(type='nms', iou_threshold=0.8), min_bbox_size=0), rcnn=dict( nms_pre=2000, min_bbox_size=0, score_thr=0.05, nms=dict(type='nms_rotated', iou_threshold=0.1), max_per_img=2000))) launcher = 'none' work_dir = 'run2'

06/09 21:20:29 - mmengine - INFO - Distributed training is not used, all SyncBatchNorm (SyncBN) layers in the model will be automatically reverted to BatchNormXd layers if they are used. D:\Anaconda3\envs\mmr2\lib\site-packages\mmdet\engine\hooks\visualization_hook.py:64: UserWarning: The show is True, it means that only the prediction results are visualized without storing data, so vis_backends needs to be excluded. warnings.warn('The show is True, it means that only ' 06/09 21:20:29 - mmengine - INFO - Hooks will be executed in the following order: before_run: (VERY_HIGH ) RuntimeInfoHook
(BELOW_NORMAL) LoggerHook


before_train: (VERY_HIGH ) RuntimeInfoHook
(NORMAL ) IterTimerHook
(VERY_LOW ) CheckpointHook


before_train_epoch: (VERY_HIGH ) RuntimeInfoHook
(NORMAL ) IterTimerHook
(NORMAL ) DistSamplerSeedHook


before_train_iter: (VERY_HIGH ) RuntimeInfoHook
(NORMAL ) IterTimerHook


after_train_iter: (VERY_HIGH ) RuntimeInfoHook
(NORMAL ) IterTimerHook
(BELOW_NORMAL) LoggerHook
(LOW ) ParamSchedulerHook
(VERY_LOW ) CheckpointHook


after_train_epoch: (NORMAL ) IterTimerHook
(LOW ) ParamSchedulerHook
(VERY_LOW ) CheckpointHook


before_val_epoch: (NORMAL ) IterTimerHook


before_val_iter: (NORMAL ) IterTimerHook


after_val_iter: (NORMAL ) IterTimerHook
(NORMAL ) DetVisualizationHook
(BELOW_NORMAL) LoggerHook


after_val_epoch: (VERY_HIGH ) RuntimeInfoHook
(NORMAL ) IterTimerHook
(BELOW_NORMAL) LoggerHook
(LOW ) ParamSchedulerHook
(VERY_LOW ) CheckpointHook


after_train: (VERY_LOW ) CheckpointHook


before_test_epoch: (NORMAL ) IterTimerHook


before_test_iter: (NORMAL ) IterTimerHook


after_test_iter: (NORMAL ) IterTimerHook
(NORMAL ) DetVisualizationHook
(BELOW_NORMAL) LoggerHook


after_test_epoch: (VERY_HIGH ) RuntimeInfoHook
(NORMAL ) IterTimerHook
(BELOW_NORMAL) LoggerHook


after_run: (BELOW_NORMAL) LoggerHook


Loads checkpoint by local backend from path: D:\1rotate\mmrotate-1.0.0rc1\tools\run2\epoch_4.pth 06/09 21:20:30 - mmengine - INFO - Load checkpoint from D:\1rotate\mmrotate-1.0.0rc1\tools\run2\epoch_4.pth 06/09 21:20:41 - mmengine - WARNING - "FileClient" will be deprecated in future. Please use io functions in https://mmengine.readthedocs.io/en/latest/api/fileio.html#file-io 06/09 21:20:41 - mmengine - WARNING - "HardDiskBackend" is the alias of "LocalBackend" and the former will be deprecated in future. 06/09 21:20:41 - mmengine - WARNING - "FileClient" will be deprecated in future. Please use io functions in https://mmengine.readthedocs.io/en/latest/api/fileio.html#file-io 06/09 21:20:41 - mmengine - WARNING - "HardDiskBackend" is the alias of "LocalBackend" and the former will be deprecated in future. 06/09 21:20:41 - mmengine - WARNING - "FileClient" will be deprecated in future. Please use io functions in https://mmengine.readthedocs.io/en/latest/api/fileio.html#file-io 06/09 21:20:41 - mmengine - WARNING - "HardDiskBackend" is the alias of "LocalBackend" and the former will be deprecated in future. 06/09 21:20:41 - mmengine - WARNING - "FileClient" will be deprecated in future. Please use io functions in https://mmengine.readthedocs.io/en/latest/api/fileio.html#file-io 06/09 21:20:41 - mmengine - WARNING - "HardDiskBackend" is the alias of "LocalBackend" and the former will be deprecated in future. Traceback (most recent call last): File "D:/1rotate/mmrotate-1.0.0rc1/tools/test.py", line 127, in main() File "D:/1rotate/mmrotate-1.0.0rc1/tools/test.py", line 123, in main runner.test() File "D:\Anaconda3\envs\mmr2\lib\site-packages\mmengine\runner\runner.py", line 1767, in test metrics = self.test_loop.run() # type: ignore File "D:\Anaconda3\envs\mmr2\lib\site-packages\mmengine\runner\loops.py", line 435, in run self.run_iter(idx, data_batch) File "D:\Anaconda3\envs\mmr2\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "D:\Anaconda3\envs\mmr2\lib\site-packages\mmengine\runner\loops.py", line 456, in run_iter self.runner.call_hook( File "D:\Anaconda3\envs\mmr2\lib\site-packages\mmengine\runner\runner.py", line 1785, in call_hook raise TypeError(f'{e} in {hook}') from None TypeError: add_datasample() got an unexpected keyword argument 'pred_score_thr' in <mmdet.engine.hooks.visualization_hook.DetVisualizationHook object at 0x000001F34568C9D0>

进程已结束,退出代码1

Reproduces the problem - code sample

Copyright (c) OpenMMLab. All rights reserved.

import argparse import os import os.path as osp

from mmdet.utils import register_all_modules as register_all_modules_mmdet from mmengine.config import Config, DictAction from mmengine.evaluator import DumpResults from mmengine.registry import RUNNERS from mmengine.runner import Runner

from mmrotate.utils import register_all_modules

TODO: support fuse_conv_bn and format_only

def parse_args(): parser = argparse.ArgumentParser(description='Test (and eval) a model') parser.add_argument('--config', default=r'D:\1rotate\mmrotate-1.0.0rc1\tools\run2\oriented-rcnn-le90_r50_fpn_1x_dota.py',help='test config file path') parser.add_argument('--checkpoint',default=r'D:\1rotate\mmrotate-1.0.0rc1\tools\run2\epoch_4.pth', help='checkpoint file') parser.add_argument( '--work-dir', help='the directory to save the file containing evaluation metrics') parser.add_argument( '--out', type=str, help='dump predictions to a pickle file for offline evaluation') parser.add_argument( '--show', action='store_true', help='show prediction results') parser.add_argument( '--show-dir',default=r'D:\1rotate\mmrotate-1.0.0rc1\tools\run2\1', help='directory where painted images will be saved. ' 'If specified, it will be automatically saved ' 'to the work_dir/timestamp/show_dir') parser.add_argument( '--wait-time', type=float, default=2, help='the interval of show (s)') parser.add_argument( '--cfg-options', nargs='+', action=DictAction, help='override some settings in the used config, the key-value pair ' 'in xxx=yyy format will be merged into config file. If the value to ' 'be overwritten is a list, it should be like key="[a,b]" or key=a,b ' 'It also allows nested list/tuple values, e.g. key="[(a,b),(c,d)]" ' 'Note that the quotation marks are necessary and that no white space ' 'is allowed.') parser.add_argument( '--launcher', choices=['none', 'pytorch', 'slurm', 'mpi'], default='none', help='job launcher') parser.add_argument('--local_rank', type=int, default=0) args = parser.parse_args() if 'LOCAL_RANK' not in os.environ: os.environ['LOCAL_RANK'] = str(args.local_rank) return args

def trigger_visualization_hook(cfg, args): default_hooks = cfg.default_hooks if 'visualization' in default_hooks: visualization_hook = default_hooks['visualization']

Turn on visualization

    visualization_hook['draw'] = True
    if args.show:
        visualization_hook['show'] = True
        visualization_hook['wait_time'] = args.wait_time
    if args.show_dir:
        visualization_hook['test_out_dir'] = args.show_dir
else:
    raise RuntimeError(
        'VisualizationHook must be included in default_hooks.'
        'refer to usage '
        '"visualization=dict(type=\'VisualizationHook\')"')

return cfg

def main(): args = parse_args()

# register all modules in mmdet into the registries
# do not init the default scope here because it will be init in the runner
register_all_modules_mmdet(init_default_scope=False)
register_all_modules(init_default_scope=False)

# load config
cfg = Config.fromfile(args.config)
cfg.launcher = args.launcher
if args.cfg_options is not None:
    cfg.merge_from_dict(args.cfg_options)

# work_dir is determined in this priority: CLI > segment in file > filename
if args.work_dir is not None:
    # update configs according to CLI args if args.work_dir is not None
    cfg.work_dir = args.work_dir
elif cfg.get('work_dir', None) is None:
    # use config filename as default work_dir if cfg.work_dir is None
    cfg.work_dir = osp.join('./work_dirs',
                            osp.splitext(osp.basename(args.config))[0])

cfg.load_from = args.checkpoint

if args.show or args.show_dir:
    cfg = trigger_visualization_hook(cfg, args)

# build the runner from config
if 'runner_type' not in cfg:
    # build the default runner
    runner = Runner.from_cfg(cfg)
else:
    # build customized runner from the registry
    # if 'runner_type' is set in the cfg
    runner = RUNNERS.build(cfg)

# add `DumpResults` dummy metric
if args.out is not None:
    assert args.out.endswith(('.pkl', '.pickle')), \
        'The dump file must be a pkl file.'
    runner.test_evaluator.metrics.append(
        DumpResults(out_file_path=args.out))

# start testing
runner.test()

if name == 'main': main()

Reproduces the problem - command or script

tools/test.py

Reproduces the problem - error message

Traceback (most recent call last): File "D:/1rotate/mmrotate-1.0.0rc1/tools/test.py", line 127, in main() File "D:/1rotate/mmrotate-1.0.0rc1/tools/test.py", line 123, in main runner.test() File "D:\Anaconda3\envs\mmr2\lib\site-packages\mmengine\runner\runner.py", line 1767, in test metrics = self.test_loop.run() # type: ignore File "D:\Anaconda3\envs\mmr2\lib\site-packages\mmengine\runner\loops.py", line 435, in run self.run_iter(idx, data_batch) File "D:\Anaconda3\envs\mmr2\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "D:\Anaconda3\envs\mmr2\lib\site-packages\mmengine\runner\loops.py", line 456, in run_iter self.runner.call_hook( File "D:\Anaconda3\envs\mmr2\lib\site-packages\mmengine\runner\runner.py", line 1785, in call_hook raise TypeError(f'{e} in {hook}') from None TypeError: add_datasample() got an unexpected keyword argument 'pred_score_thr' in <mmdet.engine.hooks.visualization_hook.DetVisualizationHook object at 0x000001F34568C9D0>

Additional information

No response

Czs99 commented 1 year ago

do you handle the problem?

nekiynekit commented 1 month ago

Hi! I ran into the same issue when running the inference with a custom configuration file Removing vis_backend from the config solved this problem for me.