liveBook · Manning

ModelCheckpoint

As explained in Deep Learning with R, Third Edition

ModelCheckpoint is a Keras callback that saves model states during training, optionally retaining only the state with the best monitored performance.

ModelCheckpoint is a Keras callback that saves model states during training. Configure it to monitor a metric and, with save_best_only = TRUE, retain only the state from the best-performing epoch. section 7.3.2 section 7.3.3

Save the best validation model

callbacks_list <- list( callback_early_stopping( monitor = "val_accuracy", patience = 1 ), callback_model_checkpoint( filepath = "checkpoint_path.keras", monitor = "val_loss", save_best_only = TRUE ) ) model |> fit( train_images, train_labels, epochs = 10, callbacks = callbacks_list, validation_data = list(val_images, val_labels) ) model <- load_model("checkpoint_path.keras") Here, training can stop when validation accuracy stops improving, while the checkpoint preserves the model with the lowest validation loss. section 7.3.3

Use ModelCheckpoint to:

  • Save the model after training epochs during a standard fit() run. section 7.3.2 section 8.2.4
  • Monitor validation loss and overwrite the saved file only when the current value improves. section 8.2.4
  • Reload the saved state later for evaluation instead of retraining after overfitting begins. section 8.2.4
callback_model_checkpoint()
callback_early_stopping()
callback_learning_rate_scheduler()
callback_reduce_lr_on_plateau()
callback_csv_logger()

Browse related Keras callbacks for early stopping, learning-rate adjustment, plateau handling, and metric logging. section 7.3.2

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains callback configuration and best-metric replacement through runnable examples, stopping short of callback implementation internals.
Examples
Demonstrates MNIST-style image tensors and a convolutional image classifier using val_loss, .keras files, and test evaluation.
What it assumes
Assumes familiarity with model.fit(), validation data, and monitored metrics while introducing callbacks as fit()-time objects.
What you can do after
Operate/configure it by selecting a filepath, monitored metric, and save-best-only policy, then reload the saved model for evaluation.
How it connects
Connects ModelCheckpoint to callbacks, EarlyStopping, validation loss, overfitting, model loading, and model evaluation.

Also explained in

Compare how 2 books explain ModelCheckpoint →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.