我是靠谱客的博主 单薄老鼠,这篇文章主要介绍[tensorflow] eval和run的区别,现在分享给大家,希望可以做个参考。

在tensorflow中,eval和run都是获取当前结点的值的一种方式。

在使用eval时,若有一个 tTensor对象,调用t.eval()相当于调用sess.run(t) 一下两段代码等效:

float_tensor = tf.cast(tf.constant([1, 2, 3]),dtype=tf.float32)
t = float_tensor * float_tensor
sess = tf.Session()
with sess.as_default():
print(t.eval())
print(sess.run(t))

result:

[1. 4. 9.]
[1. 4. 9.]

区别
两者的区别主要在于,eval一次只能得到一个结点的值,而run可以得到多个。

float_tensor = tf.cast(tf.constant([1, 2, 3]),dtype=tf.float32)
t = float_tensor * float_tensor
sess = tf.Session()
with sess.as_default():
print(t.eval(), float_tensor.eval())
print(sess.run((t, float_tensor)))

result:

[1. 4. 9.] [1. 2. 3.]
(array([1., 4., 9.], dtype=float32), array([1., 2., 3.], dtype=float32))

参考资料

  1. https://github.com/jikexueyuanwiki/tensorflow-zh/blob/master/SOURCE/resources/faq.md
  2. https://blog.csdn.net/zcf1784266476/article/details/70259676

最后

以上就是单薄老鼠最近收集整理的关于[tensorflow] eval和run的区别的全部内容,更多相关[tensorflow]内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(43)

评论列表共有 0 条评论

立即
投稿
返回
顶部