Placeholder_2:0既被馈送也被取出

Tae*_*gol 8 machine-learning tensorflow

当我运行此代码时:

x = tf.placeholder(tf.int32, shape=(None, 3))
with tf.Session() as sess: 
    feed_dict = dict()
    feed_dict[x] = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
    input = sess.run([x], feed_dict=feed_dict)
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Placeholder_2:0 is both fed and fetched.

我不确定我在这里做错了什么.为什么这不起作用?

lej*_*lot 10

您确定此代码涵盖了您要实现的目标吗?你要求读出你通过的任何内容.这不是tensorflow中的有效调用.如果你想传递值而不做任何事情(为什么?)你应该有一个身份操作.

x = tf.placeholder(tf.int32, shape=(None, 3))
y = tf.identity(x)

with tf.Session() as sess: 
    feed_dict = dict()
    feed_dict[x] = np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
    input = sess.run([y], feed_dict=feed_dict)
Run Code Online (Sandbox Code Playgroud)

问题是"喂食"实际上会覆盖你的操作产生的任何东西,因此你现在无法获取它(因为这个特定的操作系统不再真正产生任何东西).如果你添加这个标识操作,你正确地提供(覆盖x)对结果(标识)什么都不做并获取它(身份产生什么,这是你作为x的输出所提供的任何东西)