Skip to content
Snippets Groups Projects

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.

Do you have some time to review this one @amohammadi ? Perhaps this can be useful for you.

Thanks

Merge request reports

Pipeline #14707 failed

Pipeline failed for 07b17ec9 on shutting-down-parts-of-the-network

Approval is optional

Merged by avatar (Aug 24, 2025 6:12am UTC)

Merge details

  • Changes merged into master with 69f0e7b0.
  • Deleted the source branch.

Pipeline #14768 failed

Pipeline failed for 69f0e7b0 on master

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 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)
  • 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
    • this is good but I really don't like that you are using kwargs for something specific.

    • I'm doing like that just to have more flexibility and not to have a rigid API. I don't want to force this specific keyword argument in the estimators.

      input, mode and scope are more orthodox, but everything else is superfluous. That's why I'm shipping this via kwargs

    • @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 inside kwargs.

    • Please register or sign in to reply
  • Do we have anything blocking this to be merged? Thanks

  • added 1 commit

    • 33d4e3b6 - Created mechanism that allows as to train only parts of the graph

    Compare with previous version

  • added 25 commits

    Compare with previous version

  • 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
  • Amir MOHAMMADI mentioned in commit 69f0e7b0

    mentioned in commit 69f0e7b0

  • Please register or sign in to reply
    Loading