mednet.utils.checkpointer

Module Attributes

CheckpointAliasType

Definition of a Checkpoint alias type to make it flexible to user defined metric to monitor.

CHECKPOINT_ALIASES

Standard paths where checkpoints may be (if produced with this framework).

Functions

get_checkpoint_to_resume_training(path)

Return the best checkpoint file path to resume training from.

get_checkpoint_to_run_inference(path, metric)

Return the best checkpoint file path to run inference with.

mednet.utils.checkpointer.CheckpointAliasType = str | collections.abc.Callable[[str, str], str]

Definition of a Checkpoint alias type to make it flexible to user defined metric to monitor.

mednet.utils.checkpointer.CHECKPOINT_ALIASES: dict[str, str | Callable[[str, str], str]] = {'best': <function <lambda>>, 'periodic': 'model-at-{epoch}'}

Standard paths where checkpoints may be (if produced with this framework).

mednet.utils.checkpointer.get_checkpoint_to_resume_training(path)[source]

Return the best checkpoint file path to resume training from.

Parameters:

path (Path) – The base directory containing either the “periodic” checkpoint to start the training session from.

Returns:

Path to a checkpoint file that exists on disk.

Return type:

Path

Raises:

FileNotFoundError – If none of the checkpoints can be found on the provided directory.

mednet.utils.checkpointer.get_checkpoint_to_run_inference(path, metric, mode='min')[source]

Return the best checkpoint file path to run inference with.

Parameters:
  • path (Path) – The base directory containing either the “best”, “last” or “periodic” checkpoint to start the training session from.

  • metric (str) – Name of the metric used for monitoring and saving the best checkpoint (default: “loss”).

  • mode (Literal['min', 'max']) – One of {“min”, “max”}.

Returns:

Path to a checkpoint file that exists on disk.

Return type:

Path

Raises:

FileNotFoundError – If none of the checkpoints can be found on the provided directory.