Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ke-dev opened this issue Aug 1, 2022 · 1 comment
Closed

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

ke-dev opened this issue Aug 1, 2022 · 1 comment

Comments

@ke-dev
Copy link

ke-dev commented Aug 1, 2022

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

@ke-dev ke-dev changed the title RuntimeError: mat1 dim 1 must match mat2 dim 0 TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. Aug 2, 2022
@ke-dev
Copy link
Author

ke-dev commented Aug 2, 2022

the issue has been resolved, checkpoint models should be the same or similar

@ke-dev ke-dev closed this as completed Aug 2, 2022
@ke-dev ke-dev changed the title TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first. RuntimeError: mat1 dim 1 must match mat2 dim 0 Aug 2, 2022
humu789 pushed a commit to humu789/mmrazor that referenced this issue Feb 13, 2023
* [WIP] Refactor v2.0 (open-mmlab#163)

* Refactor backend wrapper

* Refactor mmdet.inference

* Fix

* merge

* refactor utils

* Use deployer and deploy_model to manage pipeline

* Resolve comments

* Add a real inference api function

* rename wrappers

* Set execute to private method

* Rename deployer deploy_model

* Refactor task

* remove type hint

* lint

* Resolve comments

* resolve comments

* lint

* docstring

* [Fix]: Fix bugs in details in refactor branch (open-mmlab#192)

* [WIP] Refactor v2.0 (open-mmlab#163)

* Refactor backend wrapper

* Refactor mmdet.inference

* Fix

* merge

* refactor utils

* Use deployer and deploy_model to manage pipeline

* Resolve comments

* Add a real inference api function

* rename wrappers

* Set execute to private method

* Rename deployer deploy_model

* Refactor task

* remove type hint

* lint

* Resolve comments

* resolve comments

* lint

* docstring

* Fix errors

* lint

* resolve comments

* fix bugs

* conflict

* lint and typo

* Resolve comment

* refactor mmseg (open-mmlab#201)

* support mmseg

* fix docstring

* fix docstring

* [Refactor]: Get the count of backend files (open-mmlab#202)

* Fix backend files

* resolve comments

* lint

* Fix ncnn

* [Refactor]: Refactor folders of mmdet (open-mmlab#200)

* Move folders

* lint

* test object detection model

* lint

* reset changes

* fix openvino

* resolve comments

* __init__.py

* Fix path

* [Refactor]: move mmseg (open-mmlab#206)

* [Refactor]: Refactor mmedit (open-mmlab#205)

* feature mmedit

* edit2.0

* edit

* refactor mmedit

* fix __init__.py

* fix __init__

* fix formai

* fix comment

* fix comment

* Fix wrong func_name of ConvFCBBoxHead (open-mmlab#209)

* [Refactor]: Refactor mmdet unit test (open-mmlab#207)

* Move folders

* lint

* test object detection model

* lint

* WIP

* remove print

* finish unit test

* Fix tests

* resolve comments

* Add mask test

* lint

* resolve comments

* Refine cfg file

* Move files

* add files

* Fix path

* [Unittest]: Refine the unit tests in mmdet open-mmlab#214

* [Refactor] refactor mmocr to mmdeploy/codebase (open-mmlab#213)

* refactor mmocr to mmdeploy/codebase

* fix docstring of show_result

* fix docstring of visualize

* refine docstring

* replace print with logging

* refince codes

* resolve comments

* resolve comments

* [Refactor]: mmseg  tests (open-mmlab#210)

* refactor mmseg tests

* rename test_codebase

* update

* add model.py

* fix

* [Refactor] Refactor mmcls and the package (open-mmlab#217)

* refactor mmcls

* fix yapf

* fix isort

* refactor-mmcls-package

* fix print to logging

* fix docstrings according to others comments

* fix comments

* fix comments

* fix allentdans comment in pr215

* remove mmocr init

* [Refactor] Refactor mmedit tests (open-mmlab#212)

* feature mmedit

* edit2.0

* edit

* refactor mmedit

* fix __init__.py

* fix __init__

* fix formai

* fix comment

* fix comment

* buff

* edit test and code refactor

* refactor dir

* refactor tests/mmedit

* fix docstring

* add test coverage

* fix lint

* fix comment

* fix comment

* Update typehint (open-mmlab#216)

* update type hint

* update docstring

* update

* remove file

* fix ppl

* Refine get_predefined_partition_cfg

* fix tensorrt version > 8

* move parse_cuda_device_id to device.py

* Fix cascade

* onnx2ncnn docstring

Co-authored-by: Yifan Zhou <singlezombie@163.com>
Co-authored-by: RunningLeon <maningsheng@sensetime.com>
Co-authored-by: VVsssssk <88368822+VVsssssk@users.noreply.github.com>
Co-authored-by: AllentDan <41138331+AllentDan@users.noreply.github.com>
Co-authored-by: hanrui1sensetime <83800577+hanrui1sensetime@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant