在哪些情况下应出于什么目的考虑 tf.Session()
和 tf.InteractiveSession()
?
当我尝试使用前一个函数时,某些函数(例如.eval()
)不起作用,而当我更改为后一个函数时,它起作用了。
最佳答案
主要摘自official文档:
The only difference with a regular Session is that an InteractiveSession installs itself as the default session on construction. The methods Tensor.eval() and Operation.run() will use that session to run ops.
这允许使用交互式上下文,例如 shell,因为它避免了必须传递显式 Session 对象来运行操作:
sess = tf.InteractiveSession()
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
# We can just use 'c.eval()' without passing 'sess'
print(c.eval())
sess.close()
也可以说,InteractiveSession
支持更少的输入,因为允许运行变量而无需不断引用 session 对象。
关于tensorflow - tf.Session() 和 tf.InteractiveSession() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41791469/