Depth Pro 2 H ONNX: dynamic resolution, five precisions
ONNX export of apple/DepthPro2-H, Apple's 872 M-parameter metric monocular depth model. One RGB image plus its focal length gives depth in metres.
Three properties distinguish this release:
- Dynamic height and width. A single file runs 480x640, 736x1280 and 1088x1920 without re-export. Sides must be multiples of 32.
- Five weight precisions. fp32, fp16, bf16, group-32 int8 and a mixed 4-bit GPTQ graph, from 3.7 GB down to 839 MB.
- Companion graphs. A 4-frame clip model for temporally consistent video, and a focal-length estimator for images without EXIF.
Every graph passes a parity gate against the PyTorch model it was built from. Accuracy is measured on 300 NYUv2 images, 150 KITTI LiDAR frames and 96 frames of TUM RGB-D; methodology, rejected recipes and ablations are in BENCHMARKS.md.
Research use only. These weights are a Model Derivative under the Apple Machine Learning Research Model License: non-commercial research and academic use only. This port is independent and is not endorsed by Apple.
Measured accuracy
Fidelity of the weight recipes on the same 300 NYUv2 validation images at 480x640. The focal length is fitted once on fp32 (f_px = 484.20) and frozen for every candidate. The primary metric is weighted absolute relative error on inverse depth, Ξ£|1/dΜ β 1/d| / Ξ£(1/d), which stays bounded at the sky where depth diverges.
| recipe | AbsRel_inv | delta1 | Edge F1 | verdict |
|---|---|---|---|---|
| fp32 | 0 | 1.0000 | 1.0000 | reference |
| INT8 group-32 | 0.0014 | 1.0000 | 0.9952 | shipped default |
| GPTQ 4-bit, sensitive layers 8-bit | 0.0091 | 0.9989 | 0.9924 | shipped size option |
| GPTQ 4-bit, no exceptions | 0.0201 | 0.9977 | 0.9907 | rejected, fails the 1 % gate |
Parity of the published ONNX graphs against PyTorch fp32, measured on 8 NYU images (focal error is measured separately on the focal graphs):
| File | ONNX vs PyTorch fp32, AbsRel_inv |
|---|---|
model.onnx |
3.4e-7 |
model_fp16.onnx |
6.5e-5 |
model_bf16.onnx |
3.9e-4 |
model_int8.onnx |
0.0012 |
model_w4mixed.onnx |
0.0076 |
model_clip4_int8.onnx |
0.0012* |
* Against the same model in fp32 clip mode. Clip mode changes the output by 2β5 % relative to independent single frames, so the two references are not interchangeable.
The H checkpoints beat their L counterparts on every recipe: W8 0.0014 vs 0.0019, W4-mixed 0.0091 vs 0.0108, int8 ONNX parity 0.0012 vs 0.0027. Two independent transfers confirm the ranking:
- Outdoor. On 150 KITTI depth-completion images (352x1216, real LiDAR), int8 changes absolute AbsRel against ground truth by +0.0003 and the 4-bit recipe by +0.0007 compared with fp32 (0.0579). No KITTI data was used to fit any quantizer.
- Video. On 96 frames of TUM RGB-D, int8 leaves frame-to-frame flicker unchanged in both single-frame and 4-frame modes. The 4-bit recipe raises independent-frame flicker by 11 % but is clean in the 4-frame KV path β see below.
Files
| File | Input | Frames | Precision | Disk | Use when |
|---|---|---|---|---|---|
onnx/model_int8.onnx |
dynamic | 1 | INT8 group-32 | 1067 MB | default choice: 0.14 % error at 29 % of fp32 size |
onnx/model_w4mixed.onnx |
dynamic | 1 | 4-bit GPTQ + 8-bit exceptions | 839 MB | disk is the binding constraint |
onnx/model.onnx |
dynamic | 1 | FP32 | 4.4 MB + 3.3 GB .data |
exact reference output |
onnx/model_fp16.onnx |
dynamic | 1 | FP16 weights | 1752 MB | half-size weights, near-exact |
onnx/model_bf16.onnx |
dynamic | 1 | BF16 weights | 1752 MB | half-size weights, wider numeric range |
onnx/model_clip4_int8.onnx |
dynamic | 4 | INT8 group-32 | 1067 MB | temporally consistent video |
onnx/model_focal.onnx |
480x640 | 1 | FP32 | 92 MB | focal length from the image |
onnx/model_focal_fp16.onnx |
480x640 | 1 | FP16 weights | 47 MB | recommended focal graph |
onnx/model_focal_int8.onnx |
480x640 | 1 | INT8 group-32, FP32 head | 33 MB | focal graph, size-critical |
model.onnx is exported with ONNX external data: onnx/model.onnx.data must be downloaded and kept beside it. The other graphs are self-contained. Downloads from the Hub keep the pair together automatically.
Quick start
pip install onnxruntime huggingface_hub pillow numpy # onnxruntime-gpu for CUDA
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
repo = "Petrouil/DepthPro2-H-ONNX"
providers = ["CUDAExecutionProvider", "CPUExecutionProvider"]
session = ort.InferenceSession(hf_hub_download(repo, "onnx/model_int8.onnx"),
providers=providers)
# pixels: RGB in [0, 1], NCHW. f_px: focal length of that image in pixels.
pixels = image_rgb.astype(np.float32) / 255.0
pixels = np.ascontiguousarray(pixels.transpose(2, 0, 1)[None])
inverse_depth, depth_meters = session.run(
None, {"pixel_values": pixels, "f_px": np.array([f_px], np.float32)})
example.py resizes any photo to a multiple of 32, reads the EXIF focal length, scales f_px with the crop and writes a colourised depth map:
python example.py photo.jpg --model onnx/model_int8.onnx --out depth.png
python example.py photo.jpg --model Petrouil/DepthPro2-H-ONNX:onnx/model_w4mixed.onnx
Inputs and outputs
| Name | Direction | Type and shape | Meaning |
|---|---|---|---|
pixel_values |
input | float32 (1, 3, H, W) or (4, 3, H, W) |
RGB in [0, 1], not normalised; ImageNet normalisation is inside the graph |
f_px |
input | float32 (1,) |
horizontal focal length of the image as passed in, in pixels |
inverse_depth |
output | float32 (1, H, W) or (4, H, W) |
focal-normalised inverse depth, 0 at infinite distance |
depth_meters |
output | float32 (1, H, W) or (4, H, W) |
f_px / (W Β· inverse_depth) in metres, inf at the sky |
H and W are free but must be multiples of 32. If you resize the image, scale f_px by the same factor; a wrong focal length scales the entire depth map linearly. The clip graph takes T = 4 frames and returns T maps.
Video and focal-length companion graphs
model_clip4_int8.onnx runs four frames jointly. Its encoder's cross-frame blocks let the frames attend to each other, which is what makes a depth video temporally stable.
- Output is not the same as four independent single-frame calls: on real TUM frames the two differ by 2β5 % in absolute scale, by design. Do not mix the two in one pipeline.
- Quantization error is lower than single-frame int8 (0.12 % vs 0.14 % on the weight recipes) because each frame sees more context.
- The graph is stateless and costs about 4x a single frame. For longer videos, run successive 4-frame windows or keep the KV cache in your own runtime.
model_focal.onnx estimates focal length when EXIF is absent. Resize the photo to 480x640, run the graph, then multiply f_px by real_width / 640. It is a DINOv3 ViT-S/16 (23.5 M parameters) built from Apple's apple/DepthPro2-focal weights, independent of the depth checkpoint size, so the same three graphs are published here as in DepthPro2-L-ONNX. On NYU val it lands about 2.5 % above the focal fitted on fp32 ground truth; it assumes a 4:3-ish framing, and extreme aspect ratios bias the estimate.
The focal graph has a single scalar output, so weight rounding does not average out over pixels as it does in depth maps. The error below is in f_px itself and propagates 1:1 into metric depth.
| File | Disk | Mean error in f_px | Max error |
|---|---|---|---|
onnx/model_focal.onnx |
92 MB | 0 (reference) | 0 |
onnx/model_focal_fp16.onnx |
47 MB | 0.02 % | 0.18 % |
onnx/model_focal_int8.onnx |
33 MB | 0.28 % | 1.4 % |
The int8 focal graph keeps the small FOV head in fp32; a fully int8 graph costs 0.36 % mean and 2.0 % worst case for 5 MB less. Measured on 50 NYU images against the fp32 graph.
Resolution behaviour
Attention cost grows quadratically with token count, so resolution is a memory decision. The dynamic axes were exercised at all three geometries from one file. Timings are PyTorch fp32 GPU forward passes on the 1080 Ti; peak VRAM includes the 3.49 GB of weights.
| Input | PyTorch fp32, 1080 Ti | Peak VRAM | ONNX int8 parity | CPU time, int8 ONNX |
|---|---|---|---|---|
| 480x640 | 0.59 s | 3.64 GB | 0.0012 | 5.9 s |
| 736x1280 | 2.33 s | 4.22 GB | β | β |
| 1088x1920 | 6.83 s | 5.27 GB | 0.0022 | 123 s |
At 1088x1920 the CUDA execution provider cannot fit this model on an 11 GB card: it requests a 5.33 GB single buffer and fails. Stay at 720p or below for GPU inference. CPU inference at HD works but takes about two minutes per frame.
Performance
Measured at 480x640, one frame at a time, host array to host array. GPU is ONNX Runtime 1.22 CUDA 12 on a GTX 1080 Ti (11 GB, compute capability 6.1); CPU is ONNX Runtime with 16 threads.
| File | ORT CPU, default | ORT CUDA, 480x640 | ORT CUDA, 736x1280 | Peak host RAM, default | Peak host RAM, ORT_DISABLE_ALL |
|---|---|---|---|---|---|
model.onnx |
β | 0.53 s | 2.34 s | β | β |
model_fp16.onnx |
β | 0.54 s | 2.44 s | β | β |
model_bf16.onnx |
β | 0.55 s | 2.34 s | β | β |
model_int8.onnx |
5.89 s | 0.57 s | 2.32 s | 21.2 GB | 2.5 GB |
model_w4mixed.onnx |
6.08 s | 0.53 s | 2.41 s | 24.1 GB | 4.0 GB |
The default optimizer constant-folds the in-graph dequantization into fp32 weight copies, so the quantized graphs trade disk for more RAM. For the lower figures, build the session with folding disabled:
so = ort.SessionOptions()
so.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
session = ort.InferenceSession("onnx/model_int8.onnx", so, providers=["CPUExecutionProvider"])
That is 8x less peak RAM for int8 and 6x for 4-bit, at 11β45 % more CPU time (6.54 s and 8.8 s per frame respectively). fp32 and the half-precision files have nothing to fold and are unaffected.
The CUDA EP is about 10x faster than CPU on this card at VGA.
Why fp16 is weights-only
A full fp16 forward pass overflows on this architecture. In the DINOv3 encoder a prefix token reaches a magnitude of about 1.3e5, above the fp16 maximum of 65 504; casting it to fp16 gives inf, which the next attention and softmax turn into NaN. Clamping the token to the fp16 range in fp32 already changes the final depth by 10 %, so the value cannot be discarded.
model_fp16.onnx therefore stores weights rounded to fp16 and casts back to fp32 before use, halving the file while keeping arithmetic in fp32. model_bf16.onnx applies the same trick with bf16, whose 8-bit exponent covers 1.3e5; it costs a little more numerically but has a much wider range if your runtime supports bf16.
How the graphs were made
INT8 is symmetric group-32 weight quantization: one scale per 32 weights, dequantized in-graph by Cast and Mul before every MatMul, Conv and ConvTranspose. Activations stay fp32. The simple grid is why it transfers across domains.
4-bit uses GPTQ with group size 32 and damping 0.1 on the linear layers, keeping attn.qkv, mlp.fc2 and every convolution at 8 bits. Pure 4-bit scores 2.01 % on NYU, 4-bit convolutions destroy edge detail on L, and qkv is the weight matrix that suffers most at 4 bits. The graph stores packed nibbles and unpacks them with standard ONNX operators (BitShift, Sub, Cast, Reshape, Mul) before a normal fp32 MatMul. This avoids com.microsoft.MatMulNBits, so the file runs on any ONNX Runtime build and any hardware.
Calibration used 128 NYUv2 training images at 480x640 for the GPTQ Hessians, accumulated in host memory (~4 GB) because 3.49 GB of weights plus 4 GB of Hessians do not fit beside the desktop on an 11 GB card. KITTI, COCO and TUM were used only for evaluation.
Changes from the original
- Dynamic height and width instead of fixed 480x640; sides must be multiples of 32.
- ImageNet normalisation and
depth = f_px / (W Β· inverse_depth)are inside the graph. - The fp32 graph is exported with ONNX external data; keep
model.onnx.databesidemodel.onnx. - FP16 stores weights only; full fp16 compute is numerically impossible (see above).
- INT8 is weight-only. Dynamic activation INT8 collapses this backbone.
- A focal-length estimator is included as a separate graph; the depth graphs take
f_pxas an input. - A 4-frame clip graph is included; the PyTorch KV-cache streaming API has no exported counterpart here.
Provenance and licence
- Base weights:
apple/DepthPro2-H, revision68426c789f75a7c760273e857222625b4fe69576, 872 108 865 parameters. - Architecture:
apple-aiml-research/ml-depth-pro-2. - Export: PyTorch 2.14.1, ONNX opset 18.
- Licence: Apple Machine Learning Research Model License. Research and non-commercial use only.
Ablation tables, rejected recipes and the full evaluation protocol are in BENCHMARKS.md.
Citation
@article{hu2026depthpro2,
title = {Depth Pro 2: Sharp and Temporally Consistent Metric Monocular Depth},
author = {Hu, Peiyun and Mihajlovic, Marko and Duong, Lyndon and Lipson, Lahav and
Dong, Wei and Delaunoy, Ama{\"e}l and Richter, Stephan R. and Koltun, Vladlen},
journal = {arXiv preprint arXiv:2611.26603},
year = {2026}
}
- Downloads last month
- 51
Model tree for Petrouil/DepthPro2-H-ONNX
Base model
apple/DepthPro2-H