The pretrained model’s feature map(after a avgpooling layer) is of shape (bs, 512, 1, 1),
so for nn.Conv2d layer, it should be
self.fc = nn.Conv2d(512, num_classes, kernel_size=1,stride=1, padding=0, bias=True)
when forward,
# input x is the feature map
x = self.fc(x)
out = x.view(x.size(0), -1)

for nn.Linear,
self.fc = nn.Linear(512, num_classes, bias=True)
when forward,
x = self.fc(x.view(x.size(0), -1))