26The module provides utility functions for loading data from files 
   36if sys.version_info[1] < 11:
 
   37    import tomli 
as tomllib
 
   44    Class provides the following utility functions: 
   53        Function to sanitize a path string 
   56        return os.path.normpath(os.path.expanduser(os.path.expandvars(path_str)))
 
   59    def load_tensor(path: (str, pathlib.Path)) -> torch.tensor:
 
 
   61        Function to load a tensor from a file 
   62        Can load tensors from jit script format files 
   65            path (str): Path to the file 
   68            tensor: The loaded tensor 
   69            None: If the file does not exist 
   72            FileNotFoundError: If the file does not exist 
   75        if isinstance(path, pathlib.Path):
 
   78        path = IOUtils.sanitize_path(path)
 
   80        if not os.path.exists(path):
 
   81            raise FileNotFoundError(f
"IOUtils::load_tensor: File not found: {path}")
 
   83        data = torch.load(path, weights_only=
True)
 
   86        if isinstance(data, torch.jit.ScriptModule):
 
   87            tensor = list(data.parameters())[0]
 
 
   96        Function to load a yaml file 
   99            path (str): Path to the file 
  102            data: The loaded data 
  105            FileNotFoundError: If the file does not exist 
  108        path = IOUtils.sanitize_path(path)
 
  111        if not os.path.exists(path):
 
  112            raise FileNotFoundError(f
"IOUtils::load_yaml File not found: {path}")
 
  114        with open(path, 
"rb") 
as f:
 
  115            data = yaml.load(f, Loader=yaml.FullLoader)
 
 
  122        Function to load a toml file 
  124        path = IOUtils.sanitize_path(path)
 
  126        if not os.path.exists(path):
 
  127            raise FileNotFoundError(f
"IOUtils::load_toml: File not found: {path}")
 
  129        with open(path, 
"rb") 
as f:
 
  130            data = tomllib.load(f)
 
 
 
Class provides the following utility functions:
 
str sanitize_path(str path_str)
Function to sanitize a path string.
 
torch.tensor load_tensor((str, pathlib.Path) path)
Function to load a tensor from a file Can load tensors from jit script format files.
 
dict load_toml(str path)
Function to load a toml file.
 
dict load_yaml(str path)
Function to load a yaml file.