py123d_detection.torch.callbacks

Callbacks the training loop adds beyond Lightning’s own.

SaveEpochCheckpoints exists because the stock ModelCheckpoint keeps the best three by val_loss and overwrites last.ckpt every epoch. That is the right default for getting a trained model out of a run, and useless for asking what the model looked like halfway through: by the time a 24-epoch run finishes, epoch 12 is gone. Scoring an intermediate epoch is how you tell a model that is still improving from one that peaked early and has been drifting since.

Classes

SaveEpochCheckpoints(dirpath, save_epochs)

Write a checkpoint of its own at the end of each named epoch.

class py123d_detection.torch.callbacks.SaveEpochCheckpoints(dirpath, save_epochs)[source]

Bases: Callback

Write a checkpoint of its own at the end of each named epoch.

save_epochs=[6, 12, 18] leaves epoch_6.ckpt, epoch_12.ckpt and epoch_18.ckpt in dirpath, next to whatever ModelCheckpoint is doing. Nothing overwrites them.

Epochs are counted the way a training log reads them, from 1, so 12 means after twelve epochs of training. Lightning’s own current_epoch is 0-indexed during the epoch, which is where the off-by-one lives; it is converted here so that a config file never has to think about it.

Parameters:
  • dirpath (str | Path) – Directory to write into, created if it does not exist.

  • save_epochs (Iterable[int]) – 1-indexed epoch numbers. Epochs outside the run are simply never reached.

on_validation_epoch_end(trainer, pl_module)[source]
Return type:

None