MCPcopy Index your code
hub / github.com/lisa-lab/DeepLearningTutorials / freezeParameters

Function freezeParameters

code/fcn_2D_segm/fcn8.py:15–36  ·  view source on GitHub ↗

Freeze parameters of a layer or a network so that they are not trainable anymore Parameters ---------- net: a network layer single: whether to freeze a single layer of all of the layers below as well

(net, single=True)

Source from the content-addressed store, hash-verified

13
14
15def freezeParameters(net, single=True):
16 """
17 Freeze parameters of a layer or a network so that they are not trainable
18 anymore
19
20 Parameters
21 ----------
22 net: a network layer
23 single: whether to freeze a single layer of all of the layers below as well
24 """
25 all_layers = lasagne.layers.get_all_layers(net)
26
27 if single:
28 all_layers = [all_layers[-1]]
29
30 for layer in all_layers:
31 layer_params = layer.get_params()
32 for p in layer_params:
33 try:
34 layer.params[p].remove('trainable')
35 except KeyError:
36 pass
37
38
39# start-snippet-1

Callers 1

buildFCN8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected