Debugging Operations

TensorFlow provides several operations that you can use to validate values and debug your graph.

tf.is_finite(x, name=None)

Returns which elements of x are finite.

Args:
  • x: A Tensor. Must be one of the following types: half, float32, float64.
  • name: A name for the operation (optional).
Returns:

A Tensor of type bool.


tf.is_inf(x, name=None)

Returns which elements of x are Inf.

Args:
  • x: A Tensor. Must be one of the following types: half, float32, float64.
  • name: A name for the operation (optional).
Returns:

A Tensor of type bool.


tf.is_nan(x, name=None)

Returns which elements of x are NaN.

Args:
  • x: A Tensor. Must be one of the following types: half, float32, float64.
  • name: A name for the operation (optional).
Returns:

A Tensor of type bool.


tf.verify_tensor_all_finite(t, msg, name=None)

Assert that the tensor does not contain any NaN's or Inf's.

Args:
  • t: Tensor to check.
  • msg: Message to log on failure.
  • name: A name for this operation (optional).
Returns:

Same tensor as t.


tf.check_numerics(tensor, message, name=None)

Checks a tensor for NaN and Inf values.

When run, reports an InvalidArgument error if tensor has any values that are not a number (NaN) or infinity (Inf). Otherwise, passes tensor as-is.

Args:
  • tensor: A Tensor. Must be one of the following types: half, float32, float64.
  • message: A string. Prefix of the error message.
  • name: A name for the operation (optional).
Returns:

A Tensor. Has the same type as tensor.


tf.add_check_numerics_ops()

Connect a check_numerics to every floating point tensor.

check_numerics operations themselves are added for each half, float, or double tensor in the graph. For all ops in the graph, the check_numerics op for all of its (half, float, or double) inputs is guaranteed to run before the check_numerics op on any of its outputs.

Returns:

A group op depending on all check_numerics ops added.


tf.Assert(condition, data, summarize=None, name=None)

Asserts that the given condition is true.

If condition evaluates to false, print the list of tensors in data. summarize determines how many entries of the tensors to print.

NOTE: To ensure that Assert executes, one usually attaches a dependency:

 # Ensure maximum element of x is smaller or equal to 1
assert_op = tf.Assert(tf.less_equal(tf.reduce_max(x), 1.), [x])
x = tf.with_dependencies([assert_op], x)
Args:
  • condition: The condition to evaluate.
  • data: The tensors to print out when condition is false.
  • summarize: Print this many entries of each tensor.
  • name: A name for this operation (optional).
Returns:
  • assert_op: An Operation that, when executed, raises a tf.errors.InvalidArgumentError if condition is not true.

tf.Print(input_, data, message=None, first_n=None, summarize=None, name=None)

Prints a list of tensors.

This is an identity op with the side effect of printing data when evaluating.

Args:
  • input_: A tensor passed through this op.
  • data: A list of tensors to print out when op is evaluated.
  • message: A string, prefix of the error message.
  • first_n: Only log first_n number of times. Negative numbers log always; this is the default.
  • summarize: Only print this many entries of each tensor. If None, then a maximum of 3 elements are printed per input tensor.
  • name: A name for the operation (optional).
Returns:

Same tensor as input_.