class tf.train.SingularMonitoredSessionSee the guide: Training > Distributed execution
Session-like object that handles initialization, restoring, and hooks.
Please note that this utility is not recommended for distributed settings. For distributed settings, please use tf.train.MonitoredSession. The differences between MonitoredSession and SingularMonitoredSession are: MonitoredSession handles AbortedError for distributed settings, but SingularMonitoredSession does not. MonitoredSession can be created in chief or worker modes. SingularMonitoredSession is always created as chief. You can access the raw tf.Session object used by
SingularMonitoredSession, whereas in MonitoredSession the raw session is private. This can be used: - To run without hooks. - To save and restore. All other functionality is identical.
Example usage:
saver_hook = CheckpointSaverHook(...)
summary_hook = SummaryHook(...)
with SingularMonitoredSession(hooks=[saver_hook, summary_hook]) as sess:
while not sess.should_stop():
sess.run(train_op)
Initialization: At creation time the hooked session does following things in given order:
hook.begin() for each given hookscaffold.finalize()
Scaffold
Run: When run() is called, the hooked session does following things:
hook.before_run()
session.run() with merged fetches and feed_dicthook.after_run()
session.run() asked by userExit: At the close(), the hooked session does following things in order:
hook.end()
OutOfRange error which indicates that all inputs have been processed if the SingularMonitoredSession is used as a context.graphThe graph that was launched in this session.
__init__(hooks=None, scaffold=None, master='', config=None, checkpoint_dir=None)Creates a SingularMonitoredSession.
hooks: An iterable of `SessionRunHook' objects.scaffold: A Scaffold used for gathering or building supportive ops. If not specified a default one is created. It's used to finalize the graph.master: String representation of the TensorFlow master to use.config: ConfigProto proto used to configure the session.checkpoint_dir: A string. Optional path to a directory where to restore variables.close()raw_session()Returns underlying TensorFlow.Session object.
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/SingularMonitoredSession