MiDaS v2.1 Small (256x256) for OpenCV dnn

An ONNX copy of MiDaS v2.1 Small (Intel ISL) that loads with cv2.dnn.readNet in OpenCV 4.x, including OpenCV in Pyodide.

The original export (julienkay/sentis-MiDaS, onnx/midas_v21_small_256.onnx) computes its "same" padding from Shape ops at runtime, which OpenCV's ONNX importer rejects. This version:

  1. was constant-folded with ONNX Runtime (ORT_ENABLE_BASIC), which merges that padding into the Conv nodes, leaving only Conv, Clip, Relu, Add, Sub, Div, Resize and Squeeze;
  2. has its weights stored as float16 (onnxconverter-common, keep_io_types=True), so inputs and outputs stay float32. The file is 33 MB instead of 66 MB.

Input and output

  • Input input_image: float32 [1, 3, 256, 256], RGB, values 0 to 1. ImageNet mean/std normalisation is part of the graph, so don't normalise again.
  • Output output_depth: float32 [1, 256, 256], relative inverse depth (bigger means closer). Not in meters.
import cv2
net = cv2.dnn.readNet("onnx/model.onnx")
blob = cv2.dnn.blobFromImage(bgr_image, 1 / 255, (256, 256), swapRB=True)
net.setInput(blob)
depth = net.forward()[0]
depth = (depth - depth.min()) / (depth.max() - depth.min())  # 0 = far, 1 = near

Licence and citation

MIT, as the original MiDaS release.

@article{Ranftl2022,
  author  = {Ren\'{e} Ranftl and Katrin Lasinger and David Hafner and Konrad Schindler and Vladlen Koltun},
  title   = {Towards Robust Monocular Depth Estimation: Mixing Datasets for Zero-Shot Cross-Dataset Transfer},
  journal = {IEEE Transactions on Pattern Analysis and Machine Intelligence},
  year    = {2022},
  volume  = {44},
  number  = {3}
}
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support