This ONNX-based DepthPro model generates high-quality depth maps with minimal overhead. Depth values are encoded such that near points are bright and far points are dark, making the output directly usable for stereo and disparity-based applications without additional inversion or preprocessing. The model is optimized for efficient inference on standard hardware.
1import cv2
2import numpy as np
3import onnxruntime as ort
4
5# Load model
6session = ort.InferenceSession('depthpro_1536x1536_bs1_fp16_opset21_optimized.onnx', providers=['DmlExecutionProvider', 'CPUExecutionProvider'])
7input_name, output_name = session.get_inputs()[0].name, session.get_outputs()[0].name
8
9# Load & preprocess
10img = cv2.cvtColor(cv2.imread('examples/sample1/source.jpg'), cv2.COLOR_BGR2RGB)
11img = cv2.resize(img, (1536, 1536))
12img = np.transpose(((img.astype(np.float32)/127.5)-1.0).astype(np.float16), (2,0,1))[np.newaxis]
13
14# Inference
15depth = session.run([output_name], {input_name: img})[0].squeeze().astype(np.float32)
16
17# Clip extreme values and normalize
18depth = np.clip(np.nan_to_num(depth, nan=0.0), -1e3, 1e3)
19depth_norm = (depth - depth.min()) / max(depth.max() - depth.min(), 1e-6)
20
21# Save 8-bit PNG for smaller size
22cv2.imwrite('depth_frame_0001.png', (depth_norm * 255).round().astype(np.uint8))
23
24# Save 16-bit TIFF for higher precision
25cv2.imwrite('depth_frame_0001.tif', (depth_norm * 65535).round().astype(np.uint16), [cv2.IMWRITE_TIFF_COMPRESSION, cv2.IMWRITE_TIFF_COMPRESSION_DEFLATE])
26
27print(f'Depth maps saved')
Benchmarked on an AMD Radeon RX 7900 XTX using ONNX Runtime v1.23.0 with DirectML.
DepthPro's post-processing step calibrates depth values using field-of-view information and normalizes the output. This can cause severe artifacts:
The models below use post-processing and may exhibit these issues depending on the scene:
This ONNX version of DepthPro is licensed under the Apple Machine Learning Research Model License.