I would recommend to stick to the named_parameters approach, as in your approach resnet18.modules() will also return fc.weight and fc.bias, which do not contain the 'Linear' name in it.



 Shisho_Sama:

but the code I gave produces an error. it says:
fc doesnt have any attribute named parameters()


Does this code raise this error:
for name, param in resnet18.fc.named_parameters():
    print(name, param.requires_grad)

If so, could you post your pytorch and torchvision versions, as I would like to have a look at it?