CerebNet.utils.checkpoint

CerebNet.utils.checkpoint.create_checkpoint_dir(expr_dir, expr_num)[source]

Create the checkpoint dir if not exists.

Parameters:
expr_dirUnion[os.PathLike]

Directory to create.

expr_numint

Experiment number.

Returns:
checkpoint_dir

Directory of the checkpoint.

CerebNet.utils.checkpoint.get_checkpoint(ckpt_dir, epoch)[source]

Find the standardizes checkpoint name for the checkpoint in the directory ckpt_dir for the given epoch.

Parameters:
ckpt_dirstr

Checkpoint directory.

epochint

Number of the epoch.

Returns:
checkpoint_dir

Standardizes checkpoint name.

CerebNet.utils.checkpoint.get_checkpoint_path(log_dir, resume_experiment=None)[source]

Find the paths to checkpoints from the experiment directory.

Parameters:
log_dirPath, str

Experiment directory.

resume_experimentUnion[str, int, None]

Sub-experiment to search in for a model (Default value = None).

Returns:
prior_model_pathsMutableSequence[Path]

A list of filenames for checkpoints.

CerebNet.utils.checkpoint.is_checkpoint_epoch(cfg, cur_epoch)[source]

Check if checkpoint need to be saved.

Parameters:
cfgyacs.config.CfgNode

The config node.

cur_epochint

The current epoch number to check if this is the last epoch.

CerebNet.utils.checkpoint.load_from_checkpoint(checkpoint_path, model, optimizer=None, scheduler=None, fine_tune=False, drop_classifier=False)[source]

Load the model from the given experiment number.

Parameters:
checkpoint_pathstr, Path

Path to the checkpoint.

modeltorch.nn.Module

Network model.

optimizerOptional[torch.optim.Optimizer]

Network optimizer (Default value = None).

schedulerOptional[Scheduler]

Network scheduler (Default value = None).

fine_tunebool

Whether to fine tune or not (Default value = False).

drop_classifierbool

Whether to drop the classifier or not (Default value = False).

Returns:
loaded_epochint

Epoch number.

CerebNet.utils.checkpoint.save_checkpoint(checkpoint_dir, epoch, best_metric, num_gpus, cfg, model, optimizer, scheduler=None, best=False)[source]

Save the state of training for resume or fine-tune.

Parameters:
checkpoint_dirstr, Path

Path to the checkpoint directory.

epochint

Current epoch.

best_metricbest_metric

Best calculated metric.

num_gpusint

Number of used gpus.

cfgyacs.config.CfgNode

Configuration node.

modeltorch.nn.Module

Used network model.

optimizertorch.optim.Optimizer

Used network optimizer.

schedulerOptional[Scheduler]

Used network scheduler. Optional (Default value = None).

bestbool, default=False

Whether this was the best checkpoint so far (Default value = False).