Fine Tune MobileNet_V2

Hi Team,
I am new to pytorch and I am trying to Create a Classifier where I have around 10 kinds of Images Folder Dataset, for this task I am using Pretrained model( MobileNet_v2 ) but the problem is I am not able to chnage the fc layer of it. There is not model.fc attribute.
Can anyone help me to do this.

MobileNetV2 uses a classifier head with an nn.Dropout layer and the final nn.Linear layer:

model = models.mobilenet_v2()
> Sequential(
  (0): Dropout(p=0.2)
  (1): Linear(in_features=1280, out_features=1000, bias=True)

If you want to change the last linear layer, try this code:

model.classifier[1] = nn.Linear(1280, 10)

e.g. to change the number of classes to 10.
model.classifier[1] = nn.Linear(1280, 10)

1 Like