Depth Pro 2 L ONNX: dynamic resolution, five precisions
ONNX export of apple/DepthPro2-L, Apple's 334 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 1339 MB down to 360 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 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
Deviation from the PyTorch fp32 model 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.
| File | Precision | Disk | AbsRel_inv | delta1 | Edge F1 |
|---|---|---|---|---|---|
onnx/model.onnx |
FP32 | 1339 MB | 0 | 1.0000 | 1.0000 |
onnx/model_fp16.onnx |
FP16 weights, FP32 compute | 674 MB | 0.0001 | 1.0000 | 0.9997 |
onnx/model_bf16.onnx |
BF16 weights, FP32 compute | 674 MB | 0.0014 | 1.0000 | 0.9942 |
onnx/model_int8.onnx |
INT8 group-32 | 420 MB | 0.0019 | 0.9998 | 0.9966 |
onnx/model_w4mixed.onnx |
GPTQ 4-bit, sensitive layers 8-bit | 360 MB | 0.0108 | 0.9963 | 0.9905 |
onnx/model_clip4_int8.onnx |
INT8 group-32, 4-frame window | 420 MB | 0.0013* | β | β |
* 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 quantized files carry the exact codes produced by the PyTorch quantizer, not a second re-quantization. Pooled parity with the source graph is 0.0001 (fp16), 0.0014 (bf16), 0.0027 (int8) and 0.0103 (4-bit) on 12 NYU images. 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.0006 and the 4-bit recipe by β0.0005 compared with fp32 (0.0714). No KITTI data was used to fit any quantizer.
- Video. On 96 frames of TUM RGB-D, the quantized weights change frame-to-frame flicker by 0.99β1.02x relative to fp32.
Files
| File | Input | Frames | Precision | Disk | Use when |
|---|---|---|---|---|---|
onnx/model_int8.onnx |
dynamic | 1 | INT8 group-32 | 420 MB | default choice: 0.19 % error at 31 % of fp32 size |
onnx/model_w4mixed.onnx |
dynamic | 1 | 4-bit GPTQ + 8-bit exceptions | 360 MB | disk is the binding constraint |
onnx/model.onnx |
dynamic | 1 | FP32 | 1339 MB | exact reference output |
onnx/model_fp16.onnx |
dynamic | 1 | FP16 weights | 674 MB | half-size weights, near-exact |
onnx/model_bf16.onnx |
dynamic | 1 | BF16 weights | 674 MB | half-size weights, wider numeric range |
onnx/model_clip4_int8.onnx |
dynamic | 4 | INT8 group-32 | 420 MB | temporally consistent video |
onnx/model_focal.onnx |
480x640 | 1 | FP32 | 96 MB | focal length from the image |
onnx/model_focal_fp16.onnx |
480x640 | 1 | FP16 weights | 49 MB | recommended focal graph |
onnx/model_focal_int8.onnx |
480x640 | 1 | INT8 group-32, FP32 head | 34 MB | focal graph, size-critical |
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-L-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-L-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.13 % vs 0.19 %) 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. 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 |
96 MB | 0 (reference) | 0 |
onnx/model_focal_fp16.onnx |
49 MB | 0.02 % | 0.18 % |
onnx/model_focal_int8.onnx |
34 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.
| Input | PyTorch fp32, 1080 Ti | Peak VRAM | INT8 AbsRel_inv | INT8 Edge F1 |
|---|---|---|---|---|
| 480x640 | 0.22 s | 1.54 GB | 0.0019 | 0.9966 |
| 736x1280 | 0.89 s | 2.11 GB | β | β |
| 1088x1920 | 2.78 s | 3.15 GB | 0.0027 | 0.9929 |
Accuracy does not improve with resolution, and quantization error does not hide there either. 4K is possible in principle and impractical in memory: Apple reports 82.6 GB at 4K for the fp32 model.
Performance
Measured at 480x640, one frame at a time, host array to host array. CPU is ONNX Runtime 1.32 on 16 threads; GPU is ONNX Runtime 1.22 CUDA 12 on a GTX 1080 Ti (11 GB, compute capability 6.1).
| File | ORT CPU | ORT CUDA | Peak host RAM, default | Peak host RAM, ORT_DISABLE_ALL |
|---|---|---|---|---|
model.onnx |
3.3 s | 0.30 s | 3.2 GB | β |
model_fp16.onnx |
3.0 s | 0.30 s | 3.8 GB | β |
model_bf16.onnx |
3.7 s | 0.29 s | 3.8 GB | β |
model_int8.onnx |
3.4 s | 0.30 s | 8.7 GB | 2.1 GB |
model_w4mixed.onnx |
2.6 s | 0.31 s | 10.5 GB | 2.3 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 4x less peak RAM for int8 and 4.5x for 4-bit, at 10β100 % more CPU time. fp32 and the half-precision files have nothing to fold and are unaffected.
The CUDA EP is about 12x the CPU time. At 1088x1920 ONNX Runtime materialises a 4.3 GB softmax buffer and does not fit on an 11 GB card; stay at 720p or below on such hardware.
Why fp16 is weights-only
A full fp16 forward pass returns NaN for this architecture. In every encoder block one 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 0.14 % instead of 0.01 % 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 96 linear layers, keeping attn.qkv, mlp.fc2 and every convolution at 8 bits. RTN at 4 bits scores 4.2 %, 4-bit convolutions collapse Edge F1 from 0.99 to 0.83, 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 256 NYUv2 training images at 480x640; GPTQ Hessians used 128 of them. 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. - 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-L, revision849dc5461267e0bc006ec63ab46920ea1ed98702, 333 958 465 parameters. - Architecture:
apple-aiml-research/ml-depth-pro-2, commitaa389cb. - 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
- 121
Model tree for Petrouil/DepthPro2-L-ONNX
Base model
apple/DepthPro2-L