mmrotate icon indicating copy to clipboard operation
mmrotate copied to clipboard

[Bug] TypeError: class `RTMDet` in mmdet/models/detectors/rtmdet.py: __init__() got an unexpected keyword argument 'pretrained'

Open 18735549442 opened this issue 1 year ago • 9 comments

Prerequisite

Task

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

Branch

1.x branch https://github.com/open-mmlab/mmrotate/tree/1.x

Environment

sys.platform: linux Python: 3.7.11 (default, Jul 27 2021, 14:32:16) [GCC 7.5.0] CUDA available: True numpy_random_seed: 2147483648 GPU 0: Tesla T4 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 11.1, V11.1.105 GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 PyTorch: 1.10.0 PyTorch compiling details: PyTorch built with:

  • GCC 7.3
  • C++ Version: 201402
  • Intel(R) oneAPI Math Kernel Library Version 2021.4-Product Build 20210904 for Intel(R) 64 architecture applications
  • Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740)
  • OpenMP 201511 (a.k.a. OpenMP 4.5)
  • LAPACK is enabled (usually provided by MKL)
  • NNPACK is enabled
  • CPU capability usage: AVX512
  • CUDA Runtime 11.1
  • NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_37,code=compute_37
  • CuDNN 8.0.5
  • Magma 2.5.2
  • Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.1, CUDNN_VERSION=8.0.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON,

TorchVision: 0.11.1 OpenCV: 4.7.0 MMEngine: 0.6.0 MMRotate: 1.0.0rc1+20e8a5c

Reproduces the problem - code sample

configs/rotated_rtmdet/rotated_rtmdet_l-3x-dota.py

Reproduces the problem - command or script

python -m torch.distributed.launch --nproc_per_node=1 --master_port=29500 tools/analysis_tools/benchmark.py configs/rotated_rtmdet/rotated_rtmdet_l-3x-dota.py checkpoints/rotated_rtmdet_l-3x-dota-23992372.pth) --launcher pytorch --task inference --dataset-type val

Reproduces the problem - error message

Traceback (most recent call last): File "/opt/conda/lib/python3.7/site-packages/mmengine/registry/build_functions.py", line 121, in build_from_cfg obj = obj_cls(**args) # type: ignore TypeError: init() got an unexpected keyword argument 'pretrained'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "benchmark.py", line 141, in main() File "benchmark.py", line 136, in main benchmark = eval(f'{args.task}_benchmark')(args, cfg, distributed, logger) File "benchmark.py", line 87, in inference_benchmark logger=logger) File "/opt/conda/lib/python3.7/site-packages/mmdet/utils/benchmark.py", line 164, in init self.model = self._init_model(checkpoint, is_fuse_conv_bn) File "/opt/conda/lib/python3.7/site-packages/mmdet/utils/benchmark.py", line 180, in _init_model model = MODELS.build(self.cfg.model) File "/opt/conda/lib/python3.7/site-packages/mmengine/registry/registry.py", line 548, in build return self.build_func(cfg, *args, **kwargs, registry=self) File "/opt/conda/lib/python3.7/site-packages/mmengine/registry/build_functions.py", line 241, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/opt/conda/lib/python3.7/site-packages/mmengine/registry/build_functions.py", line 136, in build_from_cfg f'class {obj_cls.__name__} in ' # type: ignore TypeError: class RTMDet in mmdet/models/detectors/rtmdet.py: init() got an unexpected keyword argument 'pretrained' ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 0 (pid: 821) of binary: /opt/conda/bin/python Traceback (most recent call last): File "/opt/conda/lib/python3.7/runpy.py", line 193, in _run_module_as_main "main", mod_spec) File "/opt/conda/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/opt/conda/lib/python3.7/site-packages/torch/distributed/launch.py", line 193, in main() File "/opt/conda/lib/python3.7/site-packages/torch/distributed/launch.py", line 189, in main launch(args) File "/opt/conda/lib/python3.7/site-packages/torch/distributed/launch.py", line 174, in launch run(args) File "/opt/conda/lib/python3.7/site-packages/torch/distributed/run.py", line 713, in run )(*cmd_args) File "/opt/conda/lib/python3.7/site-packages/torch/distributed/launcher/api.py", line 131, in call return launch_agent(self._config, self._entrypoint, list(args)) File "/opt/conda/lib/python3.7/site-packages/torch/distributed/launcher/api.py", line 261, in launch_agent failures=result.failures, torch.distributed.elastic.multiprocessing.errors.ChildFailedError:

benchmark.py FAILED

Failures: <NO_OTHER_FAILURES>

Root Cause (first observed failure): [0]: time : 2023-04-10_20:24:32 host : fa6f52200d793011ed0917a0c7f822b9ff09-task1-0.fa6f52200d793011ed0917a0c7f822b9ff09.ed9ed5aa2938366557d3851691b38794.svc.cluster.local rank : 0 (local_rank: 0) exitcode : 1 (pid: 821) error_file: <N/A> traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html

Additional information

No response

18735549442 avatar Apr 10 '23 12:04 18735549442

python -m torch.distributed.launch --nproc_per_node=1 --master_port=29500 tools/analysis_tools/benchmark.py configs/rotated_rtmdet/rotated_rtmdet_l-3x-dota.py checkpoints/rotated_rtmdet_l-3x-dota-23992372.pth --launcher pytorch --task inference --dataset-type val there is no ')' for ckpt. when i open the issue, i wrongly type it.

18735549442 avatar Apr 10 '23 12:04 18735549442

me too!

Zeba-Xie avatar Apr 18 '23 12:04 Zeba-Xie

这是来自QQ邮箱的假期自动回复邮件。   您好,我已收到您的邮件。我将尽快给您回复。

18735549442 avatar Apr 18 '23 12:04 18735549442

我添加了这个代码到mmdet/utils/benchmark.py中的_init_model可以解决上述问题

if 'pretrained' in self.cfg.model:
            print("cfg.model", self.cfg.model)
            del self.cfg.model['pretrained']

但是依然会出现其他错误:

TypeError: conv2d() received an invalid combination of arguments - got (dict, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:
 * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
      didn't match because some of the arguments have invalid types: (dict, Parameter, NoneType, tuple, tuple, tuple, int)
 * (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
      didn't match because some of the arguments have invalid types: (dict, Parameter, NoneType, tuple, tuple, tuple, int)

Zeba-Xie avatar Apr 18 '23 12:04 Zeba-Xie

我是在detector的__init__函数参数中加入pretrained参数。结果也是出现你这个报错。 我打印conv2d的input参数如下: {'inputs': [tensor([[[54, 54, 55, ..., 53, 53, 53], [54, 54, 55, ..., 53, 53, 53], [55, 54, 55, ..., 53, 53, 53], ..., [52, 51, 51, ..., 55, 55, 54], [52, 52, 52, ..., 54, 55, 55], [54, 54, 54, ..., 54, 55, 54]],

    [[54, 54, 55,  ..., 53, 53, 53],
     [54, 54, 55,  ..., 53, 53, 53],
     [55, 54, 55,  ..., 53, 53, 53],
     ...,
     [52, 51, 51,  ..., 55, 55, 54],
     [52, 52, 52,  ..., 54, 55, 55],
     [54, 54, 54,  ..., 54, 55, 54]],

    [[54, 54, 55,  ..., 53, 53, 53],
     [54, 54, 55,  ..., 53, 53, 53],
     [55, 54, 55,  ..., 53, 53, 53],
     ...,
     [52, 51, 51,  ..., 55, 55, 54],
     [52, 52, 52,  ..., 54, 55, 55],
     [54, 54, 54,  ..., 54, 55, 54]]], device='cuda:0', dtype=torch.uint8)], 'data_samples': [<DetDataSample(

META INFORMATION
img_shape: (1024, 1024)
img_id: 'P1569__1024__2472___2472'
scale_factor: (1.0, 1.0)
img_path: '/dataset/val/images/P1569__1024__2472___2472.png'
ori_shape: (1024, 1024)

DATA FIELDS
ignored_instances: <InstanceData(
    
        META INFORMATION
    
        DATA FIELDS
        bboxes: RotatedBoxes(
            tensor([], size=(0, 5)))
        labels: tensor([], dtype=torch.int64)
    ) at 0x7fa738058850>
gt_instances: <InstanceData(
    
        META INFORMATION
    
        DATA FIELDS
        bboxes: RotatedBoxes(
            tensor([], size=(0, 5)))
        labels: tensor([], dtype=torch.int64)
    ) at 0x7fa738058a90>

) at 0x7fa738058d90>]} 我将input的inputs对应的张量提供给conv2d后,会报矩阵维度不一致的错误。 看报错反馈,感觉是mmdet的inference_benchmark()对原始图像像素矩阵处理有问题。 但我还没尝试mmdetection中的benchmark.py。

18735549442 avatar Apr 19 '23 09:04 18735549442

我是这样暂时解决这个问题的:

# mmdet/utils/benchmark.py
# InferenceBenchmark.run_once中修改
self.model(data['inputs'][0][None].float())

Zeba-Xie avatar Apr 19 '23 10:04 Zeba-Xie

兄弟,你好厉害👍

18735549442 avatar Apr 23 '23 07:04 18735549442

我是这样暂时解决这个问题的:

# mmdet/utils/benchmark.py
# InferenceBenchmark.run_once中修改
self.model(data['inputs'][0][None].float())

好牛啊,您是怎么想到的

zhu011 avatar Aug 01 '23 05:08 zhu011

这是来自QQ邮箱的假期自动回复邮件。   您好,我已收到您的邮件。我将尽快给您回复。

18735549442 avatar Aug 01 '23 05:08 18735549442