您的问题的快速回答是否。
您只需要Session.run() 或Tensor.eval() 即可评估张量对象的值。人们通常使用Tensor.eval()来试验编程模型,即打印出张量的值来跟踪流程!例如,
import tensorflow as tf
a = tf.constant([1, 2], name='a')
b = tf.constant([3, 4], name='b')
c = tf.constant([1, 3], name='c')
d = tf.add_n([a, b])
e = tf.pow(d, c)
printout_d = tf.Print(d, [a, b, d], 'Input for d and the result: ')
printout_e = tf.Print(e, [d, c, e], 'Input for e and the result: ')
with tf.Session() as sess:
sess.run([d, e])
printout_d.eval()
printout_e.eval()
在上面的代码中,您可以只需要sess.run([d, e]) 来执行图形。但是,在某些情况下,例如调试,您可以从printout_d.eval() 和printout_e.eval() 中受益。