TensorFlow Cannot feed value of shape (100, 784) for Tensor 'Placeholder:0'

后端 未结 3 718
-上瘾入骨i
-上瘾入骨i 2021-01-13 14:41

I am learning TensorFLow. So to understand how to make something, I tried to copy some code from a source and execute it. But I\'m hitting an error message. So I tried some

3条回答
  •  甜味超标
    2021-01-13 15:00

    When you define a placeholder in TensorFlow, the shape of the input during the session should be the same as the shape of the placeholder.

    In batch_X, batch_Y = mnist.train.next_batch(100), the batch_x is a 2D array of pixel values, which will have a shape of [batch_size, 28*28].

    In X = tf.placeholder(tf.float32,[None, 28, 28, 1]), the input placeholder is defined to have a 4D shape of [batch_size, 28, 28, 1]

    You can either 1) reshape batch_x before the feeding to TensorFlow. e.g.batch_x = np.reshape(batch_x, [-1, 28, 28, 1]) or 2) Change the shape of the placeholder. e.g. X = tf.placeholder(tf.float32,[None, 784])

    I would recommend 2), since this saves you from doing any reshaping operations both in and outside of the TensorFlow graph.

提交回复
热议问题