Cross-Platform Frameworks¶
Already using MMPose, DeepLabCut, Lightning Pose, or SLEAP in your lab? You do not need to rebuild your lab's tracking pipeline to use PrimateFace. We release native v1.0.0 68-landmark face models for all four pose-estimation ecosystems—trained on the same PrimateFace splits—so you can drop our weights straight into the software your lab already runs, or fine-tune them on your own species and camera rig.
You can pick whichever toolbox your lab already knows
Across all four ecosystems, predicted eye-center coordinates on held-out macaque faces agree to within 0.49 pixels on average. Choose the framework that best fits your existing behavioral pipeline and hardware.
Canonical 4-Ecosystem Benchmark¶
All models below were evaluated on the same held-out test set (pose_test.json.gz, n = 15,814 primate faces from unseen individuals and sources). NME (Normalized Mean Error) measures average landmark placement error as a percentage of face size—so 0.58% NME is roughly 1 pixel of error on a 200-pixel-wide face (lower is better).
| Ecosystem | Architecture | Median NME ↓ | Checkpoint File | License |
|---|---|---|---|---|
| MMPose | ViTPose-L | 0.58% | vitpose_checkpoint.pth (primateface_vitpose_l_v1.0.0.pth) | Apache-2.0 |
| DeepLabCut 3.0.2 | RTMPose-M | 0.62% | dlc3_rtmpose_m_v1.0.0.pt | Apache-2.0 weights / LGPL-3.0 DLC |
| MMPose | RTMPose-M | 0.71% | rtmpose_checkpoint.pth (primateface_rtmpose_m_v1.0.0.pth) | Apache-2.0 |
| MMPose | HRNetV2-W18 | 0.85% | mmpose_checkpoint.pth (primateface_hrnet_w18_v1.0.0.pth) | Apache-2.0 |
| Lightning Pose 2.0 | ResNet-18 | 0.85% | lp2_resnet18_v1.0.0.ckpt | MIT |
| SLEAP-NN | ConvNeXt-Tiny | 1.09% | sleap_convnext_tiny_v1.0.0.ckpt | BSD-3-Clause |
Hardware requirements
Running inference on a few dozen photos works on a laptop CPU, while fine-tuning or processing long field videos is much faster on an NVIDIA GPU (or free Google Colab). See Model Zoo & Selection for speed and memory numbers.
Step 1: Download the Companion Weights¶
One command downloads the core PrimateFace v1.0.0 stack plus the DeepLabCut 3.0.2, Lightning Pose 2.0, and SLEAP-NN checkpoints from Hugging Face and verifies every file with a SHA-256 integrity check:
python demos/download_models.py --include-cross-platform ./models
# Optional: add --include-vitpose to also fetch ViTPose-L (1.23 GB)
Expected output (sizes reported in binary MiB; ~137 MB decimal prints as 131.0 MB):
All selected models downloaded and verified!
- primateface_rfdetr_m_v1.0.0.pth (131.0 MB)
- mmpose_checkpoint.pth (41.0 MB)
- rtmpose_checkpoint.pth (62.0 MB)
- dlc3_rtmpose_m_v1.0.0.pt (...)
- lp2_resnet18_v1.0.0.ckpt (...)
- sleap_convnext_tiny_v1.0.0.ckpt (...)
Step 2: Train or Evaluate in Your Toolbox¶
Select your lab's framework below for the exact v1.0.0 config and training/evaluation scripts included in this repository. All scripts read standard COCO JSON annotation files (a widely used JSON format storing image filenames, face boxes, and 68 landmark coordinates).
MMPose is the native backend behind the PrimateFace Python API and offers all three Apache-2.0 pose models (ViTPose-L, RTMPose-M, HRNetV2-W18-DARK). Release configs live in configs/release_v1.0.0/:
configs/release_v1.0.0/vitpose_l_68kpt_v1.0.0_config.pyconfigs/release_v1.0.0/rtmpose_m_68kpt_v1.0.0_config.pyconfigs/release_v1.0.0/hrnetv2_w18_dark_68kpt_v1.0.0_config.py
import primateface
# Switch between "hrnet" (41 MB), "rtmpose" (fastest), or "vitpose" (0.58% NME)
pf = primateface.PrimateFace(pose_model="rtmpose", model_dir="./models")
faces = pf.analyze("macaque.jpg")
print(f"Found {len(faces)} face(s), 68 keypoints shape: {faces[0].keypoints.shape}")
To fine-tune on your own COCO JSON dataset, point MMPose's standard tools/train.py at one of the three configs above and set load_from to the matching v1.0.0 checkpoint.
DeepLabCut 3.0.2 uses a modern PyTorch backend (deeplabcut>=3.0.2). Our released dlc3_rtmpose_m_v1.0.0.pt checkpoint achieves 0.62% median NME. Use evals/dlc/train_with_coco.py and evals/dlc/evaluate_nme.py to fine-tune or benchmark directly from COCO JSON:
uv pip install "deeplabcut>=3.0.2"
# Fine-tune RTMPose-M from the v1.0.0 checkpoint on your COCO JSON
python evals/dlc/train_with_coco.py \
--model_type rtmpose_m \
--coco_json ./my_labels.json \
--image_dir ./my_images \
--resume ./models/dlc3_rtmpose_m_v1.0.0.pt \
--output_dir ./dlc_finetuned
# Evaluate NME on a held-out COCO JSON test split
python evals/dlc/evaluate_nme.py \
--model_dir ./dlc_finetuned \
--test_json ./my_test.json
Lightning Pose 2.0 (lightning-pose>=2.0.0, MIT License) is popular in neuroscience labs for semi-supervised video tracking. Our lp2_resnet18_v1.0.0.ckpt achieves 0.85% median NME.
Note that train_lpose_with_coco.py expects cropped face images plus DeepLabCut / Lightning Pose MultiIndex CSV label files (which you can export directly from PrimateFace detections using primateface.io.to_dlc_csv).
uv pip install "lightning-pose>=2.0.0"
# Train on face crops + DLC / Lightning Pose CSV labels
python evals/lightning_pose/train_lpose_with_coco.py \
--crops-root ./face_crops --train-csv ./lp_train.csv --val-csv ./lp_val.csv \
--backbone resnet18 --epochs 25 --out-dir ./lp2_runs/resnet18
# Evaluate the v1.0.0 checkpoint on a COCO 68-keypoint test JSON
python evals/lightning_pose/evaluate_lpose_nme.py \
--ckpt ./models/lp2_resnet18_v1.0.0.ckpt --backbone resnet18 \
--coco-json ./pose_test.json --image-dir ./images \
--out-json ./lp2_eval_metrics.json
Technical details: exact 68-point symmetric flip wrapper
train_lpose_with_coco.py wraps training batches with SymmetricFlipWrapper, which mirrors 50% of face crops horizontally while swapping anatomically paired left/right landmarks (eyes, brows, jaw, lips) and applying a +0.75-stride sub-cell heatmap offset so left-facing and right-facing profiles stay bias-free.
SLEAP-NN (PyTorch backend, BSD-3-Clause) supports fast multi-animal tracking in the SLEAP GUI. Our released v1.0.0 sleap_convnext_tiny_v1.0.0.ckpt checkpoint uses PyTorch sleap-nn (achieving 1.09% median NME) and is run or fine-tuned with the standard sleap-nn CLI:
uv pip install sleap-nn
# Run tracking or fine-tune with the PyTorch sleap-nn CLI
sleap-nn track --help
sleap-nn train --help
Legacy SLEAP 1.x (TensorFlow .h5) helper scripts
The repository's evals/sleap/train_sleap_with_coco.py and evals/sleap/evaluate_sleap_nme.py scripts are legacy SLEAP 1.x (TensorFlow .h5) wrappers retained for older SLEAP installations—they do not load the PyTorch sleap_convnext_tiny_v1.0.0.ckpt file. If you still run SLEAP 1.x, edit the TRAIN_JSON_PATH / TEST_JSON_PATH constants at the top of those scripts before calling:
Step 3: Export Predictions Between Formats¶
Even if you run detection and landmarks with the Python PrimateFace API, primateface.io exports directly to DeepLabCut / Lightning Pose CSV, SLEAP .slp, COCO JSON, and NWB (Neurodata Without Borders, the standard neurophysiology archive format):
import primateface
from primateface import io
pf = primateface.PrimateFace()
faces = pf.analyze("macaque.jpg")
io.to_dlc_csv(faces, "out/macaque_dlc.csv") # Works in DeepLabCut & Lightning Pose
io.to_coco_json(faces, "out/macaque_coco.json", image_path="macaque.jpg")
io.to_sleap(faces, "out/macaque.slp") # Requires: uv pip install -e ".[interop]"
io.to_nwb(faces, "out/macaque.nwb") # Requires: uv pip install -e ".[interop]"
For full import/export options (including from_dlc, from_sleap, and to_dataframe), see Analysis Features & Data Export. For BORIS behavioral coding and video timestamping workflows (lemur_video_timestamping.ipynb), see Interactive Tutorials.
Next Steps¶
- Need to label new footage from an unusual species or camera rig? See Annotation & Frame Selection.
- Want full benchmark details across taxa and splits? See Benchmarks & Evaluation.