ONNX-compatible implementation of Depth Anything 3 for efficient depth estimation inference.
This repository provides scripts to export Depth Anything 3 models to ONNX format and run inference using ONNXRuntime, enabling deployment on a wide range of platforms with minimal dependencies.
ONNX models provide significant performance benefits:
depth-anything/DA3-SMALL| Resolution | Model Size | Mean Time | Std Dev | Min | Max | Median | P95 | P99 | FPS |
|---|---|---|---|---|---|---|---|---|---|
| 224x224 | 96.1 MB | 92.44ms | 2.28ms | 88.89ms | 96.30ms | 92.49ms | 96.11ms | 96.26ms | 10.82 |
| 392x392 | 96.1 MB | 279.67ms | 8.04ms | 271.08ms | 298.78ms | 278.13ms | 298.48ms | 298.72ms | 3.58 |
| 504x504 | 96.1 MB | 506.84ms | 14.97ms | 490.04ms | 545.88ms | 504.01ms | 541.25ms | 544.95ms | 1.97 |
| 672x672 | 96.1 MB | 1101.54ms | 15.72ms | 1078.86ms | 1131.54ms | 1097.70ms | 1121.84ms | 1129.60ms | 0.91 |
| 840x840 | 96.1 MB | 2206.96ms | 63.76ms | 2115.01ms | 2365.68ms | 2209.16ms | 2298.87ms | 2352.32ms | 0.45 |
pip install -r requirements.txt
If you only need to run inference with pre-exported ONNX models:
pip install onnxruntime opencv-python pillow imageio numpy matplotlib
To export PyTorch models to ONNX, you'll need PyTorch:
pip install torch>=2.0.0 torchvision
pip install -r requirements.txt
Export a Depth Anything 3 model from HuggingFace to ONNX format:
python export_onnx.py \
--model depth-anything/DA3-SMALL \
--process-res 504 \
--output DA3-SMALL-504.onnx
By default the exported model supports dynamic batch, height, and width axes, and the script runs portable ONNX Runtime basic graph optimization.
Available Models:
depth-anything/DA3-SMALL (80M params)depth-anything/DA3-BASE (120M params)depth-anything/DA3-LARGE (350M params)Note: The first run will download the model from HuggingFace. Models are cached in ~/.cache/huggingface/.
For mobile converters that prefer a smaller fixed-shape graph, export a static model:
python export_onnx.py \
--model depth-anything/DA3-SMALL \
--process-res 504 \
--output DA3-SMALL-504-static.onnx \
--static
Run depth estimation on an image using the exported ONNX model:
python run_onnx.py \
--image assets/examples/input.jpg \
--onnx DA3-SMALL-504.onnx \
--process-res 504 \
--export-dir ./output \
--visualize
Arguments:
--image: Path to input image--onnx: Path to ONNX model file--process-res: Processing resolution (default: 504)--export-dir: Directory to save depth visualization--visualize: Display visualization with matplotlibimport cv2
import numpy as np
import onnxruntime as ort
from PIL import Image
# Load ONNX model
sess = ort.InferenceSession("DA3-SMALL-504.onnx")
# Load and preprocess image
image = cv2.imread("input.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (504, 504))
image = image.transpose(2, 0, 1).astype(np.float32) / 255.0
image = np.expand_dims(image, axis=0)
# Run inference
depth = sess.run(None, {"image": image})[0]
# Depth shape: (1, 1, 504, 504)
print(f"Depth map shape: {depth.shape}")
The export script creates ONNX models with:
image tensor of shape (batch, 3, height, width), dtype float32, range [0, 1]depth tensor of shape (batch, 1, height, width), dtype float32--static is used14). run_onnx.py handles this through preprocessing.--opset)python export_onnx.py --help
Key Parameters:
--model: HuggingFace model ID or local path--process-res: Fixed square resolution for export (e.g., 504, 672)--output: Output ONNX file path--opset: ONNX opset version (default: 17)--static: Export fixed batch/height/width axes for mobile-friendly conversion--optimize: ONNX Runtime graph optimization level: none, basic, extended, or all (default: basic)The inference script handles:
Dynamic ONNX exports can be used with different --process-res values at
inference time. Static exports must be run at the same resolution used during
export.
python run_onnx.py --help
import onnxruntime as ort
# For CUDA GPU
sess = ort.InferenceSession("model.onnx", providers=["CUDAExecutionProvider"])
# For CPU
sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
# For TensorRT (fastest on NVIDIA GPUs)
sess = ort.InferenceSession("model.onnx", providers=["TensorrtExecutionProvider"])
Depth-Anything-3-Onnx/
├── src/
│ └── depth_anything_3/ # Source code from Depth Anything 3
├── assets/
│ └── examples/ # Sample images
├── export_onnx.py # Export PyTorch to ONNX
├── run_onnx.py # Run inference with ONNX
├── requirements.txt # Python dependencies
├── LICENSE # Apache 2.0 License
└── README.md # This file
Make sure you're running scripts from the project root directory where the src/ folder is located.
If you experience network issues downloading from HuggingFace:
export HF_ENDPOINT=https://hf-mirror.com
Try using a smaller model (DA3-SMALL) or enabling optimizations:
sess_options = ort.SessionOptions()
sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
sess = ort.InferenceSession("model.onnx", sess_options=sess_options)
If you use Depth Anything 3 in your research, please cite:
@article{depthanything3,
title={Depth Anything 3: Recovering the visual space from any views},
author={Haotong Lin and Sili Chen and Jun Hao Liew and Donny Y. Chen and Zhenyu Li and Guang Shi and Jiashi Feng and Bingyi Kang},
journal={arXiv preprint arXiv:2511.10647},
year={2025}
}
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
The Depth Anything 3 models have varying licenses:
Please refer to the official Depth Anything 3 repository for model-specific license information.
Contributions are welcome! Please feel free to submit issues or pull requests.
ONNX-compatible implementation of Depth Anything 3 for efficient depth estimation inference.
This repository provides scripts to export Depth Anything 3 models to ONNX format and run inference using ONNXRuntime, enabling deployment on a wide range of platforms with minimal dependencies.
ONNX models provide significant performance benefits:
depth-anything/DA3-SMALL| Resolution | Model Size | Mean Time | Std Dev | Min | Max | Median | P95 | P99 | FPS |
|---|---|---|---|---|---|---|---|---|---|
| 224x224 | 96.1 MB | 92.44ms | 2.28ms | 88.89ms | 96.30ms | 92.49ms | 96.11ms | 96.26ms | 10.82 |
| 392x392 | 96.1 MB | 279.67ms | 8.04ms | 271.08ms | 298.78ms | 278.13ms | 298.48ms | 298.72ms | 3.58 |
| 504x504 | 96.1 MB | 506.84ms | 14.97ms | 490.04ms | 545.88ms | 504.01ms | 541.25ms | 544.95ms | 1.97 |
| 672x672 | 96.1 MB | 1101.54ms | 15.72ms | 1078.86ms | 1131.54ms | 1097.70ms | 1121.84ms | 1129.60ms | 0.91 |
| 840x840 | 96.1 MB | 2206.96ms | 63.76ms | 2115.01ms | 2365.68ms | 2209.16ms | 2298.87ms | 2352.32ms | 0.45 |
pip install -r requirements.txt
If you only need to run inference with pre-exported ONNX models:
pip install onnxruntime opencv-python pillow imageio numpy matplotlib
To export PyTorch models to ONNX, you'll need PyTorch:
pip install torch>=2.0.0 torchvision
pip install -r requirements.txt
Export a Depth Anything 3 model from HuggingFace to ONNX format:
python export_onnx.py \
--model depth-anything/DA3-SMALL \
--process-res 504 \
--output DA3-SMALL-504.onnx
By default the exported model supports dynamic batch, height, and width axes, and the script runs portable ONNX Runtime basic graph optimization.
Available Models:
depth-anything/DA3-SMALL (80M params)depth-anything/DA3-BASE (120M params)depth-anything/DA3-LARGE (350M params)Note: The first run will download the model from HuggingFace. Models are cached in ~/.cache/huggingface/.
For mobile converters that prefer a smaller fixed-shape graph, export a static model:
python export_onnx.py \
--model depth-anything/DA3-SMALL \
--process-res 504 \
--output DA3-SMALL-504-static.onnx \
--static
Run depth estimation on an image using the exported ONNX model:
python run_onnx.py \
--image assets/examples/input.jpg \
--onnx DA3-SMALL-504.onnx \
--process-res 504 \
--export-dir ./output \
--visualize
Arguments:
--image: Path to input image--onnx: Path to ONNX model file--process-res: Processing resolution (default: 504)--export-dir: Directory to save depth visualization--visualize: Display visualization with matplotlibimport cv2
import numpy as np
import onnxruntime as ort
from PIL import Image
# Load ONNX model
sess = ort.InferenceSession("DA3-SMALL-504.onnx")
# Load and preprocess image
image = cv2.imread("input.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (504, 504))
image = image.transpose(2, 0, 1).astype(np.float32) / 255.0
image = np.expand_dims(image, axis=0)
# Run inference
depth = sess.run(None, {"image": image})[0]
# Depth shape: (1, 1, 504, 504)
print(f"Depth map shape: {depth.shape}")
The export script creates ONNX models with:
image tensor of shape (batch, 3, height, width), dtype float32, range [0, 1]depth tensor of shape (batch, 1, height, width), dtype float32--static is used14). run_onnx.py handles this through preprocessing.--opset)python export_onnx.py --help
Key Parameters:
--model: HuggingFace model ID or local path--process-res: Fixed square resolution for export (e.g., 504, 672)--output: Output ONNX file path--opset: ONNX opset version (default: 17)--static: Export fixed batch/height/width axes for mobile-friendly conversion--optimize: ONNX Runtime graph optimization level: none, basic, extended, or all (default: basic)The inference script handles:
Dynamic ONNX exports can be used with different --process-res values at
inference time. Static exports must be run at the same resolution used during
export.
python run_onnx.py --help
import onnxruntime as ort
# For CUDA GPU
sess = ort.InferenceSession("model.onnx", providers=["CUDAExecutionProvider"])
# For CPU
sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
# For TensorRT (fastest on NVIDIA GPUs)
sess = ort.InferenceSession("model.onnx", providers=["TensorrtExecutionProvider"])
Depth-Anything-3-Onnx/
├── src/
│ └── depth_anything_3/ # Source code from Depth Anything 3
├── assets/
│ └── examples/ # Sample images
├── export_onnx.py # Export PyTorch to ONNX
├── run_onnx.py # Run inference with ONNX
├── requirements.txt # Python dependencies
├── LICENSE # Apache 2.0 License
└── README.md # This file
Make sure you're running scripts from the project root directory where the src/ folder is located.
If you experience network issues downloading from HuggingFace:
export HF_ENDPOINT=https://hf-mirror.com
Try using a smaller model (DA3-SMALL) or enabling optimizations:
sess_options = ort.SessionOptions()
sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_ALL
sess = ort.InferenceSession("model.onnx", sess_options=sess_options)
If you use Depth Anything 3 in your research, please cite:
@article{depthanything3,
title={Depth Anything 3: Recovering the visual space from any views},
author={Haotong Lin and Sili Chen and Jun Hao Liew and Donny Y. Chen and Zhenyu Li and Guang Shi and Jiashi Feng and Bingyi Kang},
journal={arXiv preprint arXiv:2511.10647},
year={2025}
}
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
The Depth Anything 3 models have varying licenses:
Please refer to the official Depth Anything 3 repository for model-specific license information.
Contributions are welcome! Please feel free to submit issues or pull requests.