Size mismatch error in CNN FC layer

Here is a simple function you can use, based on the docs, to calculate the output size from any convolution or pooling layer:

import math
def calc_conv_size(length, kernel_size, stride=1, padding=0, dilation=1):
    return math.floor((length + 2*padding - dilation*(kernel_size-1)-1)/stride+1)

For example:

out1=calc_conv_size(224, 5, 1, 1) #Conv2d
print(out1)
out2=calc_conv_size(out1, 3, 2) #MaxPool2d
print(out2)