title: Tensorflow - Value Error in model.fit - How to fix
body: <p>I am trying to train a Deep Neural Network using MNIST data set.</p>
  
  <pre><code>BATCH_SIZE = 100
  train_data = train_data.batch(BATCH_SIZE)
  validation_data = validation_data.batch(num_validation_samples)
  test_data = scaled_test_data.batch(num_test_samples)
  
  validation_inputs, validation_targets = next(iter(validation_data))
  
  input_size = 784
  output_size = 10
  hidden_layer_size = 50
  
  model = tf.keras.Sequential([
                      tf.keras.layers.Flatten(input_shape=(28,28,1)),
                      tf.keras.layers.Dense(hidden_layer_size, activation='relu'),
                      tf.keras.layers.Dense(hidden_layer_size, activation='relu'),
                      tf.keras.layers.Dense(output_size, activation='softmax')                        
                  ])
  
  model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
  
  NUM_EPOCHS = 5
  model.fit(train_data, epochs=NUM_EPOCHS, validation_data=(validation_inputs,validation_targets))
  </code></pre>
  
  <p>The model.fit is throwing the following error</p>
  
  <pre><code>-------------------------------------------------------------------------
  
  --
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-58-c083185dafc6&gt; in &lt;module&gt;
        1 NUM_EPOCHS = 5
  ----&gt; 2 model.fit(train_data, epochs=NUM_EPOCHS, validation_data=(validation_inputs,validation_targets))
  
  ~/anaconda3/envs/py3-TF2/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
      726         max_queue_size=max_queue_size,
      727         workers=workers,
  --&gt; 728         use_multiprocessing=use_multiprocessing)
      729 
      730   def evaluate(self,
  
  ~/anaconda3/envs/py3-TF2/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs)
      222           validation_data=validation_data,
      223           validation_steps=validation_steps,
  --&gt; 224           distribution_strategy=strategy)
      225 
      226       total_samples = _get_total_number_of_samples(training_data_adapter)
  
  ~/anaconda3/envs/py3-TF2/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py in _process_training_inputs(model, x, y, batch_size, epochs, sample_weights, class_weights, steps_per_epoch, validation_split, validation_data, validation_steps, shuffle, distribution_strategy, max_queue_size, workers, use_multiprocessing)
      562                                     class_weights=class_weights,
      563                                     steps=validation_steps,
  --&gt; 564                                     distribution_strategy=distribution_strategy)
      565     elif validation_steps:
      566       raise ValueError('`validation_steps` should not be specified if '
  
  ~/anaconda3/envs/py3-TF2/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_v2.py in _process_inputs(model, x, y, batch_size, epochs, sample_weights, class_weights, shuffle, steps, distribution_strategy, max_queue_size, workers, use_multiprocessing)
      604       max_queue_size=max_queue_size,
      605       workers=workers,
  --&gt; 606       use_multiprocessing=use_multiprocessing)
      607   # As a fallback for the data type that does not work with
      608   # _standardize_user_data, use the _prepare_model_with_inputs.
  
  ~/anaconda3/envs/py3-TF2/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/data_adapter.py in __init__(self, x, y, sample_weights, batch_size, epochs, steps, shuffle, **kwargs)
      252     if not batch_size:
      253       raise ValueError(
  --&gt; 254           "`batch_size` or `steps` is required for `Tensor` or `NumPy`"
      255           " input data.")
      256 
  
  ValueError: `batch_size` or `steps` is required for `Tensor` or `NumPy` input data.
  </code></pre>
  
  <p>The training and validation data are obtained from MNIST dataset. Some part of the data are taken as training data and some as testing data.</p>
  
  <p>What am I doing wrong here?</p>
  
  <p><strong>Update</strong>
  As per Dominques suggestion, I have changed model.fit to</p>
  
  <pre><code>model.fit(train_data, batch_size=128, epochs=NUM_EPOCHS, validation_data=(validation_inputs,validation_targets))
  </code></pre>
  
  <p>But now, I get the following error</p>
  
  <pre><code>ValueError: The `batch_size` argument must not be specified for the given input type. Received input: &lt;BatchDataset shapes: ((None, 28, 28, 1), (None,)), types: (tf.float32, tf.int64)&gt;, batch_size: 128
  </code></pre>