RuntimeError: input and target shapes do not match

While running the python code I am getting the following error. Can anyone tell me where I am going wrong?
The input image is just resized from the original image. It works fine with the original image, but when I resize it produces the error.
Error-
RuntimeError: input and target shapes do not match: input [1 x 3 x 64 x 64], target [1 x 1 x 64 x 64] at /opt/conda/conda-bld/pytorch_1532502421238/work/aten/src/THCUNN/generic/MSECriterion.cu:12

How do you resize the image?
Looks like an image is RGB and the other is grayscale.

2 Likes

from PIL import Image
from resizeimage import resizeimage
with open(’/home/ccpem_project/MRC2tif_2/Falcon_2015_05_14-20_42_18.tif’, ‘r+b’) as f:
with Image.open(f) as image:
cover = resizeimage.resize_cover(image, [256, 256])
cover.save(‘tnew5.tif’, image.format)

I used this to resize the image. But if I use the original Falcon_2015_05_14-20_42_18.tif image, it works fine!

I thing the problem is that the Model is expecting a greyscale image instead of a RGB.

You should check the first layer of the Neural Net and see if the input is a 3 channel image or (as I suspect) 1.

1 Like

Well, I am new to this. How can I see if it is a 3 channel image?

I think I got what the problem is, you should check that the inputs to the function that calculates the loss are the same sire so that it can actually calculate a loss.

You would nee to use the debugger and check that both tensors have the same size. (tensor.size)

1 Like

Will try that. Thanks!