ONNX checkpoint of
Intel ISL's MiDaS v2.1 small — 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.
Credit: Intel Intelligent Systems Lab (MiDaS team — Ranftl, Lasinger, Hafner, Schindler, Koltun).
A single ONNX file. No tokenizer, no preprocessor config — preprocessing is fixed by the architecture convention.
1import onnxruntime as ort
2import numpy as np
3from PIL import Image
4
5sess = ort.InferenceSession("midas_v21_small_256.onnx")
6
7# Resize, BGR (note: PIL is RGB by default — swap channels for MiDaS-small)
8img = Image.open("photo.jpg").convert("RGB").resize((256, 256))
9arr = np.asarray(img, dtype=np.float32) / 255.0
10arr = arr[..., ::-1] # RGB -> BGR
11arr = (arr - [0.485, 0.456, 0.406]) / [0.229, 0.224, 0.225] # ImageNet normalize
12arr = arr.transpose(2, 0, 1)[None, ...].copy().astype(np.float32) # NCHW
13
14depth = 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.
For sharper boundaries and higher absolute quality (at ~16× the disk + GPU latency), reach for dpt-large instead — same model family, same upstream lab.