How to pass certain layers weights in the optimizer

search for named_parameters…

here’s how it’s done,

print('Training these layers')
for name,param in model.named_parameters():
    if param.requires_grad is True:
        print(name, param.requires_grad)

I hope you can flip the requires_grad as per the need…

Secondly don’t pass model.parameters() like that rather filter the ones which have requires_grad as True… (looks cool)

1 Like