title: ValueError: Input 0 of layer "conv2d" is incompatible with the layer: expected min_ndim=4, found ndim=3. Full shape received: (28, 28, 1)
body: <p>I keep on getting this error related to input shape. Any help would be highly appreciated. Thanks!</p>
  <pre><code>import tensorflow as tf
  import numpy as np
  import os
  import time
  
  LABEL_DIMENSION = 10
  (X_train, Y_train), (X_test, Y_test) = tf.keras.datasets.fashion_mnist.load_data()
  Training_size = len(X_train)
  Test_size = len(X_test)
  
  X_train = np.asarray(X_train, dtype=np.float32)/255
  X_train = X_train.reshape((Training_size, 28, 28, 1))
  
  X_test = np.asarray(X_test, dtype=np.float32)/255
  X_test = X_test.reshape((Test_size, 28, 28, 1))
  
  Y_train = tf.keras.utils.to_categorical(Y_train, LABEL_DIMENSION)
  Y_test = tf.keras.utils.to_categorical(Y_test, LABEL_DIMENSION)
  
  Y_train = Y_train.astype(np.float32)
  Y_test = Y_test.astype(np.float32)
  
  inputs= tf.keras.Input(shape=(28, 28, 1))
  x = tf.keras.layers.Conv2D(filters=32, kernel_size=(3, 3), activation=&quot;relu&quot;)(inputs)
  x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
  x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), activation=&quot;relu&quot;)(x)
  x = tf.keras.layers.MaxPooling2D(pool_size=(2, 2), strides=2)(x)
  x = tf.keras.layers.Conv2D(filters=64, kernel_size=(3,3), activation=&quot;relu&quot;)(x)
  x = tf.keras.layers.Flatten()(x)
  x = tf.keras.layers.Dense(64, activation=&quot;relu&quot;)(x)
  predictions = tf.keras.layers.Dense(LABEL_DIMENSION, activation=&quot;softmax&quot;)(x)
  model = tf.keras.Model(inputs=inputs, outputs=predictions)
  model.summary()
  
  optim = tf.keras.optimizers.SGD()
  model.compile(loss=&quot;categorical_crossentropy&quot;, optimizer=optim, metrics=[&quot;accuracy&quot;])
  
  strategy = None
  #strategy = tf.distribute.MirroredStrategy()
  configs = tf.estimator.RunConfig(train_distribute=strategy)
  
  estimator = tf.keras.estimator.model_to_estimator(model, config=configs)
  
  def input_fn(images, labels, epochs, batch_size):
      dataset = tf.data.Dataset.from_tensor_slices((images, labels))
  
      SHUFFLE_SIZE = 5000
      dataset.shuffle(SHUFFLE_SIZE).repeat(epochs).batch(batch_size)
      dataset = dataset.prefetch(None)
  
      return dataset
  
  BATCH_SIZE = 512
  EPOCHS = 50
  estimator_train_result = estimator.train(input_fn=lambda: input_fn(X_train, Y_train, epochs=EPOCHS, batch_size=BATCH_SIZE))
  print(estimator_train_result)
  
  estimator.evaluate(lambda: input_fn(X_test, Y_test, epochs=1, batch_size=BATCH_SIZE))
  </code></pre>
  <blockquote>
  <p>ValueError: Input 0 of layer &quot;conv2d&quot; is incompatible with the layer: expected min_ndim=4, found ndim=3. Full shape received: (28, 28, 1)</p>
  </blockquote>