class tf.train.MonitoredSession
See the guide: Training > Distributed execution
Session-like object that handles initialization, recovery and hooks.
Example usage:
saver_hook = CheckpointSaverHook(...) summary_hook = SummaryHook(...) 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:
hook.begin()
for each given hookscaffold.finalize()
Scaffold
Run: When run()
is called, the monitored session does following things:
hook.before_run()
session.run()
with merged fetches and feed_dicthook.after_run()
session.run()
asked by userAbortedError
occurs, it recovers or reinitializes the session before executing the run() call againExit: At the close()
, the monitored session does following things in order:
hook.end()
OutOfRange
error which indicates that all inputs have been processed if the monitored_session is used as a contextHow to set tf.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.
session_creator
: A factory object to create session. Typically a ChiefSessionCreator
which is the default one.hooks
: An iterable of `SessionRunHook' objects.A MonitoredSession object.
graph
The graph that was launched in this session.
__init__(session_creator=None, hooks=None)
close()
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.
fetches
: Same as tf.Session.run()
.feed_dict
: Same as tf.Session.run()
.options
: Same as tf.Session.run()
.run_metadata
: Same as tf.Session.run()
.Same as tf.Session.run()
.
should_stop()
Defined in tensorflow/python/training/monitored_session.py
.
© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/train/MonitoredSession