open-mmlab / mmcv

OpenMMLab Computer Vision Foundation
https://mmcv.readthedocs.io/en/latest/
Apache License 2.0
5.93k stars 1.66k forks source link

torch.nn.modules.module.ModuleAttributeError: MaskRCNN: 'Sequential' object has no attribute 'init_weights #1590

Closed LZYmixiu closed 2 years ago

LZYmixiu commented 2 years ago

When I training the model which type is maskrcnn, the error likes title was encouraged, dose anyone knows what's going on? or have met this erro before? The problem seems like in mmcv. The Traceback is:

Traceback (most recent call last):
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg
    return obj_cls(**args)
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/mmdet-2.11.0-py3.7.egg/mmdet/models/detectors/mask_rcnn.py", line 24, in __init__    pretrained=pretrained)
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/mmdet-2.11.0-py3.7.egg/mmdet/models/detectors/two_stage.py", line 48, in __init__                                             rixzerogoki" 10:54 16-12月-21
    self.init_weights(pretrained=pretrained)
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/mmdet-2.11.0-py3.7.egg/mmdet/models/detectors/two_stage.py", line 78, in init_weights
    self.roi_head.init_weights(pretrained)
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/mmdet-2.11.0-py3.7.egg/mmdet/models/roi_heads/standard_roi_head.py", line 48, in init_weights
    self.bbox_head.init_weights()
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/torch/nn/modules/module.py", line 779, in __getattr__
    type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'Sequential' object has no attribute 'init_weights'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./tools/train.py", line 187, in <module>
    main()
  File "./tools/train.py", line 161, in main
    test_cfg=cfg.get('test_cfg'))
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/mmdet-2.11.0-py3.7.egg/mmdet/models/builder.py", line 77, in build_detector
    return build(cfg, DETECTORS, dict(train_cfg=train_cfg, test_cfg=test_cfg))
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/mmdet-2.11.0-py3.7.egg/mmdet/models/builder.py", line 34, in build
    return build_from_cfg(cfg, registry, default_args)
  File "/home/ljo4sgh/miniconda3/envs/new-swin-T/lib/python3.7/site-packages/mmcv/utils/registry.py", line 55, in build_from_cfg
    raise type(e)(f'{obj_cls.__name__}: {e}')
torch.nn.modules.module.ModuleAttributeError: MaskRCNN: 'Sequential' object has no attribute 'init_weights'

ps: I haven't modified the test_cfg in my own config.

MeowZheng commented 2 years ago

What's the version of MMCV? Actually, we have added Sequential in MMCV which has init_weights https://github.com/open-mmlab/mmcv/blob/e4b5348ebf407f0886bc11caa7ca74d2fbf693ac/mmcv/runner/base_module.py#L172-L181

LZYmixiu commented 2 years ago

What's the version of MMCV? Actually, we have added Sequential in MMCV which has init_weights

https://github.com/open-mmlab/mmcv/blob/e4b5348ebf407f0886bc11caa7ca74d2fbf693ac/mmcv/runner/base_module.py#L172-L181 Version: mmcv-full 1.4.0
mmdet 2.11.0
mmpycocotools 12.0.3

jshilong commented 2 years ago

mmdet 2.11.0 is not compatible with MMCV 1.4.0, please update your mmdetection to latest version or degrad your mmcv to ~ 1.2.4

LZYmixiu commented 2 years ago

It still would be torch.nn.modules.module.ModuleAttributeError: 'Sequential' object has no attribute 'init_weights'after I downgrade mmcv-full to 1.2.4 And new error TypeError: MaskRCNN: SwinTransformer: __init__() got an unexpected keyword argument 'embed_dim'be encouraged after I upgrade mmde to 2.19.1 (In this situation mmcv is 1.4.0)

LZYmixiu commented 2 years ago

I found it's a mistake form my config file And the version I used is: mmcv-full 1.4.0 pypi_0 pypi mmdet 2.11.0 pypi_0 pypi mmpycocotools 12.0.3 pypi_0 pypi Thanks every replier under this issue!