Skip to content

Models

dynaface.models

Download Dynaface's three AI models, load them and choose a device to run on.

download_models

download_models(
    path: Optional[Union[str, Path]] = None,
    verify_hash: bool = True,
) -> str

Download Dynaface's AI models, unless they're already there.

The three ONNX models (about 400 MB) come as one zip file, which is checked against a SHA-256 hash and then unpacked.

Parameters:

Name Type Description Default
path Optional[Union[str, Path]]

The folder for the models. Defaults to ~/.dynaface/models.

None
verify_hash bool

Whether to check the download's SHA-256 hash before unpacking it.

True

Returns:

Name Type Description
str str

The folder that holds the models, to pass to init_models().

Raises:

Type Description
ValueError

If the download doesn't match the expected hash.

init_models

init_models(model_path: str, device: str) -> None

Load the AI models. Call this once before analyzing any face.

Parameters:

Name Type Description Default
model_path str

The folder that holds the models, as download_models() returns it.

required
device str

"cpu", "cuda" for an NVIDIA GPU, or "mps" for Core ML on a Mac. detect_device() picks the best one available.

required

unload_models

unload_models() -> None

Release the loaded models. Call init_models() again before analyzing more.

are_models_init

are_models_init() -> bool

Report whether init_models() has been called.

Returns:

Name Type Description
bool bool

True once init_models() has been called. It stays True after unload_models().

detect_device

detect_device() -> str

Pick the fastest device ONNX Runtime can use on this computer.

Returns:

Name Type Description
str str

"cuda" when an NVIDIA GPU is available, "mps" (Core ML) on a Mac that supports it, and "cpu" otherwise.