PyTorch VGG16 cant learn multiclass-classification

Hi everyone!

I’m pretty new to PyTorch.
I’ve been trying to train a VGG16 to perform multiclass classification of face images.

I’ve used ‘torchvision.models’ to import vgg16 pretrained model as follows:

model = models.vgg16(pretrained=True)

I’ve changed the last linear layer in the classifier to output 27 classes but it seems that it can’t learn good enough; It stops at 0.0333 accuracy and can’t go better than that.

I’ve used Cross Entropy Loss and SGD optimizer of PyTorch.

Must mention that I did try to train other models from ‘torchvision.models’ (VGG11, GoogleNet and others) and they went amazing.

Can someone please help me to understand why is this happening?

Make sure you are really replacing the last linear layer with your custom one, as different models might use different names for this layer (e.g. model.classifier vs. model.fc).

If that’s not the case, try to overfit a small data sample by playing around with some hyperparameters and scale up the problem once this is working.