luz_callback_model_checkpoint: Checkpoints model weights

luz_callback_model_checkpointR Documentation

Checkpoints model weights

Description

This saves checkpoints of the model according to the specified metric and behavior.

Usage

luz_callback_model_checkpoint(
  path,
  monitor = "valid_loss",
  save_best_only = FALSE,
  mode = "min",
  min_delta = 0
)

Arguments

path

Path to save the model on disk. The path is interpolated with glue, so you can use any attribute within the ctx by using '{ctx$epoch}'. Specially the epoch and monitor quantities are already in the environment. If the specified path is a path to a directory (ends with / or ⁠\⁠), then models are saved with the name given by ⁠epoch-{epoch:02d}-{self$monitor}-{monitor:.3f}.pt⁠. See more in the examples. You can use sprintf() to quickly format quantities, for example:'{epoch:02d}'.

monitor

A string in the format ⁠<set>_<metric>⁠ where ⁠<set>⁠ can be 'train' or 'valid' and ⁠<metric>⁠ can be the abbreviation of any metric that you are tracking during training. The metric name is case insensitive.

save_best_only

if TRUE models are only saved if they have an improvement over a previously saved model.

mode

Specifies the direction that is considered an improvement. By default 'min' is used. Can also be 'max' (higher is better) and 'zero' (closer to zero is better).

min_delta

Minimum difference to consider as improvement. Only used when save_best_only=TRUE.

Note

mode and min_delta are only used when save_best_only=TRUE. save_best_only will overwrite the saved models if the path parameter don't differentiate by epochs.

Read the checkpointing article in the pkgdown website for more information.

See Also

Other luz_callbacks: luz_callback_auto_resume(), luz_callback_csv_logger(), luz_callback_early_stopping(), luz_callback_interrupt(), luz_callback_keep_best_model(), luz_callback_lr_scheduler(), luz_callback_metrics(), luz_callback_mixed_precision(), luz_callback_mixup(), luz_callback_profile(), luz_callback_progress(), luz_callback_resume_from_checkpoint(), luz_callback_train_valid(), luz_callback()

Examples

luz_callback_model_checkpoint(path= "path/to/dir")
luz_callback_model_checkpoint(path= "path/to/dir/epoch-{epoch:02d}/model.pt")
luz_callback_model_checkpoint(path= "path/to/dir/epoch-{epoch:02d}/model-{monitor:.2f}.pt")


mlverse/luz documentation built on Sept. 19, 2024, 11:20 p.m.