Placeholder_2:0是美联储和取的。

时间:2021-07-28 23:44:47

When I run this code:

当我运行这段代码:

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)

I get this error:

我得到这个错误:

Placeholder_2:0 is both fed and fetched.

Placeholder_2:0是美联储和取的。

I'm not sure what I'm doing wrong here. Why does this not work?

我不知道我在这里做错了什么。为什么这样不行?

2 个解决方案

#1


1  

Are you sure this code covers what you are trying to achieve? You ask to read out whatever you pass through. This is not a valid call in tensorflow. If you want to pass through values and do nothing with it (what for?) you should have an identity operation.

你确定这段代码涵盖了你想要达到的目标吗?你要求通读任何你通过的东西。这不是一个有效的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)

The problem is "feeding" actually kind of overwrites whatever your op generates, thus you cannot fetch it at this moment (since there is nothing being really produced by this particular op anymore). If you add this identity op, you correctly feed (override x) do nothing with the result (identity) and fetch it (what identity produces, which is whatever you feeded as an output of x)

问题是“喂养”实际上是覆盖了您的op生成的任何内容,因此您无法在此时获取它(因为没有任何东西是由这个特定的op产生的)。如果您添加了这个标识操作,您就可以正确地输入(override x),而不使用结果(identity)并获取它(身份生成,这是您作为x的输出所忽略的内容)

#2


0  

I found out what I was doing wrong.

我发现我做错了什么。

x is a placeholder -- it holds information and evaluating x does not do anything. I forgot that vital piece of information and proceeded to attempt to run the Tensor x inside sess.run()

x是一个占位符——它保存信息,并且对x进行评估不会做任何事情。我忘记了重要的信息,并开始尝试在sess.run()中运行张量x

Code similar to this would work if, say, there was another Tensor y that depended on x and I ran that like sess.run([y], feed_dict=feed_dict)

类似于这个的代码会起作用,比如说,有一个依赖于x的张量y,我运行它就像sess。run([y], feed_dict=feed_dict)

#1


1  

Are you sure this code covers what you are trying to achieve? You ask to read out whatever you pass through. This is not a valid call in tensorflow. If you want to pass through values and do nothing with it (what for?) you should have an identity operation.

你确定这段代码涵盖了你想要达到的目标吗?你要求通读任何你通过的东西。这不是一个有效的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)

The problem is "feeding" actually kind of overwrites whatever your op generates, thus you cannot fetch it at this moment (since there is nothing being really produced by this particular op anymore). If you add this identity op, you correctly feed (override x) do nothing with the result (identity) and fetch it (what identity produces, which is whatever you feeded as an output of x)

问题是“喂养”实际上是覆盖了您的op生成的任何内容,因此您无法在此时获取它(因为没有任何东西是由这个特定的op产生的)。如果您添加了这个标识操作,您就可以正确地输入(override x),而不使用结果(identity)并获取它(身份生成,这是您作为x的输出所忽略的内容)

#2


0  

I found out what I was doing wrong.

我发现我做错了什么。

x is a placeholder -- it holds information and evaluating x does not do anything. I forgot that vital piece of information and proceeded to attempt to run the Tensor x inside sess.run()

x是一个占位符——它保存信息,并且对x进行评估不会做任何事情。我忘记了重要的信息,并开始尝试在sess.run()中运行张量x

Code similar to this would work if, say, there was another Tensor y that depended on x and I ran that like sess.run([y], feed_dict=feed_dict)

类似于这个的代码会起作用,比如说,有一个依赖于x的张量y,我运行它就像sess。run([y], feed_dict=feed_dict)

相关文章