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

后端 未结 3 685
-上瘾入骨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 14:59

    You need to reshape X.

        X = tf.placeholder(tf.float32 , [None ,28 , 28 , 1])
        X = tf.reshape(X , [-1 , 784])
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-13 15:14

    You are getting that error because there is a mismatch between the shape of what you are feeding in and what the TensorFlow is expecting. To fix the issue, you might want to reshape your data at placeholder:0 which is batch_X to (?, 28, 28, 1). For example, you would do the following:

    batch_X = np.reshape(batch_X, (-1, 28, 28, 1))
    
    0 讨论(0)
提交回复
热议问题