There’s two ways you could do that:
- Split the model into groups as @florianl mentioned above. You can then do
learn.freeze_to(...). However, I think this freezes a bunch of layers sequentially, so if you need to only tweak a specific part, the method below is better - Access the specific layer, and turn off logging gradients by changing the
requires_gradattribute. For example:
learn = cnn_learner(dls, model)
for p in learn.model[1][3].parameters():
p.requires_grad = None
# p.requires_grad = False
# I remember reading somewhere `None` is better, but can't remember why
EDIT: I meant for p in model[...].parameters()