Checkpoints

Callbacks for argus model saving.

class argus.callbacks.Checkpoint(dir_path: Union[pathlib.Path, str] = '', file_format: str = 'model-{epoch:03d}-{train_loss:.6f}.pth', max_saves: Optional[int] = None, period: int = 1, save_after_exception: bool = False, optimizer_state: bool = 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 or pathlib.Path) – 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.

  • optimizer_state (bool) – Save optimizer state. Defaults to False.

save_model(state: argus.engine.engine.State, file_path: Union[pathlib.Path, str])[source]

Save model to file.

Override the method if you need custom checkpoint saving.

Parameters
class argus.callbacks.MonitorCheckpoint(dir_path: Union[pathlib.Path, str] = '', file_format: str = 'model-{epoch:03d}-{monitor:.6f}.pth', max_saves: Optional[int] = None, save_after_exception: bool = False, optimizer_state: bool = False, monitor: str = 'val_loss', better: str = '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 or pathlib.Path) – 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 (int, 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.

  • optimizer_state (bool) – Save optimizer state. 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’.

attach(engine: argus.engine.engine.Engine)

Attach callback to the argus.engine.Engine.

Parameters

engine (Engine) – The engine to which the callback will be attached.

save_model(state: argus.engine.engine.State, file_path: Union[pathlib.Path, str])

Save model to file.

Override the method if you need custom checkpoint saving.

Parameters