class Network(nn.Module): def __init__(self): super(Network, self).__init__() self.network1 = nn.Sequential( nn.Linear(10,100), nn.Dropout(0.2), nn.ReLU(), ) self.network2 = nn.Sequential( nn.Linear(100,100), nn.Dropout(0.2), nn.ReLU(), ) def forward(self, x): x = self.network1(x) x = self.network2(x) return x
I want to freeze network2 in Network(). I don’t know how to freeze.
Let me guess.
First, train the whole model .
Second, freeze the network2 and fine-tuning the network1.
Q1) This flow is right?
Q2) How can I freeze the network 2 ?
(If above flow is right) After train the whole network, just change requires_grad from True to False? Is that all I have to do?
for p in network.parameters(): p.requires_grad = False