这是一个关于学习Tensorflow的初学者问题。我习惯于在交互式shell中使用机器学习模型,比如Jupyter notebook。我知道tensorflow采用了懒惰的执行方式,所以我不能很容易地打印张量进行检查。
经过一些研究,我发现了两种解决方案:tf.InteractiveSession()或tf.enable_eager_execution()。据我所知,这两种方法都允许我在编写变量时打印变量。这是正确的吗?有什么偏好吗?
发布于 2019-05-22 17:01:01
在使用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 valuehttps://stackoverflow.com/questions/54101024
复制相似问题