feed_dict无法在张量流中将int转换为张量

jay*_*jay 2 python tensorflow

似乎tensorflow中最棘手的部分是将张量匹配到目的地.

我得到运行时错误:TypeError:"无法将feed_dict键解释为Tensor:无法将int转换为Tensor."

我正在尝试解决XOR问题,这是我的主要设置.

i = tf.placeholder(tf.float32, shape=[None,2])
y_ = tf.placeholder(tf.float32, shape=[None,1])

inp_vec = [[1.,0.],[0.,1.],[1.,1.],[0.,0.]]
solutions = [[1.],[1.],[0.],[0.]]

with tf.Session() as sess:
    sess.run( tf.initialize_all_variables() )

    for i in range(1000):
       sess.run(optim, feed_dict={i:inp_vec, y_:solutions})
Run Code Online (Sandbox Code Playgroud)

如果您需要查看更多或想要告诉我我能做得更好的话,这是整个代码http://pastebin.com/GqrX21vf

inp_vec是[4x2],解是[4x1].两者都应匹配占位符.自从我开始张量流以来,我一直遇到匹配问题所以我开始认为我从根本上不理解设置.对此的澄清将非常感激.

fab*_*ioM 8

您正在i使用ifor循环覆盖对变量的引用.更改名称以x_解决问题.

x_ = tf.placeholder(tf.float32, shape=[None,2])
y_ = tf.placeholder(tf.float32, shape=[None,1])

inp_vec = [[1.,0.],[0.,1.],[1.,1.],[0.,0.]]
solutions = [[1.],[1.],[0.],[0.]]

with tf.Session() as sess:
    sess.run( tf.initialize_all_variables() )

    for i in range(1000):
       sess.run(optim, feed_dict={x_:inp_vec, y_:solutions})
Run Code Online (Sandbox Code Playgroud)