tensorflow之eval

有了sess.run之后,为什么还需要eval呢,感觉两个效果是一样的。

参考下面博主:

https://blog.csdn.net/chengshuhao1991/article/details/78554743

简单点说就是:你可以使用sess.run()在同一步获取多个tensor中的值,使用Tensor.eval()时只能在同一步当中获取一个tensor值,并且每次使用 eval 和 run时,都会执行整个计算图。

上一个示例:

t = tf.constant(42.0)
u = tf.constant(37.0)
tu = tf.multiply(t, u)
ut = tf.multiply(u, t)
with tf.Session() as sess:
    print(tu.eval())  # runs one step
    print(ut.eval())  # runs one step
    print(sess.run([tu, ut]))  # evaluates both tensors in a single step

输出:

猜你喜欢

转载自blog.csdn.net/g0415shenw/article/details/86535033
今日推荐