I know how to remove the last layer of mobinet_v2, but how to remove certain layer of features?
Mobilenet has the following structure,
(features):
layer 1
layer 2
layer 3
…
…
(classifier):
output layer
Are you attempting to do fine-tuning or something else like transfer learning ?
Meanwhile I saw this tutorial but the source code link gives me a 404
https://pytorch.org/tutorials/beginner/finetuning_torchvision_models_tutorial.html
Here is how I freeze a pre-trained model to do what is now called transfer learning… and I erase the last fc layer
if model_conf["hyperParameters"]["freeze_pretrained_gradients"]:
print("Using backbone as fixed feature extractor")
modules = list(backbone_nn.children())[:-1] # delete the last fc layer.
backbone_nn = nn.Sequential(*modules)
# FasterRCNN needs to know the number of
# output channels in a backbone. For resnet101, it's 2048
for param in backbone_nn.parameters():
param.requires_grad = False
backbone_nn.out_channels = 2048
the key is that .children() call