Skip to content

deeplabcut.pose_estimation_pytorch.utils

Functions:

Name Description
create_folder

Creates all folders contained in the path.

fix_seeds

Fixes the random seed for python, numpy and pytorch.

resolve_device

Determines which device should be used from the model config.

create_folder

create_folder(path_to_folder)

Creates all folders contained in the path.

Parameters:

Name Type Description Default

path_to_folder

Path to the folder that should be created

required
Source code in deeplabcut/pose_estimation_pytorch/utils.py
def create_folder(path_to_folder):
    """Creates all folders contained in the path.

    Args:
        path_to_folder: Path to the folder that should be created
    """
    if not os.path.exists(path_to_folder):
        os.makedirs(path_to_folder)

fix_seeds

fix_seeds(seed: int) -> None

Fixes the random seed for python, numpy and pytorch.

Parameters:

Name Type Description Default

seed

int

the seed to set

required
Source code in deeplabcut/pose_estimation_pytorch/utils.py
def fix_seeds(seed: int) -> None:
    """Fixes the random seed for python, numpy and pytorch.

    Args:
        seed: the seed to set
    """
    random.seed(seed)
    torch.manual_seed(seed)
    np.random.seed(seed)
    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = False

resolve_device

resolve_device(model_config: dict) -> str

Determines which device should be used from the model config.

When the device is set to 'auto': If an Nvidia GPU is available, selects the device as cuda:0. Selects 'mps' if available (on macOS) and the net type is compatible. Otherwise, returns 'cpu'. Otherwise, simply returns the selected device

Parameters:

Name Type Description Default

model_config

dict

the configuration for the pose model

required

Returns:

Type Description
str

the device on which training should be run

Source code in deeplabcut/pose_estimation_pytorch/utils.py
def resolve_device(model_config: dict) -> str:
    """Determines which device should be used from the model config.

    When the device is set to 'auto':
        If an Nvidia GPU is available, selects the device as cuda:0.
        Selects 'mps' if available (on macOS) and the net type is compatible.
        Otherwise, returns 'cpu'.
    Otherwise, simply returns the selected device

    Args:
        model_config: the configuration for the pose model

    Returns:
        the device on which training should be run
    """
    device = model_config["device"]
    supports_mps = "resnet" in model_config.get("net_type", "resnet")

    if device == "auto":
        if torch.cuda.is_available():
            return "cuda"
        elif supports_mps and torch.backends.mps.is_available():
            return "mps"
        return "cpu"
    return device