depth-anything.cpp  by mudler

C++ inference engine for monocular depth and camera pose

Created 3 weeks ago

New!

257 stars

Top 98.3% on SourcePulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This project offers a highly optimized, from-scratch C++17/ggml port of ByteDance's Depth Anything 3 model, enabling dependency-free monocular metric depth and camera pose inference. It targets engineers and researchers seeking efficient, local AI inference without the overhead of Python, PyTorch, or CUDA, providing faster CPU performance and a self-contained, portable GGUF format.

How It Works

The core of depth-anything.cpp is a C++17 implementation leveraging the ggml library for efficient tensor operations. It utilizes a self-contained GGUF file format that embeds all model dimensions, hyperparameters, and preprocessing constants, eliminating the need for external configuration files or Python scripts during inference. This approach ensures a small, native library and CLI, with a strong emphasis on bit-exact parity to the original PyTorch model, verified component by component against reference tensors.

Quick Start & Requirements

  • Primary install / run command: Clone the repository (git clone --recursive), navigate into the directory, build with CMake (cmake -B build -DDA_BUILD_CLI=ON && cmake --build build -j), and run the CLI executable (build/examples/cli/da3-cli).
  • Non-default prerequisites and dependencies: C++17 compiler and CMake are required for building. Python is only needed for model conversion scripts. GPU acceleration (CUDA, Metal, Vulkan) requires corresponding SDKs and specific CMake flags (e.g., -DDA_GGML_CUDA=ON). No GPU is required for CPU inference.
  • Estimated setup time or resource footprint: Quantized models (e.g., q4_k) are approximately 99 MB. Inference is memory-efficient, using roughly half the RAM compared to PyTorch implementations.
  • Links: Official quick-start instructions are within the README. Further details on GPU usage, export formats, and verification are available in docs/GPU.md, docs/EXPORT.md, and docs/VERIFICATION.md respectively.

Highlighted Details

  • Performance: Significantly faster than PyTorch on CPU (1.20x at f32, 1.31x at q8_0) with ~6.7x faster model loading times and reduced memory footprint.
  • Comprehensive Output: Generates dense metric depth maps, per-pixel confidence scores, camera extrinsics (3x4) and intrinsics (3x3), optional sky masks, and back-projected 3D point clouds.
  • Model Support: Supports the full Depth Anything 3 family (ViT-S, ViT-B, ViT-L, ViT-g) and Depth Anything V2 models, all driven by metadata embedded within the GGUF files.
  • Embeddability: Features a flat C API (include/da_capi.h) for straightforward integration into C, C++, Go, and Rust applications.
  • Export Formats: Native, dependency-free exporters for glb (glTF 2.0), COLMAP, and PLY formats.

Maintenance & Community

This project is developed by the LocalAI team. Specific community channels (like Discord/Slack) or detailed roadmaps are not explicitly mentioned in the provided README.

Licensing & Compatibility

  • License type: The depth-anything.cpp library is released under the permissive MIT License.
  • Compatibility notes: The original Depth Anything 3 model weights are governed by their Apache-2.0 license. The MIT license permits commercial use and linking within closed-source applications.

Limitations & Caveats

Depth Anything V2 models, while supported, do not output confidence scores or camera pose information. The ViT-g (Giant) DA2 checkpoint is not included due to its gated/unreleased status in the original repository. While GPU backends are available, the project's primary performance advantages and detailed benchmarks focus on CPU execution.

Health Check
Last Commit

3 weeks ago

Responsiveness

Inactive

Pull Requests (30d)
2
Issues (30d)
0
Star History
257 stars in the last 27 days

Explore Similar Projects

Starred by Aravind Srinivas Aravind Srinivas(Cofounder of Perplexity), Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), and
13 more.

pytorch3d by facebookresearch

0.1%
10k
PyTorch3D is a PyTorch library for 3D deep learning research
Created 6 years ago
Updated 2 weeks ago
Feedback? Help us improve.