Swin-Transformer icon indicating copy to clipboard operation
Swin-Transformer copied to clipboard

The problem of size mismatch and training weight mismatch occurred when importing (swinv2_tiny_patch4_window16_256.pth) into Swin-v2

Open LUO77123 opened this issue 2 years ago • 2 comments

When I import (swinv2_tiny_patch4_window8_256.pth) and use window 8, I can run the code normally; However, when I import (swinv2_tiny_patch4_window16_256.pth) and the usage window is 16, the import weights do not match; I don't know how to deal with it. Please answer my questions. The questions are as follows: (当我导入swinv2_tiny_patch4_window8_256.pth,使用窗口为8时候,可以正常跑代码;但是当我导入swinv2_tiny_patch4_window16_256.pth,使用窗口为16时候,导入权重出现不匹配情况;不知道如何处理,请大佬解答一下。 问题如下:) Traceback (most recent call last): File "/home/zhuyu/anaconda3/envs/yolo5obb/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/home/zhuyu/anaconda3/envs/yolo5obb/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/zhuyu/.vscode-server/extensions/ms-python.python-2022.12.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/main.py", line 39, in cli.main() File "/home/zhuyu/.vscode-server/extensions/ms-python.python-2022.12.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main run() File "/home/zhuyu/.vscode-server/extensions/ms-python.python-2022.12.0/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file runpy.run_path(target, run_name="main") File "/home/zhuyu/.vscode-server/extensions/ms-python.python-2022.12.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path return _run_module_code(code, init_globals, run_name, File "/home/zhuyu/.vscode-server/extensions/ms-python.python-2022.12.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code _run_code(code, mod_globals, init_globals, File "/home/zhuyu/.vscode-server/extensions/ms-python.python-2022.12.0/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "/home/C/LUOLIE/yolov5-6.1-obb-linux/trainad.py", line 1330, in main(opt) File "/home/C/LUOLIE/yolov5-6.1-obb-linux/trainad.py", line 1194, in main train(opt.hyp, opt, device, callbacks) File "/home/C/LUOLIE/yolov5-6.1-obb-linux/trainad.py", line 508, in train model.load_state_dict(dic4, strict=False) # load File "/home/zhuyu/anaconda3/envs/yolo5obb/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1051, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for Model: size mismatch for model.7.blocks.0.attn.relative_coords_table: copying a param with shape torch.Size([1, 15, 15, 2]) from checkpoint, the shape in current model is torch.Size([1, 31, 31, 2]). size mismatch for model.7.blocks.0.attn.relative_position_index: copying a param with shape torch.Size([64, 64]) from checkpoint, the shape in current model is torch.Size([256, 256]). size mismatch for model.7.blocks.1.attn.relative_coords_table: copying a param with shape torch.Size([1, 15, 15, 2]) from checkpoint, the shape in current model is torch.Size([1, 31, 31, 2]). size mismatch for model.7.blocks.1.attn.relative_position_index: copying a param with shape torch.Size([64, 64]) from checkpoint, the shape in current model is torch.Size([256, 256]).

LUO77123 avatar Aug 14 '22 15:08 LUO77123

同学,找到原因了吗,求解答

liu-guo-jing avatar Jul 10 '23 05:07 liu-guo-jing

I have the same question

semaphore-egg avatar Jun 07 '24 07:06 semaphore-egg