code: def test_model_checkpoint_loading(self):
      def get_model():
          inputs = layers.Input(shape=(INPUT_DIM,), batch_size=5)
          x = layers.Dense(NUM_HIDDEN, activation="relu")(inputs)
          outputs = layers.Dense(NUM_CLASSES, activation="softmax")(x)
          functional_model = models.Model(inputs, outputs)
          functional_model.compile(
              loss="categorical_crossentropy",
              optimizer="sgd",
              metrics=[metrics.Accuracy("acc")],
          )
          return functional_model
  
      (x_train, y_train), (x_test, y_test) = test_utils.get_test_data(
          random_seed=42,
          train_samples=TRAIN_SAMPLES,
          test_samples=TEST_SAMPLES,
          input_shape=(INPUT_DIM,),
          num_classes=NUM_CLASSES,
      )
      y_test = numerical_utils.to_categorical(
          y_test, num_classes=NUM_CLASSES
      )
      y_train = numerical_utils.to_categorical(
          y_train, num_classes=NUM_CLASSES
      )
  
      # Model Checkpoint load model (default)
      model = get_model()
      temp_dir = self.get_temp_dir()
      filepath = os.path.join(temp_dir, "checkpoint.model.keras")
      mode = "auto"
      monitor = "val_loss"
      save_best_only = True
  
      cbks = [
          callbacks.ModelCheckpoint(
              filepath,
              monitor=monitor,
              save_best_only=save_best_only,
              mode=mode,
          )
      ]
      model.fit(
          x_train,
          y_train,
          batch_size=BATCH_SIZE,
          validation_data=(x_test, y_test),
          callbacks=cbks,
          epochs=1,
          verbose=0,
      )
      ref_weights = model.get_weights()
      self.assertTrue(os.path.exists(filepath))
      new_model = saving.load_model(filepath)
      new_weights = new_model.get_weights()
      self.assertEqual(len(ref_weights), len(new_weights))
      for ref_w, w in zip(ref_weights, new_weights):
          self.assertAllClose(ref_w, w)
  
      # Model Checkpoint load model weights
      model = get_model()
      temp_dir = self.get_temp_dir()
      filepath = os.path.join(temp_dir, "checkpoint.weights.h5")
      mode = "auto"
      monitor = "val_loss"
      save_best_only = True
  
      cbks = [
          callbacks.ModelCheckpoint(
              filepath,
              monitor=monitor,
              save_best_only=save_best_only,
              save_weights_only=True,
              mode=mode,
          )
      ]
      model.fit(
          x_train,
          y_train,
          batch_size=BATCH_SIZE,
          validation_data=(x_test, y_test),
          callbacks=cbks,
          epochs=1,
          verbose=0,
      )
      ref_weights = model.get_weights()
      self.assertTrue(os.path.exists(filepath))
      new_model = get_model()
      new_model.load_weights(filepath)
      new_weights = new_model.get_weights()
      self.assertEqual(len(ref_weights), len(new_weights))
      for ref_w, w in zip(ref_weights, new_weights):
          self.assertAllClose(ref_w, w)
  
file_path: keras/keras/callbacks/model_checkpoint_test.py
imports: import os
  import warnings
  import pytest
  from keras import callbacks
  from keras import layers
  from keras import metrics
  from keras import models
  from keras import saving
  from keras import testing
  from keras.models import Sequential
  from keras.testing import test_utils
  from keras.utils import numerical_utils
label_desc: Use image node_id 2 for calling the ModelCheckpointTest obj's underlying member method code with example usage: obj.test_model_checkpoint_loading() and returns: functional_model