How to fix the weights and biases except two?

Hmmm
Esentially what you save is a dicitonary.
The simplest way is changing the values in the state_dict before the new network loads them.
Something like

weights = net.state_dict()
weights['layer_name1'] = ... 
weights['layer_nameN'] = ...
new_net.load_state_dict(weights)

To freeze certain layers: How the pytorch freeze network in some layers, only the rest of the training?

1 Like