dcnum.segm.segm_torch.torch_model

Attributes

logger

Functions

check_md5sum(path)

Verify the last five characters of the file stem with its MD5 hash

load_model(path_or_name, device)

Load a PyTorch model + metadata from a TorchScript jit checkpoint

retrieve_model_file(path_or_name)

Retrieve a dcnum torch model file

Module Contents

dcnum.segm.segm_torch.torch_model.logger
dcnum.segm.segm_torch.torch_model.check_md5sum(path)[source]

Verify the last five characters of the file stem with its MD5 hash

dcnum.segm.segm_torch.torch_model.load_model(path_or_name, device)[source]

Load a PyTorch model + metadata from a TorchScript jit checkpoint

Parameters:
  • path_or_name (str or pathlib.Path) – jit checkpoint file; For dcnum, these files have the suffix .dcnm and contain a special _extra_files[“dcnum_meta.json”] extra file that can be loaded via torch.jit.load (see below).

  • device (str or torch.device) – device on which to run the model

Returns:

  • model_jit (torch.jit.ScriptModule) – loaded PyTorch model stored as a TorchScript module

  • model_meta (dict) – metadata associated with the loaded model

dcnum.segm.segm_torch.torch_model.retrieve_model_file(path_or_name)[source]

Retrieve a dcnum torch model file

If a path to a model is given, then this path is returned directly. If a file name is given, then look for the file with dcnum.meta.paths.find_file() using the “torch_model_file” topic.