Annotation & Frame Selection¶
Building a custom labeled dataset—for example, for an under-represented primate species, an infrared camera trap, or a new laboratory filming rig—usually means spending weeks hand-clicking bounding boxes and 68 facial landmarks. PrimateFace ships two complementary tools to cut that labeling time dramatically:
- Pseudo-labeling (
gui/pseudolabel.py): Automatically generates draft boxes and 68 landmarks on your new photos or videos so you only fix mistakes instead of annotating from scratch. - DINOv2 frame selection (
dinov2/dinov2_cli.py): Picks the most visually diverse frames from a large pile of redundant video footage before you invest human annotation time.
Part 1: Speeding Up Labeling with Pseudo-Labeling¶
Pseudo-labeling means letting a pretrained PrimateFace model draw draft face boxes and 68 landmarks on your new images or video frames, exporting everything into a standard COCO JSON annotation file (a structured text file accepted by CVAT, Label Studio, DeepLabCut, SLEAP, and MMPose). Instead of clicking 68 points per face from scratch, annotators only nudge the few points that drifted.

Open the Interactive Review GUI¶
Once you have a draft COCO JSON file, launch the browser-based review interface shown above to inspect and adjust bounding boxes or 68 landmarks:
(Add --enable-keypoints to nudge individual landmarks interactively, and --output ./refined.json to save to a new file.)
Laptop CPU vs. GPU
Pseudo-labeling a few hundred photos works on a laptop CPU (--device cpu), though a GPU processes thousands of images or long videos 10–30× faster. If you do not have a local GPU, you can run this step on Google Colab.
Install and Download Models¶
Generate Draft Annotations (CLI)¶
By default, gui.pseudolabel uses RF-DETR-M (--framework rfdetr, Apache-2.0) for face detection and MMPose (--pose-framework mmpose) for 68 landmarks. Legacy MMDetection (--framework mmdet) is also supported optionally.
Expected output in ./pseudo_out/: a COCO JSON file containing image metadata, face bounding boxes, and 68-landmark coordinates (plus optional preview images when you pass --save-viz).
Generate Draft Annotations (Python)¶
from gui import Detector, PoseEstimator, ImageCOCOConverter
detector = Detector("rfdetr", checkpoint_path="./models/primateface_rfdetr_m_v1.0.0.pth")
pose = PoseEstimator(
"mmpose",
config_path="./models/mmpose_config.py",
checkpoint_path="./models/mmpose_checkpoint.pth",
)
converter = ImageCOCOConverter(detector, pose, output_dir="./pseudo_out")
json_path = converter.process_directory("./images")
print(f"Draft COCO annotations saved to: {json_path}")
Technical details: useful gui.pseudolabel flags
--bbox-thr 0.3— minimum face detection confidence (raise to0.6–0.7on noisy camera traps).--max-instances 3— maximum faces kept per image (increase for large social groups).--save-viz— save overlay previews so you can spot-check quality before opening an editor.--gpus 0 1 --jobs-per-gpu 2— split long video folders across multiple GPUs.
Part 2: Choosing Diverse Frames to Label (DINOv2)¶
Suppose your field camera recorded 5,000 video frames, but you only have time to hand-check 300. If you sample every N-th frame, you will waste hours labeling near-identical resting poses while missing rare yawns, threats, or lighting angles.
Our DINOv2 CLI (dinov2/dinov2_cli.py) converts each image into a visual "fingerprint" (embedding—a compact list of numbers summarizing face shape, pose, and background) using Meta's self-supervised DINOv2 model, then groups similar frames and picks maximally diverse examples to annotate.

When DINOv2 selection helps most (empirical guidance)
In our active-learning benchmark (Supplementary Fig. 2b), DINOv2-guided selection gives its clearest accuracy gain at small annotation budgets (~500 images, detection AP 0.401 → 0.425), where AP (Average Precision) measures how reliably the model finds faces without false alarms. At larger dataset sizes, prioritize sampling distinct individuals, lighting conditions, camera angles, and taxa rather than relying solely on feature-guided sampling.
Install, Extract Embeddings, and Select Frames¶
uv pip install -e ".[dinov2]"
# 1. Extract visual embeddings for every image in ./frames/
python -m dinov2.dinov2_cli extract \
--input ./frames/ \
--output ./embeddings.pt
# 2. Pick 300 maximally diverse frames (hybrid clustering + farthest-point sampling)
python -m dinov2.dinov2_cli select \
--embeddings ./embeddings.pt \
--n 300 \
--strategy hybrid \
--output ./selected_300.txt
Expected output:
selected_300.txt lists the chosen image paths—copy those frames into a folder, run Part 1 (gui.pseudolabel) to generate draft landmarks, review them, and fine-tune your preferred framework in Cross-Platform Frameworks.
Technical details: optional UMAP visual exploration
To inspect how your dataset clusters by species, individual, or lighting before selecting frames, generate a 2D UMAP map (a scatter plot where visually similar faces sit near each other):
Next Steps¶
- Fine-tune MMPose, DeepLabCut, Lightning Pose, or SLEAP on your newly labeled COCO JSON: Cross-Platform Frameworks.
- Inspect dataset composition and taxonomic coverage: Dataset Reference.