Skip to content

RuntimeError: mat1 dim 1 must match mat2 dim 0 #216

@ke-dev

Description

@ke-dev

Checklist

  • I have searched related issues but cannot get the expected help.
  • I have read related documents and don't know what to do.

Describe the question you meet

hi developer, when I try to change backbone resnet of teachers and students to swin

1659341381495

I got the following error
Traceback (most recent call last): File "./tools/mmcls/train_mmcls.py", line 203, in <module> main() File "./tools/mmcls/train_mmcls.py", line 174, in main algorithm.init_weights() File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/base_module.py", line 116, in init_weights m.init_weights() File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/base_module.py", line 116, in init_weights m.init_weights() File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/base_module.py", line 105, in init_weights initialize(self, self.init_cfg) File "/opt/conda/lib/python3.7/site-packages/mmcv/cnn/utils/weight_init.py", line 613, in initialize _initialize(module, cp_cfg) File "/opt/conda/lib/python3.7/site-packages/mmcv/cnn/utils/weight_init.py", line 517, in _initialize func(module) File "/opt/conda/lib/python3.7/site-packages/mmcv/cnn/utils/weight_init.py", line 494, in __call__ logger=logger) File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/checkpoint.py", line 602, in load_checkpoint load_state_dict(model, state_dict, strict, logger) File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/checkpoint.py", line 80, in load_state_dict load(module) File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/checkpoint.py", line 78, in load load(child, prefix + name + '.') File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/checkpoint.py", line 75, in load err_msg) File "/opt/conda/lib/python3.7/site-packages/mmcls-0.23.2-py3.7.egg/mmcls/models/backbones/swin_transformer.py", line 457, in _load_from_state_dict *args, **kwargs) File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1127, in _load_from_state_dict hook(state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs) File "/opt/conda/lib/python3.7/site-packages/mmcls-0.23.2-py3.7.egg/mmcls/models/backbones/swin_transformer.py", line 525, in _prepare_relative_position_bias_table relative_position_bias_table_pretrained, nH1) File "/opt/conda/lib/python3.7/site-packages/mmcls-0.23.2-py3.7.egg/mmcls/models/utils/embed.py", line 104, in resize_relative_position_bias_table z = table[:, i].view(src_shape, src_shape).float().numpy() TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

the command I use is
python ./tools/mmcls/train_mmcls.py \ /workspace/mmrazor/configs/distill/wsld/swin_tiny_distill_wsld_01.py \ --work-dir ./work_dir \ --cfg-options algorithm.distiller.teacher.init_cfg.type=Pretrained

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions