How to freeze a specific layer in pytorch?

(Peter Ham) #1

I found one post here: How the pytorch freeze network in some layers, only the rest of the training? but it does not answer my question. If I create a layer called conv1 = nn.Conv2d(3,3,2), then how do I freeze this specific layer?

(Daniel Bartolomé) #2

This should do the trick:

for param in conv1.parameters():
    param.requires_grad = False