Is it possible to freeze some filters/channels of a CNN and unfreeze other filters/channels?

I am training a CNN model using Pytorch.
I have identified filters with low variance/magnitude for my input dataset and want to train only these filters for new auxiliary data.
I want to freeze the rest of the filters/channels in the give layer.

How could I go about achieving this ? I did not find any latest PyTorch implementation for the same

Set requires_grad for the parameters of your layer as false before you backprop your gradients:

for param in ~your layer~.parameters():
            param.requires_grad = False
1 Like