title: How to use Tensorflow Dataset for CNN Model Training
body: <p>I wanted to feed my data using <code>tf.data.Dataset</code> class</p>
  
  <pre><code>
  from tensorflow_core.python.keras.datasets import cifar10
  (train_images, train_labels), (test_images, test_labels) = cifar10.load_data()
  
  train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels))
  test_dataset = tf.data.Dataset.from_tensor_slices((test_images, test_labels))
  
  </code></pre>
  
  <ul>
  <li><p>I am doing this to use <code>Dataset</code> in my pipeline.</p></li>
  <li><p>Utilize other features of <code>Dataset</code> further down.</p></li>
  </ul>
  
  <p>I am defining my model like this</p>
  
  <pre><code>    model = models.Sequential()
      model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
      model.add(layers.MaxPool2D((2, 2)))
      # more layers
  </code></pre>
  
  <p>But when I call to train the model</p>
  
  <pre><code>model.fit(train_dataset, epochs=10, validation_data=test_dataset, callbacks=[ cp_callback])
  
  </code></pre>
  
  <p>I get an error</p>
  
  <blockquote>
    <p>ValueError: Error when checking input: expected conv2d_input to have 4 dimensions, but got array with shape (32, 32, 3)</p>
  </blockquote>
  
  <ul>
  <li>What is really happening? How do I use <code>DataSet</code> in my Conv2D layer with input_shape=(32, 32, 3) ?</li>
  </ul>
  
  <p>The Tensorflow tutorial (<a href="https://www.tensorflow.org/tutorials/load_data/numpy" rel="nofollow noreferrer">https://www.tensorflow.org/tutorials/load_data/numpy</a>) did not cover this scenario and I cannot find an explanation that will help me solve my problem.</p>