FastSurferCNN.utils.checkpoint

class FastSurferCNN.utils.checkpoint.CheckpointConfigDict[source]

Methods

clear()

copy()

fromkeys(iterable[, value])

Create a new dictionary with keys from iterable and values set to value.

get(key[, default])

Return the value for key if key is in the dictionary, else default.

items()

keys()

pop(key[, default])

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

setdefault(key[, default])

Insert key with a value of default if key is not in the dictionary.

update([E, ]**F)

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values()

FastSurferCNN.utils.checkpoint.check_and_download_ckpts(checkpoint_path, urls)[source]

Check and download a checkpoint file, if it does not exist.

Parameters:
checkpoint_pathPath, str

Path of the file in which the checkpoint will be saved.

urlslist[str]

URLs of checkpoint hosting site.

FastSurferCNN.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.

FastSurferCNN.utils.checkpoint.download_checkpoint(checkpoint_name, checkpoint_path, urls)[source]

Download a checkpoint file.

Raises an HTTPError if the file is not found or the server is not reachable.

Parameters:
checkpoint_namestr

Name of checkpoint.

checkpoint_pathPath, str

Path of the file in which the checkpoint will be saved.

urlslist[str]

List of URLs of checkpoint hosting sites.

FastSurferCNN.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.

FastSurferCNN.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.

FastSurferCNN.utils.checkpoint.get_checkpoints(*checkpoints, urls)[source]

Check and download checkpoint files if not exist.

Parameters:
*checkpointsPath, str

Paths of the files in which the checkpoint will be saved.

urlsPath, str

URLs of checkpoint hosting sites.

FastSurferCNN.utils.checkpoint.load_checkpoint_config(filename=PosixPath('/home/runner/work/FastSurfer/FastSurfer/dev/FastSurferCNN/config/checkpoint_paths.yaml'))[source]

Load the plane dictionary from the yaml file.

Parameters:
filenamePath, str

Path to the yaml file. Either absolute or relative to the FastSurfer root directory.

Returns:
CheckpointConfigDict

A dictionary representing the contents of the yaml file.

FastSurferCNN.utils.checkpoint.load_checkpoint_config_defaults(configtype, filename=PosixPath('/home/runner/work/FastSurfer/FastSurfer/dev/FastSurferCNN/config/checkpoint_paths.yaml'))[source]

Get the default value for a specific plane or the url.

Parameters:
configtype“checkpoint”, “config”, “url”

Type of value.

filenamestr, Path

The path to the yaml file. Either absolute or relative to the FastSurfer root directory.

Returns:
dict[Plane, Path], list[str]

Default value for the plane.

FastSurferCNN.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.

FastSurferCNN.utils.checkpoint.remove_ckpt(ckpt)[source]

Remove the checkpoint.

Parameters:
ckptstr, Path

Path and filename to the checkpoint.

FastSurferCNN.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).