Expected 3d or 4d in conv2d while removing last layer in InceptionV3

I’m currently trying use inceptionv3 as a feature extractor but while trying to remove the last layer an error showed up which is the expected 3d or 4d in conv2d, here’s my code to remove the last layer

download and initiate the inceptionv3 (this works)

modelTuning = torchvision.models.inception_v3(pretrained=False)
summary.summary(modelTuning, input_size=(3, 299,299))

removing the last linear layer (this doesn’t work)

newClassifier = nn.Sequential(*list(modelTuning.children())[:-2])
modelTuning = newClassifier

any solution or maybe there’s something that i need to know?

Wrapping modules into nn.Sequential containers will drop all functional API calls from the original forward method.
In your case you would need to check if the layers are still called in the same order as seen here (of course the aux path will be missing).

so what i need to do is create the model using the code and then remove the fc manually?

If you only want to remove the self.fc layer you could instead replace it with an nn.Identity without any further modification to the model.
If your use case is more complicated, derive a custom nn.Module from the base model and rewrite the forward as you wish.

okay, thankyou for the answer :slight_smile: