ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

tf.estimator.LoggingTensorHook

Prints the given tensors every N local steps, every N seconds, or at end.

Inherits From: SessionRunHook

Used in the notebooks

Used in the guide

The tensors will be printed to the log, with INFO severity. If you are not seeing the logs, you might want to add the following line after your imports:

  tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.INFO)

Note that if at_end is True, tensors should not include any tensor whose evaluation produces a side effect such as consuming additional inputs.

tensors dict that maps string-valued tags to tensors/tensor names, or iterable of tensors/tensor names.
every_n_iter int, print the values of tensors once every N local steps taken on the current worker.
every_n_secs int or float, print the values of tensors once every N seconds. Exactly one of every_n_iter and every_n_secs should be provided.
at_end bool specifying whether to print the values of tensors at the end of the run.
formatter function, takes dict of tag->Tensor and returns a string. If None uses default printing all tensors.

ValueError if every_n_iter is non-positive.

Methods

after_create_session

View source

Called when new TensorFlow session is created.

This is called to signal the hooks that a new session has been created. This has two essential differences with the situation in which begin is called:

  • When this is called, the graph is finalized and ops can no longer be added to the graph.
  • This method will also be called as a result of recovering a wrapped session, not only at the beginning of the overall session.

Args
session A TensorFlow Session that has been created.
coord A Coordinator object which keeps track of all threads.

after_run

View source

Called after each call to run().

The run_values argument contains results of requested ops/tensors by before_run().

The run_context argument is the same one send to before_run call. run_context.request_stop() can be called to stop the iteration.

If session.run() raises any exceptions then after_run() is not called.

Args
run_context A SessionRunContext object.
run_