I wanted to implement transfer learning on a data consisting of images which are divided into 52 classes. I wanted to do that using vgg16 and the concept of transfer learning. I have frozen the weights of feature block and from the ouptut of feature block, I am training my own classifier which takes input of 25088( 512 X 7 X 7 number of neurons ). Now, vgg16’s classifier layer outputs 1000 dimension vector indicating which class the input image belonged to. I want to change this 1000 to 52. For that I have written something like:
for param in model_vgg.parameters():
(Indented by one tab space) param.requires_grad = False   #freeze all the layers
model_vgg.classifier[6].out_features = 52  #set number of output classes to 52
for param in model_vgg.classifier[6].parameters():
(Indented by one tab space)param.requires_grad = True      #unfreeze only the last layer of classifier block
But this still doesn’t work, as the output of my classifier block while training and validating is still a 1000 dimension vector for each input image. I tried print( model_vgg.classifier[6].out_features ) which prints 52, still the problem persists.
What’s the problem with my code? Any suggestions will be helpful.