tf.contrib.eager.add_execution_callback
Stay organized with collections
Save and categorize content based on your preferences.
Add an execution callback to the default eager context.
tf.contrib.eager.add_execution_callback(
callback
)
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
clear_execution_callbacks()
.
Example:
def print_even_callback(op_type, inputs, attrs, outputs, op_name):
# A callback that prints only the even output values.
if outputs[0].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()
Args |
callback
|
a callable of the signature
f(op_type, inputs, attrs, outputs, op_name) .
op_type is the type of the operation that was just executed (e.g.,
MatMul ).
inputs is the list of input Tensor (s) to the op.
attrs contains the attributes of the operation as a tuple of
alternating attribute name and attribute value.
outputs is the list of output Tensor (s) from the op.
op_name is the name of the operation that was just executed. This
name is set by the client who created the operation and can be None
if it is unset.
Return value(s) from the callback are ignored.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.contrib.eager.add_execution_callback\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/eager/execution_callbacks.py#L243-L284) |\n\nAdd an execution callback to the default eager context. \n\n tf.contrib.eager.add_execution_callback(\n callback\n )\n\nAn execution callback is invoked immediately after an eager operation or\nfunction has finished execution, providing access to the op's type, name\ninput and output tensors. Multiple execution callbacks can be added, in\nwhich case the callbacks will be invoked in the order in which they are\nadded. To clear all execution callbacks that have been added, use\n`clear_execution_callbacks()`.\n\n#### Example:\n\n def print_even_callback(op_type, inputs, attrs, outputs, op_name):\n # A callback that prints only the even output values.\n if outputs[0].numpy() % 2 == 0:\n print(\"Even output from %s: %s\" % (op_name or op_type, outputs))\n tfe.add_execution_callback(print_even_callback)\n\n x = tf.pow(2.0, 3.0) - 3.0\n y = tf.multiply(x, tf.add(1.0, 5.0))\n # When the line above is run, you will see all intermediate outputs that are\n # even numbers printed to the console.\n\n tfe.clear_execution_callbacks()\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `callback` | a callable of the signature `f(op_type, inputs, attrs, outputs, op_name)`. `op_type` is the type of the operation that was just executed (e.g., `MatMul`). `inputs` is the `list` of input `Tensor`(s) to the op. `attrs` contains the attributes of the operation as a `tuple` of alternating attribute name and attribute value. `outputs` is the `list` of output `Tensor`(s) from the op. `op_name` is the name of the operation that was just executed. This name is set by the client who created the operation and can be `None` if it is unset. Return value(s) from the callback are ignored. |\n\n\u003cbr /\u003e"]]