code: def test_early_stopping(self):
      x_train = np.random.random((10, 5))
      y_train = np.random.random((10, 1))
      x_test = np.random.random((10, 5))
      y_test = np.random.random((10, 1))
      model = models.Sequential(
          (
              layers.Dense(1, activation="relu"),
              layers.Dense(1, activation="relu"),
          )
      )
      model.compile(
          loss="mae",
          optimizer="adam",
          metrics=[
              "mse",
              "acc",
              "accuracy",
              "hinge",
              metrics.F1Score(name="f1_score"),
          ],
      )
  
      cases = [
          ("max", "val_mse", "max"),
          ("min", "val_loss", "min"),
          ("auto", "val_mse", "min"),
          ("auto", "loss", "min"),
          ("auto", "acc", "max"),
          ("auto", "val_accuracy", "max"),
          ("auto", "hinge", "min"),
          ("auto", "f1_score", "max"),
      ]
      for mode, monitor, expected_mode in cases:
          patience = 0
          cbks = [
              callbacks.EarlyStopping(
                  patience=patience, monitor=monitor, mode=mode
              )
          ]
          model.fit(
              x_train,
              y_train,
              batch_size=5,
              validation_data=(x_test, y_test),
              callbacks=cbks,
              epochs=2,
              verbose=0,
          )
          if expected_mode == "max":
              monitor_op = ops.greater
          else:
              monitor_op = ops.less
          self.assertEqual(cbks[0].monitor_op, monitor_op)
  
      with self.assertRaises(ValueError):
          cbks = [
              callbacks.EarlyStopping(
                  patience=patience, monitor="unknown"
              )
          ]
          model.fit(
              x_train,
              y_train,
              batch_size=5,
              validation_data=(x_test, y_test),
              callbacks=cbks,
              epochs=2,
              verbose=0,
          )
  
file_path: keras/keras/callbacks/early_stopping_test.py
imports: import numpy
  import pytest
  from keras import callbacks
  from keras import layers
  from keras import metrics
  from keras import models
  from keras import ops
  from keras import testing
label_desc: Use image node_id 1 for calling the EarlyStoppingTest obj's underlying member method code with example usage: obj.test_early_stopping() without return types