Checkpoints

Callbacks for argus model saving.

class argus.callbacks.Checkpoint(dir_path='', file_format='model-{epoch:03d}-{train_loss:.6f}.pth', max_saves=None, period=1, save_after_exception=False)[source]

Save the model with a given period.

In the simplest case, the callback can be used to save the model after each epoch.

Parameters
  • dir_path (str, optional) – Directory to save checkpoints. The desired directory will be created if it does not exist. Defaults to ‘’.

  • file_format (str, optional) – Model saving filename format. Any valid value names from the model State may be used. Defaults to ‘model-{epoch:03d}-{train_loss:.6f}.pth’.

  • max_saves (int, optional) – Number of last saved models to keep. Should be positive. If None - save all models. Defaults to None.

  • period (int, optional) – Interval (number of epochs) between checkpoint saves. Defaults to 1.

  • save_after_exception (bool, optional) – Save the model checkpoint after an exception occurs. Defaults to False.

save_model(state: argus.engine.engine.State, file_path)[source]

Save model to file.

Override the method if you need custom checkpoint saving.

Parameters
  • state (argus.engine.State) – State.

  • file_path (str) – Checkpoint file path.

class argus.callbacks.MonitorCheckpoint(dir_path='', file_format='model-{epoch:03d}-{monitor:.6f}.pth', max_saves=None, save_after_exception=False, monitor='val_loss', better='auto')[source]

Save the model checkpoints after a metric is improved.

The MonitorCheckpoint augments the simple Checkpoint with a metric monitoring. It saves the model after the defined metric is improved. It is possible to monitor loss values during training as well as any metric available in the model State.

Parameters
  • dir_path (str, optional) – Directory to save checkpoints. The desired directory will be created if it does not exist. Defaults to ‘’.

  • file_format (str, optional) – Model saving filename format. Any valid value names from the model State may be used. Defaults to ‘model-{epoch:03d}-{monitor:.6f}.pth’.

  • max_saves ([type], optional) – Number of last saved models to keep. Should be positive. If None - save all models. Defaults to None.

  • save_after_exception (bool, optional) – Save the model checkpoint after an exception occurs. Defaults to False.

  • monitor (str, optional) – Metric name to monitor. It should be prepended with val_ for the metric value on validation data and train_ for the metric value on the date from the train loader. A val_loader should be provided during the model fit to make it possible to monitor metrics start with val_. Defaults to val_loss.

  • better (str, optional) – The metric improvement criterion. Should be ‘min’, ‘max’ or ‘auto’. ‘auto’ means the criterion should be taken from the metric itself, which is appropriate behavior in most cases. Defaults to ‘auto’.