Neural network backend for training and inference for animal pose estimation.
-
Install miniforge
We recommend using miniforge for an isolated Python environment with fast dependency resolution. -
Create and activate the development environment using Python 3.11
mamba create -n sleap-nn-dev python=3.11 mamba activate sleap-nn-dev
-
Install
uvand development dependencies
uvis a fast and modern package manager forpyproject.toml-based projects.pip install uv uv pip install -e ".[dev]" -
Install PyTorch based on your platform
You can either:-
Install the optional dependencies:
uv pip install -e ".[torch]"This installs the default builds of
torchandtorchvisionvia PyPI for your OS. -
Or manually install the correct wheel for your system using PyTorch's index URL:
-
Windows/Linux with NVIDIA GPU (CUDA 11.8):
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
-
macOS with Apple Silicon (M1, M2, M3, M4): You don’t need to do anything if you used the
[torch]optional dependency or default PyPI install--the default wheels now include Metal backend support for Apple GPUs. -
CPU-only (no GPU or unsupported GPU): You don’t need to do anything if you used the
[torch]optional dependency or default PyPI install.
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
-
You can find the correct wheel for your system at:
👉 https://pytorch.org/get-started/locally -
-
Run tests
pytest tests
-
(Optional) Lint and format code
black --check sleap_nn tests ruff check sleap_nn/
The torch and torchvision dependencies are now defined as optional in pyproject.toml. However, they are required for the code to run, and are imported at the top level in many modules. This means:
-
You must install
sleap-nnwith the[torch]extras:uv pip install -e ".[torch]" -
Or manually install
torchandtorchvisionwith the appropriate build for your system.
🛑 If you install
sleap-nnwithouttorch, any import of `` will fail with anImportErroruntil you install it manually.
To improve the flexibility and user experience, future versions of sleap-nn may:
- Move `` imports into functions or use conditional imports to avoid top-level dependency failures.
- Add clearer runtime error messages when
torchis required but not available. - Enable limited functionality in environments without PyTorch (e.g. metadata inspection or CLI help).
This would allow sleap-nn to be installed and imported without torch, only requiring it when deep learning functionality is actually used.
We intentionally do not include GPU-specific torch or torchvision builds in pyproject.toml. Instead, we recommend installing them manually based on your platform.
- Portability: No CUDA version or hardware is assumed. This avoids broken installs on unsupported platforms.
- Flexibility: You can use the appropriate PyTorch build for your system.
- Reliability: All other dependencies are managed cleanly with
uv.
💡 This makes
sleap-nncompatible with both GPU-accelerated and CPU-only environments.
📦 Why not use `pyproject.toml` for GPU builds?
- GPU wheels are not on PyPI — they live at https://download.pytorch.org/whl/
- These builds vary by platform, CUDA version, and GPU architecture.
uvdoes not currently support CLI-based extra index URLs like pip’s--index-url.- Hardcoding GPU wheels into
pyproject.tomlwould break cross-platform support.
This repository uses GitHub Actions for continuous integration and publishing:
Runs on every pull request and performs the following:
- Sets up a Conda environment using Miniforge3 with Python 3.11.
- Installs
uvand uses it to install the package in editable mode with dev dependencies. - Runs code quality checks using
blackandruff. - Executes the test suite using
pytestwith coverage reporting. - Uploads coverage results to Codecov.
Runs on all major operating systems (ubuntu-latest, windows-latest, macos-14).
Triggered on GitHub Releases:
- For pre-releases, the package is published to Test PyPI for testing.
- For final releases, the package is published to the official PyPI registry using trusted publishing.
The uv tool is used for both building and publishing. You can create a pre-release by tagging your release with a version suffix like 1.0.0rc1 or 1.0.0b1.
To test the pre-release in your development workflow:
uv pip install --index-url https://test.pypi.org/simple/ sleap-nnTrusted publishing is handled automatically using GitHub OIDC, and no credentials are stored.