Adding layers to Inception v3 Transfer Learning

I am training a flower classifier and in order to increase the performance, I want to add 3 layers to the feature extracted by the pre-trained Inception v3 model and calculate the confusion matrix.

The three-layers are -

  1. An average pooling layer followed by
  2. 2 Dense Layers (512)

I would really appreciate if you can help me with it.

model_ft = models.inception_v3(pretrained=True)

# I want to add the layers here

num_ftrs = model_ft.fc.in_features
model_ft.fc = nn.Linear(num_ftrs, 102)

model_ft =

criterion = nn.CrossEntropyLoss()
optimizer_ft = optim.SGD(model_ft.parameters(), lr=0.001, momentum=0.9)
exp_lr_scheduler = lr_scheduler.StepLR(optimizer_ft, step_size=10, gamma=0.1)

Would you like to add these additional layers right before the pooling layer (line of code)?
If so, I think the best way would be to create your own custom model and derive from Inception3 as the base class.
This would make manipulating the forward method quite easy.

Let me know, if you get stuck somewhere.

1 Like

@ptrblck Yes I would like to add these line before that the problem is I have never done these kind of modifications earlier and hence I am completely stuck. Thank you for your help. Could you please help me out on how to do it.