model = torchvision.models.vgg19(pretrained=True)
for param in model.parameters():
param.requires_grad = False
# Replace the last fully-connected layer
# Parameters of newly constructed modules have requires_grad=True by default
model.fc = nn.Linear(512, 8) # assuming that the fc7 layer has 512 neurons, otherwise change it
model.cuda()
In a later part of the code, the model was called as follows when processing the input data
YourModule() refers to any function that returns a nn.Module. So that’s just a placeholder to say that you can insert whatever model you want in there.
Thanks a lot RicCu. I was stuck in trying to modify the original end-classifier outputting 600 features in a hybrid classical-quantum transfer learning model. I needed a binary output. I used : model_hybrid = nn.Sequential(model, DressedQuantumNet()), and it worked!