Skip to content

obrookes/Unmarked-Anything

Repository files navigation

Unmarked Anything

Segment and Depth Anything 3 for Camera Trap Distance Sampling

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.

Core Technologies

Installation

Conda (recommended)

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 ultralytics

For 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.

Singularity Container

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.def

Run 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 animal

Use --nv when you need GPU support in the container.

Model Files

Store large local model files here (all git-ignored):

  • weights/sam3/ for SAM3 checkpoints
  • weights/dap3/ for DA3 checkpoints/artifacts

Current SAM3 checkpoint example:

  • weights/sam3/safari_checkpoint_hf.pt

Quick Start

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 animal

Legacy wrapper also works: python dap3_cli.py ...

Sample Data

  • Input video: assets/videos/03290392_0_10.MP4
  • Suggested output directory: outputs/demo/
  • Visualization notebook: notebooks/camera_trap/visualize_test_output.ipynb (configured for assets/videos and outputs/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)

HPC Execution

  • For SLURM/HPC job structure, batch scripts, manifests, and helper utilities, see: hpc/README.md

Full Command Template

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

CLI Options (All)

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.

Output Structure

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.

Notes

  • target_fps is 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 track is unavailable in your ultralytics build, use --sam3-mode frame.

Additional References

About

Segment and Depth Anything 3 for Camera Trap Distance Sampling

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors