0

这是一个关于学习 TensorFlow 的初学者问题。我习惯于在 Jupyter notebook 这样的交互式 shell 中玩机器学习模型。我理解tensorflow采用惰性执行风格,所以我不能轻易打印张量来检查。

经过一番研究,我发现了两种解决方法:tf.InteractiveSession()tf.enable_eager_execution(). 据我了解,两者都允许我在编写变量时打印它们。这个对吗?有偏好吗?

4

1 回答 1

1

使用 tf.InteractiveSession() 时,您仍然处于延迟执行状态。所以你不能打印变量值。你只能看到符号。

sess = tf.InteractiveSession()
a = tf.random.uniform(shape=(2,3))
print(a) # <tf.Tensor 'random_uniform:0' shape=(2, 3) dtype=float32>

使用 tf.enable_eager_execution() 时,您可以查看变量值。

tf.enable_eager_execution()
a = tf.random.uniform(shape=(2,3))
print(a) # prints out value
于 2019-05-22T09:01:00.703 回答