张量流常数为何为可馈tru

2024-09-30 14:39:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我在学张量流

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]}))

结果如下

^{pr2}$

我不明白为什么张量流说常数是可馈的。占位符是feedable true,但为什么是常量?在


Tags: importgetversionsessiontftensorflowaswith
1条回答
网友
1楼 · 发布于 2024-09-30 14:39:06

因为在TF中,您还可以feed values in constants and variables

While you can replace any Tensor with feed data, including variables and constants, the best practice is to use a tf.placeholder node

你自己检查一下:

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更改了其值。在

相关问题 更多 >