Tensorflow feed_dict无法按预期工作

时间:2019-07-22 21:39:10

标签: python dictionary tensorflow feed

我遇到以下错误:

  

您必须使用dtype float和占位符张量'i'的值   形状[2,1]

运行以下代码时:

import tensorflow as tf 
i = tf.placeholder(dtype=tf.float32, shape=[2, 1], name="i")
t = tf.placeholder(dtype=tf.float32, shape=[2, 1], name="t")
wih = tf.Variable([[0.1, 0.12],[0.2, 0.17]], name="wih")
wbh = tf.Variable([[0.8],[0.25]], name="wbh")
h = tf.nn.sigmoid(tf.matmul(wih, i) + wbh)
who = tf.Variable([[0.05, 0.33],[0.4, 0.07]], name="who")
wbo = tf.Variable([[0.15],[0.7]], name="wbo")
o = tf.nn.sigmoid(tf.matmul(who, h) + wbo) 
e = tf.losses.mean_squared_error(t, o)
ts = tf.train.GradientDescentOptimizer(0.5).minimize(e)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    for iterations in range(10000):
        sess.run(ts, feed_dict={i:[[0.15],[0.35]], t:[[0.0],[1.0]]})

为什么feed_dict不起作用?

0 个答案:

没有答案