MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / RunUpdateOps

Class RunUpdateOps

tensorpack/callbacks/graph.py:75–105  ·  view source on GitHub ↗

Run ops from the collection UPDATE_OPS every step. The ops will be hooked to ``trainer.hooked_sess`` and run along with each ``hooked_sess.run`` call. Be careful when using ``UPDATE_OPS`` if your model contains more than one sub-networks. Perhaps not all updates are supposed to

Source from the content-addressed store, hash-verified

73
74
75class RunUpdateOps(RunOp):
76 """
77 Run ops from the collection UPDATE_OPS every step.
78 The ops will be hooked to ``trainer.hooked_sess`` and run along with
79 each ``hooked_sess.run`` call.
80
81 Be careful when using ``UPDATE_OPS`` if your model contains more than one sub-networks.
82 Perhaps not all updates are supposed to be executed in every iteration.
83
84 This callback is one of the :func:`DEFAULT_CALLBACKS()`.
85 """
86
87 def __init__(self, collection=None):
88 """
89 Args:
90 collection (str): collection of ops to run. Defaults to ``tf.GraphKeys.UPDATE_OPS``
91 """
92 if collection is None:
93 collection = tf.GraphKeys.UPDATE_OPS
94 name = 'UPDATE_OPS' if collection == tf.GraphKeys.UPDATE_OPS else collection
95
96 def f():
97 ops = tf.get_collection(collection)
98 if ops:
99 logger.info("Applying collection {} of {} ops.".format(name, len(ops)))
100 return tf.group(*ops, name='update_ops')
101 else:
102 return tf.no_op(name='empty_update_ops')
103
104 super(RunUpdateOps, self).__init__(
105 f, run_before=False, run_as_trigger=False, run_step=True)
106
107
108class ProcessTensors(Callback):

Callers 2

DEFAULT_CALLBACKSFunction · 0.85
get_configFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected