占位符_2:0既已获取又已获取 [英] Placeholder_2:0 is both fed and fetched

查看:88
本文介绍了占位符_2:0既已获取又已获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行此代码时:

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)

我收到此错误:

Placeholder_2:0 is both fed and fetched.

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

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

推荐答案

您确定此代码涵盖了您要实现的目标吗? 您要求读出您通过的所有内容.这不是张量流中的有效调用.如果您想传递值而不执行任何操作(目的是什么?),则应该执行标识操作.

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.

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)

问题在于,进给"实际上会覆盖您的操作生成的任何内容,因此您目前无法获取它(因为此特定操作实际上不再产生任何内容).如果添加了此身份操作,则可以正确地馈送(覆盖x)对结果(身份)不执行任何操作,并获取它(身份产生的内容,这就是您作为x的输出所馈送的任何内容)

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)

这篇关于占位符_2:0既已获取又已获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆