File size: 3,403 Bytes
2f457d3 4240d18 2f457d3 4240d18 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | ---
license: mit
library_name: onnx
tags:
- depth-estimation
- midas
- mobile
- edge
- onnx
base_model: isl-org/MiDaS
pipeline_tag: depth-estimation
language:
- en
---
# MiDaS v2.1 Small β Monocular Depth Estimation (ONNX)
ONNX checkpoint of [Intel ISL's MiDaS v2.1 small](https://github.com/isl-org/MiDaS) β an EfficientNet-Lite3 encoder paired with a lightweight depth decoder. ~21M params, 256Γ256 input, CPU-friendly. Sibling to DPT-Large but ~16Γ smaller and ~20Γ faster on CPU.
Not converted locally β this is the ONNX file isl-org publishes directly in the [v2_1 GitHub release](https://github.com/isl-org/MiDaS/releases/tag/v2_1).
Credit: Intel Intelligent Systems Lab (MiDaS team β Ranftl, Lasinger, Hafner, Schindler, Koltun).
## What this repo contains
```
midas_v21_small_256.onnx # ~80 MB β fp32, EfficientNet-Lite3 backbone, 256Γ256 input
```
A single ONNX file. No tokenizer, no preprocessor config β preprocessing is fixed by the architecture convention.
## Input / output
| | Spec |
|---|---|
| Input name | `input.1` (verify in Netron) |
| Input shape | `[1, 3, 256, 256]` (NCHW) |
| Input dtype | float32 |
| Input color order | **BGR** β note this differs from DPT-Large (which expects RGB) |
| Preprocessing | Resize to 256Γ256, scale to `[0,1]`, normalize with ImageNet stats: `mean=[0.485, 0.456, 0.406]`, `std=[0.229, 0.224, 0.225]` |
| Output shape | `[1, 256, 256]` |
| Output meaning | Single-channel **relative** depth (higher = closer, lower = farther). **Not metric.** Linearly map to your visualization range. |
## How to use
```python
import onnxruntime as ort
import numpy as np
from PIL import Image
sess = ort.InferenceSession("midas_v21_small_256.onnx")
# Resize, BGR (note: PIL is RGB by default β swap channels for MiDaS-small)
img = Image.open("photo.jpg").convert("RGB").resize((256, 256))
arr = np.asarray(img, dtype=np.float32) / 255.0
arr = arr[..., ::-1] # RGB -> BGR
arr = (arr - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225] # ImageNet normalize
arr = arr.transpose(2, 0, 1)[None, ...].copy().astype(np.float32) # NCHW
depth = sess.run(None, {sess.get_inputs()[0].name: arr})[0][0] # 256x256
```
For metric depth, pair with a calibration scheme β MiDaS is trained for relative depth and will not give you "this object is 1.7 m away" without further work.
## When to pick MiDaS-small
- **Real-time, edge, CPU, or mobile**: ~50 ms / image on consumer CPU, ~80 MB on disk.
- **Coarse depth is enough**: relative ordering of "what's close vs far" matters more than fine boundary precision.
- **Pair with DPT-Large**: a common pattern is to run MiDaS-small first for a quick estimate, then fall back to DPT-Large only when high-quality depth is needed for a specific frame.
For sharper boundaries and higher absolute quality (at ~16Γ the disk + GPU latency), reach for `dpt-large` instead β same model family, same upstream lab.
## License
**MIT** β same as the upstream [isl-org/MiDaS](https://github.com/isl-org/MiDaS) repo. `LICENSE` file included.
Note: a separate Intel-published variant of DPT-Large lives on HuggingFace at `Intel/dpt-large` under **Apache-2.0**. Same model family, different distribution channel, different licenses. The checkpoint in *this* repo (v2_1 GitHub release) inherits MIT from the upstream GitHub repo. |