open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.43k stars 9.43k forks source link

TypeError: Mask2Former: __init__() got an unexpected keyword argument 'pretrained' #9104

Closed LiWentomng closed 2 years ago

LiWentomng commented 2 years ago

Prerequisite

🐞 Describe the bug

When I try the script of the below to get the FPS

python -m torch.distributed.launch --nproc_per_node=1 --master_port=29500 tools/analysis_tools/benchmark.py configs/mask2former/mask2former_r50_lsj_8x2_50e_coco.py work_dirs/mask2former/iter_737500.pth --launcher pytorch

I encounter the below erro:

Traceback (most recent call last):
  File "/root/miniconda3/envs/mmdet-mask2former/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
TypeError: __init__() got an unexpected keyword argument 'pretrained'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tools/analysis_tools/benchmark.py", line 195, in <module>
    main()
  File "tools/analysis_tools/benchmark.py", line 191, in main
    args.repeat_num)
  File "tools/analysis_tools/benchmark.py", line 152, in repeat_measure_inference_speed
    is_fuse_conv_bn))
  File "tools/analysis_tools/benchmark.py", line 85, in measure_inference_speed
    model = build_detector(cfg.model, test_cfg=cfg.get('test_cfg'))
  File "/home/lwt/code/mask2former_all/mmdet/models/builder.py", line 59, in build_detector
    cfg, default_args=dict(train_cfg=train_cfg, test_cfg=test_cfg))
  File "/root/miniconda3/envs/mmdet-mask2former/lib/python3.7/site-packages/mmcv/utils/registry.py", line 215, in build
    return self.build_func(*args, **kwargs, registry=self)
  File "/root/miniconda3/envs/mmdet-mask2former/lib/python3.7/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg
    return build_from_cfg(cfg, registry, default_args)
  File "/root/miniconda3/envs/mmdet-mask2former/lib/python3.7/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
TypeError: Mask2Former: __init__() got an unexpected keyword argument 'pretrained'

However, I run the test.py as below, it can work well without this error.

python tools/test.py configs/mask2former/mask2former_r50_lsj_8x2_50e_coco.py work_dirs/mask2former/iter_737500.pth --eval segm

Look forward to the reply. Thanks!

Environment

sys.platform: linux Python: 3.7.13 (default, Mar 29 2022, 02:18:16) [GCC 7.5.0] CUDA available: True GPU 0,1,2,3,4,5,6,7: Tesla V100-SXM2-32GB CUDA_HOME: /usr/local/cuda-11.4 NVCC: Cuda compilation tools, release 11.4, V11.4.152 GCC: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609 PyTorch: 1.7.1+cu101 PyTorch compiling details: PyTorch built with:

TorchVision: 0.8.2+cu101 OpenCV: 4.6.0 MMCV: 1.5.0 MMCV Compiler: GCC 7.3 MMCV CUDA Compiler: 10.1 MMDetection: 2.25.0+

Additional information

No response

LiWentomng commented 2 years ago

Additional information: The script tools/analysis_tools/benchmark.py to FPS can run well on other models, like Mask R-CNN and SOLO.

LiWentomng commented 2 years ago

The tools/analysis_tools/benchmark.py need to be refined.

The above error can be resolved by

replacing

cfg.model.pretrained = None (line 64)

to

 if 'pretrained' in cfg.model:
     cfg.model.pretrained = None
 elif 'init_cfg' in cfg.model.backbone:
     cfg.model.backbone.init_cfg = None