title: tf.keras.callbacks.ModelCheckpoint ignores the montior parameter and always use loss
body: <p>I am running tf.keras.callbacks.ModelCheckpoint with the accuracy metric but loss is used to save the best checkpoints. I have tested this in different places (my computer and collab) and two different code and faced the same issue. Here is an example code and the results:</p>
  <pre><code>import tensorflow as tf
  from tensorflow import keras
  from tensorflow.keras import layers
  import os
  import shutil
  
  def get_uncompiled_model():
      inputs = keras.Input(shape=(784,), name=&quot;digits&quot;)
      x = layers.Dense(64, activation=&quot;relu&quot;, name=&quot;dense_1&quot;)(inputs)
      x = layers.Dense(64, activation=&quot;relu&quot;, name=&quot;dense_2&quot;)(x)
      outputs = layers.Dense(10, activation=&quot;softmax&quot;, name=&quot;predictions&quot;)(x)
      model = keras.Model(inputs=inputs, outputs=outputs)
      return model
  
  def get_compiled_model():
      model = get_uncompiled_model()
      model.compile(
          optimizer=&quot;rmsprop&quot;,
          loss=&quot;sparse_categorical_crossentropy&quot;,
          metrics=[&quot;accuracy&quot;],
      )
      return model
  
  (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
  
  # Preprocess the data (these are NumPy arrays)
  x_train = x_train.reshape(60000, 784).astype(&quot;float32&quot;) / 255
  x_test = x_test.reshape(10000, 784).astype(&quot;float32&quot;) / 255
  
  y_train = y_train.astype(&quot;float32&quot;)
  y_test = y_test.astype(&quot;float32&quot;)
  
  # Reserve 10,000 samples for validation
  x_val = x_train[-10000:]
  y_val = y_train[-10000:]
  x_train = x_train[:-10000]
  y_train = y_train[:-10000]
  
  
  ckpt_folder = os.path.join(os.getcwd(), 'ckpt')
  if os.path.exists(ckpt_folder):
      shutil.rmtree(ckpt_folder)
  
  ckpt_path = os.path.join(r'D:\deep_learning\tf_keras\semantic_segmentation\logs', 'mymodel_{epoch}')
  
  
  callbacks = [
      tf.keras.callbacks.ModelCheckpoint(
          # Path where to save the model
          # The two parameters below mean that we will overwrite
          # the current checkpoint if and only if
          # the `val_loss` score has improved.
          # The saved model name will include the current epoch.
          filepath=ckpt_path,
          montior=&quot;val_accuracy&quot;,
          # save the model weights with best validation accuracy
          mode='max',
          save_best_only=True,  # only save the best weights
          save_weights_only=False,
          # only save model weights (not whole model)
          verbose=1
      )
  ]
  
  model = get_compiled_model()
  
  
  model.fit(
      x_train, y_train, epochs=3, batch_size=1, callbacks=callbacks, validation_split=0.2, steps_per_epoch=1
  )
  </code></pre>
  <p>1/1 [==============================] - ETA: 0s - loss: 2.6475 - accuracy: 0.0000e+00
  Epoch 1: val_loss improved from -inf to 2.32311, saving model to D:\deep_learning\tf_keras\semantic_segmentation\logs\mymodel_1
  1/1 [==============================] - 6s 6s/step - loss: 2.6475 - accuracy: 0.0000e+00 - val_loss: 2.3231 - val_accuracy: 0.1142</p>
  <p>Epoch 2/3
  1/1 [==============================] - ETA: 0s - loss: 1.9612 - accuracy: 1.0000
  Epoch 2: val_loss improved from 2.32311 to 2.34286, saving model to D:\deep_learning\tf_keras\semantic_segmentation\logs\mymodel_2
  1/1 [==============================] - 5s 5s/step - loss: 1.9612 - accuracy: 1.0000 - val_loss: 2.3429 - val_accuracy: 0.1187</p>
  <p>Epoch 3/3
  1/1 [==============================] - ETA: 0s - loss: 2.8378 - accuracy: 0.0000e+00
  Epoch 3: val_loss did not improve from 2.34286
  1/1 [==============================] - 5s 5s/step - loss: 2.8378 - accuracy: 0.0000e+00 - val_loss: 2.2943 - val_accuracy: 0.1346</p>