使用之间有什么区别:
sess = tf.Session()
VS。
with tf.Session() as sess:
我问,因为我有一个更具体的例子,使用监督会话,其中:
sv = tf.train.Supervisor(logdir=logdir, save_summaries_secs=0, saver=None)
with sv.managed_session() as sess:
checkpoint = tf.train.latest_checkpoint(a.checkpoint)
restore_saver.restore(sess, checkpoint)
正确加载检查点,但以下内容:
sv = tf.train.Supervisor(logdir=logdir, save_summaries_secs=0, saver=None)
sess = sv.managed_session()
checkpoint = tf.train.latest_checkpoint(a.checkpoint)
restore_saver.restore(sess, checkpoint)
导致以下错误:
Traceback (most recent call last):
File "<ipython-input-1-24404191b942>", line 59, in <module>
restore_saver.restore(sess, checkpoint)
File "C:\Users\____\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\saver.py", line 1685, in restore
sess.run(self.saver_def.restore_op_name,
AttributeError: '_GeneratorContextManager' object has no attribute 'run'
会话对象'sess'显示为:
<contextlib._GeneratorContextManager at 0x1b06ee57550>
如果有人能解释发生了什么事,我真的很感激。谢谢!