Created mechanism that allows us to train only parts of the graph during the graph adaptation
Hey,
Sometimes when we want to apply some checkpoint in another dataset (or domain), we may want to choose which parts of the graph we want to re-train.
With this MR, our estimators (Logits.., Triplet, Siamese,) were enhanced with this keyword argument
extra_checkpoint = {
"checkpoint_path": <YOUR_CHECKPOINT>,
"scopes": dict({"<SOURCE_SCOPE>/": "<TARGET_SCOPE>/"}),
"trainable_variables": [<LIST OF VARIABLES OR SCOPES THAT YOU WANT TO RETRAIN>]
}
The novelty here is the trainable_variables
, where now we can set the parts of the graph we want to do back-propagation. If you set an empty list ( "trainable_variables": []
) all variables will not be trainable.
If this variable is not set at all, everything is trainable.
This is strongly dependent on how the architecture function is crafted. Look some example on how such functions should be crafted.
- Simple example: https://gitlab.idiap.ch/bob/bob.learn.tensorflow/blob/9a1cd4eda365f1470eab4ce9d8b49bb0278a0ae4/bob/learn/tensorflow/network/Dummy.py
- Complex one: https://gitlab.idiap.ch/bob/bob.learn.tensorflow/blob/9a1cd4eda365f1470eab4ce9d8b49bb0278a0ae4/bob/learn/tensorflow/network/InceptionResnetV2.py
Do you have some time to review this one @amohammadi ? Perhaps this can be useful for you.
Thanks
Merge request reports
Activity
- Resolved by Amir MOHAMMADI
18 20 slim = tf.contrib.slim 19 21 end_points = dict() 20 22 23 # Here is my choice to shutdown the whole scope 24 trainable = is_trainable("Dummy", **kwargs) changed this line in version 2 of the diff
- Resolved by Amir MOHAMMADI
259 303 260 304 end_points['PreLogitsFlatten'] = net 261 262 net = slim.fully_connected(net, bottleneck_layer_size, activation_fn=None, 263 scope='Bottleneck', reuse=reuse, trainable=trainable_variables) 264 end_points['Bottleneck'] = net 265 305 266 return net, end_points 306 name = "Bottleneck" 307 trainable = is_trainable(name, **kwargs) 308 net = slim.fully_connected(net, bottleneck_layer_size, activation_fn=None, 309 scope=name, reuse=reuse, trainable=trainable) 310 end_points[name] = net 267 311 312 return net, end_points @tiago.pereira normally you would use
kwargs
to accept extra arguments that you don't need. This is useful when calling several different functions at the same time.def f1(a=0, **kw): print(a) def f2(b=0, **kw): print(b) # call both using the same syntax f1(a=a, b=b) # ignores b f2(a=a, b=b) # ignores a
Different architectures take different parameters and I imagined the way to use them with logit trainer would be that all architectures accept
kwargs
but do not use what is insidekwargs
.
added 1 commit
- 33d4e3b6 - Created mechanism that allows as to train only parts of the graph
added 25 commits
-
33d4e3b6...18980c2c - 24 commits from branch
master
- 07b17ec9 - Merge branch 'master' into 'shutting-down-parts-of-the-network'
-
33d4e3b6...18980c2c - 24 commits from branch
Hey @amohammadi, I've fixed the issues with kwargs. Now I think is cleaner.
Shall we move on with this?
Thanks
23 Parameters 24 ---------- 25 26 name: str 27 Layer name 28 29 trainable_variables: list 30 List containing the variables or scopes to be trained. 31 If None, the variable/scope is trained 32 """ 33 34 # If None, we train by default 35 if trainable_variables is None: 36 return True 37 38 # Here is my choice to shutdown the whole scope mentioned in commit 69f0e7b0