为什么张力流量常数是可馈送的

时间:2017-06-11 10:22:34

标签: python tensorflow

我正在学习张量流

import tensorflow as tf
print(tf.VERSION)

a = tf.placeholder(tf.float32, shape=[3])
b = tf.constant([2, 2, 2], tf.float32)
c = a + b
with tf.Session() as sess:
    print(tf.get_default_graph().is_feedable(b))
    print(sess.run(c, feed_dict={a: [3, 2, 3]}))

输出结果如下

1.0.1
True
[ 5.  4.  5.]

我不明白为什么张量流说这个常数是可以喂食的。占位符是可以输入的,但为什么不变?

1 个答案:

答案 0 :(得分:2)

因为在TF中你也可以feed values in constants and variables

  

虽然您可以使用Feed数据(包括变量和常量)替换任何Tensor,但最佳做法是使用tf.placeholder节点

亲自检查:

import tensorflow as tf

a = tf.constant([2, 2, 2], tf.float32)
with tf.Session() as sess:
    print(sess.run(a, feed_dict={a: [3, 2, 3]}))

常量a更改了其值。