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

Getting shape mismatch error when using a different input #31

Open
RajShekhorRoy opened this issue Jun 30, 2023 · 2 comments
Open

Getting shape mismatch error when using a different input #31

RajShekhorRoy opened this issue Jun 30, 2023 · 2 comments

Comments

@RajShekhorRoy
Copy link

getting this error RuntimeError: mat1 and mat2 shapes cannot be multiplied (128x128 and 256x128)

when I am using the code below which is basically an array of size 32x32x32 and timesteps of 128:

size = 32
device_val="cuda"
x_input = torch.tensor(np.random.rand(1,size, size, size)).to(device_val).type(torch.cuda.FloatTensor)
diffusion = Diffusion(img_size=size, device=device_val)
t = diffusion.sample_timesteps(128).to(device_val)
model = UNet().to(device_val)
xmodel=model(x_input,t)

In addition to that can you please explain a bit more how is this time embedding working especially in terms of the dimension?

@dome272
Copy link
Owner

dome272 commented Jun 30, 2023 via email

@RajShekhorRoy
Copy link
Author

Here is the full error:

Traceback (most recent call last):
File "/home/rajroy/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/212.4746.96/plugins/python/helpers/pydev/pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rajroy/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/212.4746.96/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/rajroy/Diffusion-Models-pytorch/test.py", line 80, in
xmodel=model(x_input,t)
^^^^^^^^^^^^^^^^
File "/home/rajroy/anaconda3/envs/py_cryo/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rajroy/Diffusion-Models-pytorch/original_moduels.py", line 170, in forward
x2 = self.down1(x1, t)
^^^^^^^^^^^^^^^^^
File "/home/rajroy/anaconda3/envs/py_cryo/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rajroy/Diffusion-Models-pytorch/original_moduels.py", line 98, in forward
emb = self.emb_layer(t)[:, :, None, None].repeat(1, 1, x.shape[-2], x.shape[-1])
^^^^^^^^^^^^^^^^^
File "/home/rajroy/anaconda3/envs/py_cryo/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rajroy/anaconda3/envs/py_cryo/lib/python3.11/site-packages/torch/nn/modules/container.py", line 217, in forward
input = module(input)
^^^^^^^^^^^^^
File "/home/rajroy/anaconda3/envs/py_cryo/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rajroy/anaconda3/envs/py_cryo/lib/python3.11/site-packages/torch/nn/modules/linear.py", line 114, in forward
return F.linear(input, self.weight, self.bias)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: mat1 and mat2 shapes cannot be multiplied (128x128 and 256x128)
python-BaseException

One more thing is that I changed the default parameter in the model to provide the input channel number, in this way:

class UNet(nn.Module):
def init(self, c_in=32, c_out=32, time_dim=128, device="cuda"):

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

2 participants