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 Tensor size mismatch after following the instructions mentioned on this repo README #60

Open
sajidahmed12 opened this issue Oct 28, 2023 · 4 comments

Comments

@sajidahmed12
Copy link

python test.py --epoch 499 --folder demo/custom-chkpts --pose_folder demo/sample/poses --key_frame_path demo/sample/image/0024.jpg --s1 8 --s2 3 --n_steps 100 --output_dir demo/sample/results --custom_vae demo/custom-chkpts/vae_1499.pth

Traceback (most recent call last):
  File "/home/UserName/user/DreamPose/test.py", line 48, in <module>
    unet = get_unet('CompVis/stable-diffusion-v1-4', "ebb811dd71cdc38a204ecbdd6ac5d580f529fd8c", resolution=512)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/UserName/user/DreamPose/models/unet_dual_encoder.py", line 30, in get_unet
    unet.conv_in.weight[:, 4:] = torch.zeros(unet.conv_in.weight[:, 3:].shape) # new weights initialized to zero
    ~~~~~~~~~~~~~~~~~~~^^^^^^^
RuntimeError: The expanded size of the tensor (10) must match the existing size (11) at non-singleton dimension 1.  Target sizes: [320, 10, 3, 3].  Tensor sizes: [320, 11, 3, 3]

(yolo) UserName@user-Desktop:~/user/DreamPose$ python test.py --epoch 499 --folder demo/custom-chkpts --pose_folder demo/sample/poses  --key_frame_path demo/sample/key_frame.png --s1 8 --s2 3 --n_steps 100 --output_dir demo/sample/results --custom_vae demo/custom-chkpts/vae_1499.pth
Traceback (most recent call last):
  File "/home/altersense_dragon/sajid/DreamPose/test.py", line 48, in <module>
    unet = get_unet('CompVis/stable-diffusion-v1-4', "ebb811dd71cdc38a204ecbdd6ac5d580f529fd8c", resolution=512)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/UserName/user/DreamPose/models/unet_dual_encoder.py", line 30, in get_unet
    unet.conv_in.weight[:, 4:] = torch.zeros(unet.conv_in.weight[:, 3:].shape) # new weights initialized to zero
    ~~~~~~~~~~~~~~~~~~~^^^^^^^
RuntimeError: The expanded size of the tensor (10) must match the existing size (11) at non-singleton dimension 1.  Target sizes: [320, 10, 3, 3].  Tensor sizes: [320, 11, 3, 3]
@jqliu09
Copy link

jqliu09 commented Nov 25, 2023

Same problem encountered. It seems to be caused by the commit "Fix weight initialization in models/unet_dual_encoder.py."

@NolenBrolen
Copy link

Same problem here, tried checking out older branches but also ran into errors there due to mismatch n the keys in the saved state dictionary and the keys that the model expects.

According to ChatGPT this often happens when the architecture of the model has changed between the time it was saved and the time it's being loaded, which means that either the saved model is outdated, or the code defining the model has been updated since.

@liuzhuangyuan
Copy link

+1

@SaharaSheik
Copy link

I solved this by making the following changes to in this file models/unet_dual_encoder.py line 30
https://github.com/johannakarras/DreamPose/blob/5bf30b7df70cf6f2e0bb25556c6ff2cbf0f2b1bf/models/unet_dual_encoder.py#L30C1-L30C117

        unet.conv_in.weight[:, 4:] = torch.zeros(unet.conv_in.weight[:, 3:].shape) # new weights initialized to zero

change to

        unet.conv_in.weight[:, 4:] = torch.zeros(unet.conv_in.weight[:, 4:].shape) # new weights initialized to zero

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

5 participants