I just want to add on that I, too, had the same problem and this solved it.
My input images were of size 224*224 (1 channel, grayscale).
My batch size was chosen to be 32.
So for x = x.view(-1, channels*height*width) (note -1 since I’m flattening), I had to do:
height = width = sqrt( E / 32 / 16 ) where E comes from:
“RuntimeError: shape ‘[-1, 400]’ is invalid for input of size E”
and channels is the number of filter channels from the previous convolution layer.
I guess that the formula here is:
height = width = sqrt( E / batch_size / n_channels)