y = 3.0 * x + 2.0和y = tf.constant(3.0)* x + tf.constant(2.0)之间的差异

时间:2018-06-24 01:46:08

标签: tensorflow expression constants

如果我们在表达式中使用常量,那么它会自动被视为tf.constant()吗?

我尝试了以下代码:

#!/usr/bin/python

import tensorflow as tf

x1 = tf.placeholder(tf.float32, (None), name='x1')
y1 = 3.0 * x1 + 2.0

x2 = tf.placeholder(tf.float32, (None), name='x2')
y2 = tf.constant(3.0) * x2 + tf.constant(2.0) 

writer = tf.summary.FileWriter('./graphs', tf.get_default_graph())
with tf.Session() as sess:
    print (sess.run(y1, feed_dict={x1:2.0}))
    print (sess.run(y2, feed_dict={x2:2.0}))
writer.close()

y1y2的结果相同。它们都包含“ 8”。但是,当我在Tensorboard中检查图形时,我可能会注意到一些细微差别:

enter image description here

在图表中,y1 = 3.0 * x1 + 2.0中的3.0和2.0在图中分别显示为“ x”和“ y”,而tf.constant(3.0)tf.constant(2.0)在Tensorboard中显示为“ Const”和“ Const_1”。

我想知道为什么它们在Tensorboard中显得有些不同。我还想问一下上面表达式中的3.0是否与tf.constant(3.0)完全相同。

0 个答案:

没有答案