tensorflow - tf.Session() 和 tf.InteractiveSession() 有什么区别?

标签 tensorflow

在哪些情况下应出于什么目的考虑 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/

相关文章:

python - 带有 MNIST 的 LSTM 示例

python - TensorFlow 不更新权重

tensorflow - 为什么验证准确度在每个时期都会波动?

python - Huggingface TFBertForSequenceClassification 总是预测相同的标签

docker - Tensorflow/nvidia/cuda docker 版本不匹配

python - 变量和损失评估的奇怪顺序

tensorflow - TensorFlow 中的设备到底是什么?

python - Keras:如何在自定义损失中获取张量尺寸?

image - TensorFlow:在不打乱的情况下读取队列中的图像

python - Tensorflow 模型在训练期间充满 NaN