Depth Anything V2 Small — ONNX
ONNX export of depth-anything/Depth-Anything-V2-Small-hf, a monocular depth estimation model. Predicts relative inverse depth from a single RGB image — larger values are closer to the camera.
Mirrored for use with inference4j, an inference-only AI library for Java.
Original Source
- Repository: Depth Anything (ONNX by onnx-community)
- License: apache-2.0
Usage with inference4j
try (DepthAnythingEstimator estimator = DepthAnythingEstimator.builder()
.modelId("inference4j/depth-anything-v2-small")
.build()) {
DepthMap depth = estimator.estimate(Path.of("photo.jpg"));
System.out.println("Depth at centre: " + depth.at(depth.width() / 2, depth.height() / 2));
}
Model Details
| Property | Value |
|---|---|
| Architecture | DINOv2 ViT-Small backbone + DPT decoder |
| Task | Monocular depth estimation |
| Parameters | ~25M |
| Input | [1, 3, height, width] — NCHW float32, RGB |
| Normalization | ImageNet mean [0.485, 0.456, 0.406], std [0.229, 0.224, 0.225] |
| Input sizing | 518 on the longer edge, aspect preserved, both dimensions rounded up to a multiple of 14 (ViT patch size), bicubic resampling |
| Output name | predicted_depth |
| Output | [1, height, width] — rank 3, no channel dimension |
| Output semantics | Relative inverse depth; larger is closer. Scale is per-image, not metric. |
| Original framework | PyTorch (HuggingFace Transformers) |
License
This model is licensed under the Apache 2.0 License. Original model by Depth Anything, ONNX export by onnx-community.
Preprocessing
- Resize so the longer edge is 518, preserving aspect ratio (bicubic)
- Round both dimensions up to a multiple of 14 (the ViT patch size)
- ImageNet normalization:
(pixel / 255 - mean) / std- mean =
[0.485, 0.456, 0.406] - std =
[0.229, 0.224, 0.225]
- mean =
- NCHW layout:
[1, 3, H, W]
Postprocessing
The output is relative inverse depth, so values are only comparable within a single image.
To render a depth map, normalize to [0, 1] against the per-image min and max, then resize
back to the original image dimensions.
Original Paper
Yang, L., Kang, B., Huang, Z., Zhao, Z., Xu, X., Feng, J., & Zhao, H. (2024). Depth Anything V2. NeurIPS 2024. arXiv:2406.09414