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 : Size of Tensros must match except in dimension 1 #1674

Open
Jiwno opened this issue Sep 12, 2024 · 1 comment
Open

RunTimeError : Size of Tensros must match except in dimension 1 #1674

Jiwno opened this issue Sep 12, 2024 · 1 comment

Comments

@Jiwno
Copy link

Jiwno commented Sep 12, 2024

Hi, I'm having trouble with training pix2pix model with my data.
I have a run time error that I've never seen it before when I use other datasets.
is there any solution to figure this out?

python train.py --dataroot .\datasets\soolsool_5760_2880_60_30 --name soolsool_v1 --model pix2pix --direction BtoA --load_size 1440 --crop_size 1440 --preprocess none --no_dropout --input_nc 4 --output_nc 4

error message : Sizes of tensors must match except in dimension 1. Expected size 45 but got size 44 for tensor number 1 in the list.

File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\pix2pix_model.py", line 117, in optimize_parameters
self.forward() # compute fake images: G(A)
^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\pix2pix_model.py", line 88, in forward
self.fake_B = self.netG(self.real_A) # G(A)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\parallel\data_parallel.py", line 184, in forward
return self.module(*inputs[0], **module_kwargs[0])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 466, in forward
return self.model(input)
^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 534, in forward
return self.model(x)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\container.py", line 219, in forward
input = module(input)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 536, in forward
return torch.cat([x, self.model(x)], 1)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\container.py", line 219, in forward
input = module(input)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 536, in forward
return torch.cat([x, self.model(x)], 1)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\container.py", line 219, in forward
input = module(input)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 536, in forward
return torch.cat([x, self.model(x)], 1)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\container.py", line 219, in forward
input = module(input)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 536, in forward
return torch.cat([x, self.model(x)], 1)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\container.py", line 219, in forward
input = module(input)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 536, in forward
return torch.cat([x, self.model(x)], 1)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\container.py", line 219, in forward
input = module(input)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 536, in forward
return torch.cat([x, self.model(x)], 1)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\container.py", line 219, in forward
input = module(input)
^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\USER\anaconda3\envs\pix2pix\Lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\04_pix2pix\pytorch-CycleGAN-and-pix2pix-master\models\networks.py", line 536, in forward
return torch.cat([x, self.model(x)], 1)

@nhansendev
Copy link

Since model outputs are being concatenated with inputs torch.cat([x, self.model(x)], 1) (a form of skip-connection) their dimensions must match except for dimension 1. The issue is simply that one part of the generator network is not producing the expected tensor dimensions (size 44 instead of 45), though it doesn't say which dimension is mismatched. If the feature size is the issue, then this can be addressed by adjusting the kernel size and/or padding of the relevant convolution layers.

I find that printing the model summary with https://pypi.org/project/torch-summary/ and some dummy data helps with debugging this.

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