This repository provides a workflow for camera trap–based distance sampling that integrates segmentation and monocular depth estimation to localise, track, and estimate animal-to-camera distances for a specified target species. The framework combines the wildlife-adapted SAM-3 (SA-FARI) with Depth Anything 3 to generate frame-level detections, segmentation masks, object tracks, and depth-derived distance signals from camera trap video.
- SAM-3 (SA-FARI) for wildlife-specific segmentation/tracking: https://arxiv.org/abs/2511.15622
- Depth Anything 3 for monocular depth estimation: https://depth-anything-3.github.io/assets/da3_tech_report_2025.pdf
conda create -n dap-3_py3-11 "python>=3.7,<3.11"
conda activate dap-3_py3-11
pip install torch>=2 torchvision --index-url https://download.pytorch.org/whl/cu126
pip install xformers
git clone https://github.com/obrookes/Unmarked-Anything
cd Unmarked-Anything
pip install -e .
pip install gsplat
pip install ultralyticsFor AArch/ARM HPC environments where pycolmap is unavailable, keep pycolmap disabled in pyproject.toml (currently commented out).
For the same environment, pycolmap import is also commented in src/depth_anything_3/utils/export/colmap.py, so COLMAP export paths that depend on pycolmap are disabled.
Container assets:
- Definition:
envs/containers/depth-anything-3.def - Local image:
envs/containers/dap3-ultralytics.sif(git-ignored)
Build image (if needed):
singularity build envs/containers/dap3-ultralytics.sif envs/containers/depth-anything-3.defRun CLI in container:
singularity exec --nv envs/containers/dap3-ultralytics.sif \
python apps/camera_trap/cli/dap3_cli.py \
--input-video-dir assets/videos \
--output-dir outputs/demo \
--sam3-model-path weights/sam3/safari_checkpoint_hf.pt \
--sam3-text-prompts animalUse --nv when you need GPU support in the container.
Store large local model files here (all git-ignored):
weights/sam3/for SAM3 checkpointsweights/dap3/for DA3 checkpoints/artifacts
Current SAM3 checkpoint example:
weights/sam3/safari_checkpoint_hf.pt
Canonical CLI:
python apps/camera_trap/cli/dap3_cli.py \
--input-video-dir assets/videos \
--output-dir outputs/demo \
--sam3-model-path weights/sam3/safari_checkpoint_hf.pt \
--sam3-text-prompts animalLegacy wrapper also works: python dap3_cli.py ...
- Input video:
assets/videos/03290392_0_10.MP4 - Suggested output directory:
outputs/demo/ - Visualization notebook:
notebooks/camera_trap/visualize_test_output.ipynb(configured forassets/videosandoutputs/demo; includes a DAP3-style selected-frame analysis cell with manual/auto frame selection, depth-map mask contour overlay, bbox/center annotations, and mask-vs-bbox depth statistics/distributions)
- For SLURM/HPC job structure, batch scripts, manifests, and helper utilities, see:
hpc/README.md
python apps/camera_trap/cli/dap3_cli.py \
--input-video-dir /data/camera_trap/videos \
--output-dir /data/camera_trap/results \
--sam3-model-path weights/sam3/safari_checkpoint_hf.pt \
--sam3-text-prompts animal deer boar \
--da3-model-id depth-anything/DA3NESTED-GIANT-LARGE \
--target-fps 1.0 \
--sam3-mode track \
--conf 0.25 \
--device auto| Option | Type | Required | Default | Description |
|---|---|---|---|---|
--input-video-dir |
path | yes | - | Directory containing videos to process. |
--output-dir |
path | yes | - | Output root for run manifest and per-video results. |
--video-exts |
string | no | .mp4,.mov,.avi,.mkv |
Comma-separated extensions (with or without leading .). |
--sam3-model-path |
path | yes | - | Path to SAM3 checkpoint (.pt). |
--sam3-text-prompts |
list of strings | yes | - | One or more global SAM3 text prompts. |
--da3-model-id |
string | no | depth-anything/DA3NESTED-GIANT-LARGE |
DA3 pretrained model ID. |
--target-fps |
float | no | 1.0 |
Sampling rate for processing. Must be > 0. |
--sam3-mode |
enum | no | track |
track (video tracking) or frame (per-frame segmentation). |
--conf |
float | no | 0.25 |
SAM3 confidence threshold. |
--device |
enum | no | auto |
auto, cuda, or cpu. |
--half |
flag | no | false |
Enable FP16 for SAM3 (CUDA only). |
--overwrite |
flag | no | false |
Reprocess even if output JSON + NPZ already exist. |
--max-videos |
int | no | None |
Cap number of videos after sorting. Must be > 0 if provided. |
Given --output-dir ./out, outputs are:
./out/run_manifest.json./out/<video_stem>/<video_stem>.json./out/<video_stem>/<video_stem>_arrays.npz
Per-frame status values include: processed, empty_mask, sam_error, da3_error, frame_decode_error.
target_fpsis implemented as frame stride (round(video_fps / target_fps), minimum 1).- Non-overwrite mode skips videos that already have both expected output files.
- If
--sam3-mode trackis unavailable in your ultralytics build, use--sam3-mode frame.
- Camera trap CLI source:
apps/camera_trap/cli/dap3_cli.py - Archive index:
archive/INDEX.md - Archived upstream README:
archive/2026-03/readmes/README.upstream.md