1. 程式人生 > >InvalidArgumentError: You must feed a value for placeholder tensor 'xxx' with dtype xxx and shape xx

InvalidArgumentError: You must feed a value for placeholder tensor 'xxx' with dtype xxx and shape xx

InvalidArgumentError: You must feed a value for placeholder tensor 'xxx' with dtype xxx and shape xxx

發生原因

這個錯誤是由於feed_dict裡的引數不足所導致。

解決方法

確保計算圖中的所有placeholder都在feed_dict裡被賦予了值。

x1 = np.arange(24).reshape(3,8)
x2 = np.arange(8).reshape(2,4)
a = tf.placeholder(
shape=(None,8), dtype=tf.int32) b = tf.placeholder(shape=(None,4), dtype=tf.int32) c = tf.concat([tf.reshape(a, (6,4)), b], axis=0) with tf.Session() as sess: # print(sess.run(c, feed_dict={a: x1})) # InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_75' with dtype int32 and shape [?,4]
# print(sess.run(c, feed_dict={a: x1, b:x1})) # ValueError: Cannot feed value of shape (3, 8) for Tensor 'Placeholder_73:0', which has shape '(?, 4)' print(sess.run(c, feed_dict={a: x1, b:x2}))