deeplabcut.pose_estimation_pytorch.runners.base
Classes:
| Name | Description |
|---|---|
Runner |
Runner base class. |
Functions:
| Name | Description |
|---|---|
attempt_snapshot_load |
Attempts to load a snapshot using |
fix_snapshot_metadata |
Replace numpy floats in snapshot metrics. |
get_load_weights_only |
Gets the default value to use when loading snapshots with |
set_load_weights_only |
Sets the default value to use when loading snapshots with |
Runner
Bases: ABC, Generic[ModelType]
Runner base class.
A runner takes a model and runs actions on it, such as training or inference
Methods:
| Name | Description |
|---|---|
__init__ |
Args: |
load_snapshot |
Loads the state dict for a model from a file. |
Source code in deeplabcut/pose_estimation_pytorch/runners/base.py
__init__
__init__(model: ModelType, device: str = 'cpu', gpus: list[int] | None = None, snapshot_path: str | Path | None = None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ModelType
|
the model to run |
required |
|
str
|
the device to use (e.g. {'cpu', 'cuda:0', 'mps'}) |
'cpu'
|
|
list[int] | None
|
the list of GPU indices to use for multi-GPU training |
None
|
|
str | Path | None
|
the path of a snapshot from which to load model weights |
None
|
Source code in deeplabcut/pose_estimation_pytorch/runners/base.py
load_snapshot
staticmethod
load_snapshot(snapshot_path: str | Path, device: str, model: ModelType, weights_only: bool | None = None) -> dict
Loads the state dict for a model from a file.
This method loads a file containing a DeepLabCut PyTorch model snapshot onto a given device, and sets the model weights using the state_dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
The path containing the model weights to load |
required |
|
str
|
The device on which the model should be loaded |
required |
|
ModelType
|
The model for which the weights are loaded |
required |
|
bool | None
|
Value for torch.load() |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The content of the snapshot file. |
Source code in deeplabcut/pose_estimation_pytorch/runners/base.py
attempt_snapshot_load
Attempts to load a snapshot using torch.load(...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
The path of the snapshot to try to load.. |
required |
|
str
|
The device to use for the |
required |
|
bool | None
|
Value for torch.load() |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The loaded snapshot. |
Raises:
| Type | Description |
|---|---|
UnpicklingError
|
If |
Source code in deeplabcut/pose_estimation_pytorch/runners/base.py
fix_snapshot_metadata
Replace numpy floats in snapshot metrics.
Only call this method with snapshots that you trust, as torch.load(...) is called
with weights_only=False. For more information, see:
https://pytorch.org/docs/stable/generated/torch.load.html
DeepLabCut PyTorch snapshots trained with older releases may have numpy floats in
the stored metrics. This method opens the snapshots (with weights_only=False),
replaces the numpy floats with python floats (allowing to load with
weights_only=True), and saves the new snapshot data.
Warning: This overwrites your existing snapshot. If you want to ensure that no data
is lost, copy your snapshot before calling fix_snapshot_metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
The path of the snapshot to fix. |
required |
Source code in deeplabcut/pose_estimation_pytorch/runners/base.py
get_load_weights_only
Gets the default value to use when loading snapshots with torch.load(...).
Returns:
| Type | Description |
|---|---|
bool
|
The default |
Source code in deeplabcut/pose_estimation_pytorch/runners/base.py
set_load_weights_only
Sets the default value to use when loading snapshots with torch.load(...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
The default |
required |