如果我们在表达式中使用常量,那么它会自动被视为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()
y1
和y2
的结果相同。它们都包含“ 8”。但是,当我在Tensorboard中检查图形时,我可能会注意到一些细微差别:
在图表中,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)完全相同。