RuntimeError:shape '[4, 98304]' is invalid for input of size 113216

Hi, I am learning to train a basic nn model for image classification, the error happened when I was trying to feed in image data into the model. I understand that I should input correct size of image data. My image data is 128*256 with 3 channels. What I don’t understand is where does the number 113216 come from? I checked all related parameters or image meta data, but didn’t find a clue. Here is my code:


Thanks for your help!

The 113216 is flattened size of x. So the product of all of the dimensions. Can you print out the shape of x before you try and reshape it like this

x = self.pool(F.relu(self.conv2(x)))
print(x.shape)

Then just type in those dimensions instead of the ones you have.

1 Like