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
| 73 | |
| 74 | |
| 75 | class 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 | |
| 108 | class ProcessTensors(Callback): |
no outgoing calls
no test coverage detected