Join us at TensorFlow World, Oct 28-31. Use code TF20 for 20% off select passes. Register now

tf.train.LoggingTensorHook

View source on GitHub

Class LoggingTensorHook

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

Inherits From: SessionRunHook

Aliases:

  • Class tf.compat.v1.estimator.LoggingTensorHook
  • Class tf.compat.v1.train.LoggingTensorHook
  • Class tf.compat.v2.estimator.LoggingTensorHook
  • Class tf.estimator.LoggingTensorHook

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.

__init__

View source

__init__(
    tensors,
    every_n_iter=None,
    every_n_secs=None,
    at_end=False,
    formatter=None
)

Initializes a LoggingTensorHook.

Args:

  • 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.

Raises:

  • ValueError: if every_n_iter is non-positive.

Methods

after_create_session

View source

after_create_session(
    session,
    coord
)

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

after_run(
    run_context,
    run_values
)

before_run

View source

before_run(run_context)

begin

View source

begin()

end

View source

end(session)