Hello All, I’m trying to fine-tune a resnet18 model.
I want to freeze all layers except the last one. I did
resnet18 = models.resnet18(pretrained=True)
resnet18.fc = nn.Linear(512, 10) 
for param in resnet18.parameters():
    param.requires_grad = False 

However, doing
for param in resnet18.fc.parameters():
    param.requires_grad = True

Fails. How can I set a specific layers parameters to have requires_grad to True?
Thank you all in advance
Note:
I specifically don’t want to swap the order of assigning a new layer with setting all the grads to false
I want to learn how this specific thing can be done.