|View source on GitHub|
Add an execution callback to the default eager context.
An execution callback is invoked immediately after an eager operation or
function has finished execution, providing access to the op's type, name
input and output tensors. Multiple execution callbacks can be added, in
which case the callbacks will be invoked in the order in which they are
added. To clear all execution callbacks that have been added, use
def print_even_callback(op_type, inputs, attrs, outputs, op_name): # A callback that prints only the even output values. if outputs.numpy() % 2 == 0: print("Even output from %s: %s" % (op_name or op_type, outputs)) tfe.add_execution_callback(print_even_callback) x = tf.pow(2.0, 3.0) - 3.0 y = tf.multiply(x, tf.add(1.0, 5.0)) # When the line above is run, you will see all intermediate outputs that are # even numbers printed to the console. tfe.clear_execution_callbacks()
callback: a callable of the signature
f(op_type, inputs, attrs, outputs, op_name).
op_typeis the type of the operation that was just executed (e.g.,
Tensor(s) to the op.
attrscontains the attributes of the operation as a
tupleof alternating attribute name and attribute value.
Tensor(s) from the op.
op_nameis the name of the operation that was just executed. This name is set by the client who created the operation and can be
Noneif it is unset. Return value(s) from the callback are ignored.