tf.compat.v1.train.MonitoredSession

View source on GitHub

Session-like object that handles initialization, recovery and hooks.

tf.compat.v1.train.MonitoredSession(
    session_creator=None, hooks=None, stop_grace_period_secs=120
)

Example usage:

saver_hook = CheckpointSaverHook(...)
summary_hook = SummarySaverHook(...)
with MonitoredSession(session_creator=ChiefSessionCreator(...),
                      hooks=[saver_hook, summary_hook]) as sess:
  while not sess.should_stop():
    sess.run(train_op)

Initialization: At creation time the monitored session does following things in given order:

Run: When run() is called, the monitored session does following things:

Exit: At the close(), the monitored session does following things in order:

How to set tf.compat.v1.Session arguments:

MonitoredSession(
  session_creator=ChiefSessionCreator(master=..., config=...))
MonitoredSession(
  session_creator=WorkerSessionCreator(master=..., config=...))

See MonitoredTrainingSession for an example usage based on chief or worker.

Note: This is not a tf.compat.v1.Session. For example, it cannot do following:

Args:

Returns:

A MonitoredSession object.

Args:

Attributes:

Child Classes

class StepContext

Methods

__enter__

View source

__enter__()

__exit__

View source

__exit__(
    exception_type, exception_value, traceback
)

close

View source

close()

run

View source

run(
    fetches, feed_dict=None, options=None, run_metadata=None
)

Run ops in the monitored session.

This method is completely compatible with the tf.Session.run() method.

Args:

Returns:

Same as tf.Session.run().

run_step_fn

View source

run_step_fn(
    step_fn
)

Run ops using a step function.

Args:

Returns:

Returns the returned value of step_fn.

Raises:

should_stop

View source

should_stop()