xnn.common.train.callbacks.ModelCheckpoint#

class xnn.common.train.callbacks.ModelCheckpoint(monitor=None, mode=None, dirpath=None, filename='best.pt', save_last=True, every_n_epochs=0)[source]#

Bases: Callback

Saves the best model by a monitored value, the last model, and optional periodic snapshots.

Parameters:
  • monitor (str or None, optional) – The value to monitor; defaults to the trainer’s (trainer.monitor).

  • mode (str or None, optional) – "min" or "max"; defaults to the trainer’s.

  • dirpath (str or None, optional) – Directory of the checkpoints; defaults to cfg.output_dir.

  • filename (str, optional) – Name of the best checkpoint. Defaults to "best.pt".

  • save_last (bool, optional) – Also write last.pt after the last epoch. Defaults to True.

  • every_n_epochs (int, optional) – When > 0, also write epoch_<n>.pt every n epochs. Defaults to 0.

Variables:
  • best_score (float or None) – The best monitored value so far.

  • best_epoch (int or None) – The epoch it was reached in.

on_fit_start(trainer)[source]#

Fill the defaults from the trainer.

Return type:

None

on_epoch_end(trainer, epoch, metrics)[source]#

Save on improvement and on the periodic epochs.

Parameters:
Return type:

None

on_train_end(trainer)[source]#

Write last.pt.

Return type:

None