Hello Sir ptrblck,
Can you please point what am i wrong here. I am replicating VGG19_bn architecture (NOT Pre-Trained) for designing a CNN model for image classification. I have image 224x224 having output classes as 20.
I am getting this Error:
RuntimeError: size mismatch, m1: [64 x 25088], m2: [4096 x 20] at /pytorch/aten/src/THC/generic/THCTensorMathBlas.cu:283

Kindly help me out. Thank You
Here is my code:

# Replicating Architecture of VGG19_bn 
class Unit(nn.Module):
    def __init__(self,in_channels,out_channels):
        super(Unit,self).__init__()
        

        self.conv = nn.Conv2d(in_channels=in_channels,kernel_size=3,out_channels=out_channels,stride=1,padding=1)
        self.bn = nn.BatchNorm2d(num_features=out_channels)
        self.relu = nn.ReLU(inplace=True)

    def forward(self,input):
        output = self.conv(input)
        output = self.bn(output)
        output = self.relu(output)

        return output

class CNN(nn.Module):
    def __init__(self,num_classes=20):
        super(CNN,self).__init__()

        #Create 16 layers of the unit with max pooling in between
        self.unit1 = Unit(in_channels=3,out_channels=64)
        self.unit2 = Unit(in_channels=64, out_channels=64)

        self.pool1 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)

        self.unit3 = Unit(in_channels=64, out_channels=128)
        self.unit4 = Unit(in_channels=128, out_channels=128)

        self.pool2 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)

        self.unit5 = Unit(in_channels=128, out_channels=256)
        self.unit6 = Unit(in_channels=256, out_channels=256)
        self.unit7 = Unit(in_channels=256, out_channels=256)
        self.unit8 = Unit(in_channels=256, out_channels=256)

        self.pool3 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)

        self.unit9 = Unit(in_channels=256, out_channels=512)
        self.unit10 = Unit(in_channels=512, out_channels=512)
        self.unit11 = Unit(in_channels=512, out_channels=512)
        self.unit12 = Unit(in_channels=512, out_channels=512)

        self.pool4 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)

        self.unit13 = Unit(in_channels=512, out_channels=512)
        self.unit14 = Unit(in_channels=512, out_channels=512)
        self.unit15 = Unit(in_channels=512, out_channels=512)
        self.unit16 = Unit(in_channels=512, out_channels=512)

        self.pool5 = nn.MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
        
        self.avgpool = nn.AdaptiveAvgPool2d(output_size=(7,7)) #output_size=7, 7

        #Add all the units into the Sequential layer in exact order
        self.net = nn.Sequential(self.unit1, self.unit2, self.pool1, self.unit3, self.unit4, self.pool2, self.unit5, self.unit6
                                 ,self.unit7, self.unit8, self.pool3, self.unit9, self.unit10, self.unit11, self.unit12, self.pool4
                                 ,self.unit13, self.unit14, self.unit15, self.unit16, self.pool5, self.avgpool)

        self.fc = nn.Linear(in_features=512*7*7, out_features=4096) #25088
        self.fc = nn.Dropout(p=0.5, inplace=False)
        self.fc = nn.Linear(in_features=4096, out_features=4096)
        self.fc = nn.Dropout(p=0.5, inplace=False)
        self.fc = nn.Linear(in_features=4096, out_features=num_classes) #20
        
    def forward(self, input):
        output = self.net(input)
        output = output.view(-1,512*7*7)
        output = self.fc(output)
        return output