【问题标题】:Tensorflow: Is it always more convenient to use InteractiveSession() compared to Session()?Tensorflow:与 Session() 相比,使用 InteractiveSession() 总是更方便吗?
【发布时间】:2017-03-31 11:12:43
【问题描述】:

简单地使用sub.eval()而不是sess.run(eval)似乎更方便,那么总是使用InteractiveSession()会更方便吗?如果我们一直使用InteractiveSession(),有什么权衡吗?

到目前为止,我看到的唯一“缺点”是我不能使用类似的东西:

with tf.InteractiveSession() as sess:
   result = product.eval() #Where product is a simple matmul
   print result
   sess.close()

相反,我必须立即定义 sess = tf.InteractiveSession

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    从他们的实现中,InteractiveSession 将自己设置为默认会话,您随后的eval() 调用可以使用此会话。在使用Session 的几乎所有情况下,您都应该能够使用InteractiveSession

    一个小的区别是您不需要在 with 块中使用 InteractiveSession

    sess = tf.InteractiveSession()
    # do your work
    sess.close()
    

    所以不要忘记在完成工作后关闭会话。

    这是session.run()eval()之间的比较:In TensorFlow, what is the difference between Session.run() and Tensor.eval()?

    【讨论】:

      猜你喜欢
      • 2015-07-25
      • 1970-01-01
      • 2018-10-18
      • 2011-04-08
      • 2017-05-11
      • 2022-01-05
      • 2017-09-11
      • 2013-09-02
      • 1970-01-01
      相关资源
      最近更新 更多