tf.train.LoggingTensorHook

Class LoggingTensorHook

Inherits From: SessionRunHook

Defined in tensorflow/python/training/basic_session_run_hooks.py.

See the guide: Training > Training Hooks

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

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.logging.set_verbosity(tf.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.

Methods

__init__

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

after_create_session

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

after_run(
    run_context,
    run_values
)

before_run

before_run(run_context)

begin

begin()

end

end(session)