title: I am facing an "InvalidArgumentError: Input is empty" error in the custom training loop in tensorflow
body: <p>I am trying to write a custom training loop in Tensorflow
  Tensorflow version is 2.7.0</p>
  <pre><code>batch_size = 32
  img_height = 180
  img_width = 180
  
  data_dir = &quot;archive\\PetImages&quot;
  
  train_ds = tf.keras.utils.image_dataset_from_directory(data_dir, validation_split=0.2, subset=&quot;training&quot;, seed=123, image_size=(img_height, img_width), batch_size=batch_size)
  
  val_ds = tf.keras.utils.image_dataset_from_directory(data_dir, validation_split=0.2, subset=&quot;validation&quot;, seed=123, image_size=(img_height, img_width), batch_size=batch_size)
  
  model = tf.keras.Sequential([
      tf.keras.layers.Rescaling(1./255),
      tf.keras.layers.Conv2D(32, 3, activation='relu'),
      tf.keras.layers.MaxPooling2D(),
      tf.keras.layers.Conv2D(32, 3, activation='relu'),
      tf.keras.layers.MaxPooling2D(),
      tf.keras.layers.Conv2D(32, 3, activation='relu'),
      tf.keras.layers.MaxPooling2D(),
      tf.keras.layers.Flatten(),
      tf.keras.layers.Dense(128, activation='relu'),
      tf.keras.layers.Dense(1)
  ])
  
  optimizer = tf.keras.optimizers.SGD(learning_rate=1e-3)
  loss_fn = tf.keras.losses.BinaryCrossentropy()
  
  epochs = 2
  for epoch in range(epochs):
      print(&quot;\nStart of epoch %d&quot; % (epoch,))
      for step, (x_batch_train, y_batch_train) in enumerate(train_ds):
  
          with tf.GradientTape() as tape:
              logits = model(x_batch_train, training=True)  # Logits for this minibatch
              loss_value = loss_fn(y_batch_train, logits)
          grads = tape.gradient(loss_value, model.trainable_weights)
          optimizer.apply_gradients(zip(grads, model.trainable_weights))
          if step % 200 == 0:
              print(
                  &quot;Training loss (for one batch) at step %d: %.4f&quot;
                  % (step, float(loss_value))
              )
              print(&quot;Seen so far: %s samples&quot; % ((step + 1) * batch_size))
  </code></pre>
  <p>This is the custom training loop. The training goes on for some time and then gives the Input empty error.</p>
  <p>This error pops up after this:</p>
  <pre><code>Start of epoch 0
  Training loss (for one batch) at step 0: 7.7125
  Seen so far: 32 samples
  Training loss (for one batch) at step 200: 0.6864
  Seen so far: 6432 samples
  
  InvalidArgumentError                      Traceback (most recent call last)
  
  ...
  
  InvalidArgumentError: Input is empty.
       [[{{node decode_image/DecodeImage}}]] [Op:IteratorGetNext]
  </code></pre>