RuntimeError: Given input size: (512x1x1). Calculated output size: (512x0x0). Output size is too small
Cause of Error
This error occurs when the input size is smaller than the kernel size.
In my case, I tried to run VGG16 on MNIST dataset, there were 5 pooling layers with 2x2 kernel. The original image size of MNIST is 28x28, and it becomes 0x0 after 5th pooling layer.
So the 0x0 shaped feature map couldn't be put on remain layers.
Solution
You just need to make the image size bigger than the kernel size of pooling layer where error occurs.
Choice 1. To increase the size of input shape (i.e. input size of a image)
Choice 2. To decrease the kernel size of a pooling layer
Choice 3. To decrease the number of pooling layer
I choosed Choice 1.
For option 1, I added transforms.Resize() to increase the input_size of a image. (Pytorch)
Error message
RuntimeError: Given input size: (512x1x1). Calculated output size: (512x0x0). Output size is too small
Cause of Error
This error occurs when the input size is smaller than the kernel size. In my case, I tried to run VGG16 on MNIST dataset, there were 5 pooling layers with 2x2 kernel.
The original image size of MNIST is 28x28, and it becomes 0x0 after 5th pooling layer.
So the 0x0 shaped feature map couldn't be put on remain layers.
Solution
You just need to make the image size bigger than the kernel size of pooling layer where error occurs.
I choosed Choice 1.
For option 1, I added
transforms.Resize()
to increase theinput_size
of a image. (Pytorch)For option 2 & 3, you can consider the fomula that calulates the size(H, W) of a output feature.