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

Mis-matched tensors. #22

Open
DraBard opened this issue Jun 5, 2023 · 1 comment
Open

Mis-matched tensors. #22

DraBard opened this issue Jun 5, 2023 · 1 comment

Comments

@DraBard
Copy link

DraBard commented Jun 5, 2023

Hello and thank you for you work.

My input image is 1360x1814 and I get the following error:

 File "/Users/user3/Documents/projects/TLC/basicsr/models/archs/mprnet_arch.py", line 192, in forward
    x = x + y
        ~~^~~
RuntimeError: The size of tensor a (452) must match the size of tensor b (453) at non-singleton dimension 2

tensor's a shape torch.Size([1, 144, 452, 680])
tensor's b shape torch.Size([1, 144, 453, 680])

That happens on some i'th forward step. it is quite strange, that the mismatched happens, isnt it ?

@achusky
Copy link
Collaborator

achusky commented Jun 9, 2023

Hi, sorry for the late reply.

The size mismatch issue is caused by the downsampled features and upsampled features from the 'UNet-like' skip connection.
A toy example is:
(1) input feature x with spatial size 7,
(2) then downsampled by 2x (with padding) and get a downsampled feature x_down with spatial size 4,
(3) upsample the x_down by 2x and get upscaled feature x_up with spatial size 8,
(4) add x_up with x and meets spatial size mismatch issue (8 vs 7)
The solution is to check the size of the input image and pad the image if needed. For example, we can pad the x in the above example to 8. The key code is here.

Hope this helps you.

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