Deep learning for NeuroImaging in Python.
Note
This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the gallery for the big picture.
- class nidl.utils.weights.Weights(name: str, data_dir: str | Path, filepath: str)[source]¶
A class to handle (retrieve and apply) model weights.
- Parameters:
name : str
the location of the model weights specified in the form hf-hub:path/architecture_name@revision if available in Hugging Face hub or ns-hub:path/architecture_name if available in the NeuroSpin hub or a path if avaiable in your local machine.
data_dir : pathlib.Path or str
path where data should be downloaded.
filepath : str
the path of the file in the repo.
- classmethod hf_download(data_dir: str | Path, hf_id: str, filepath: str, hf_revision: str | None = None, force_download: bool = False) Path [source]¶
Download a given file if not already present.
Downloads always resume when possible. If you want to force a new download, use force_download=True.
- Parameters:
data_dir : pathlib.Path or str
path where data should be downloaded.
hf_id : str
the id of the repository.
filepath : str
the path of the file in the repo.
hf_revision : str, default=None
the revision of the repository (a tag, or a commit hash).
force_download : bool, default=False
whether the file should be downloaded even if it already exists in the local cache.
- Returns:
weight_file : Path
local path to the model weights.
- classmethod hub_split(hub_name: str) tuple[str, str | None] [source]¶
Interpret the input hub name specified in the form hf-hub:path/architecture_name@revision or ns-hub:path/architecture_name.
- Parameters:
hub_name : str
name of the repository.
- Returns:
hub_id : str
the id of the repository.
hub_revision : str
the revision of the repository.
- load_pretrained(model: Module)[source]¶
Load the model weights.
- Parameters:
model : torch.nn.Module
an input model with a load_pretrained method decalred.
- classmethod ns_download(data_dir: str | Path, ns_id: str, filepath: str, force_download: bool = False) Path [source]¶
Download a given file if not already present.
Downloads always resume when possible. If you want to force a new download, use force_download=True.
- Parameters:
data_dir : pathlib.Path or str
path where data should be downloaded.
ns_id : str
the id of the repository.
filepath : str
the path of the file in the repo.
force_download : bool, default=False
whether the file should be downloaded even if it already exists in the local cache.
- Returns:
weight_file : Path
local path to the model weights.
Examples¶
Follow us