Instructions to use litert-community/MiDaS-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/MiDaS-small with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- README.md +91 -0
- midas_small_256_fp16.tflite +3 -0
README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: litert
|
| 4 |
+
pipeline_tag: depth-estimation
|
| 5 |
+
tags:
|
| 6 |
+
- litert
|
| 7 |
+
- tflite
|
| 8 |
+
- depth-estimation
|
| 9 |
+
- midas
|
| 10 |
+
- on-device
|
| 11 |
+
- android
|
| 12 |
+
- gpu
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# MiDaS small — LiteRT (fp16, NHWC, GPU-clean)
|
| 16 |
+
|
| 17 |
+
`midas_small_256_fp16.tflite` is **MiDaS v2.1 small** (`MiDaS_small`, the CNN MiDaS
|
| 18 |
+
with an EfficientNet-Lite3 backbone — not the DPT/ViT variants) converted to
|
| 19 |
+
**LiteRT** for on-device monocular depth estimation. Given one RGB image it
|
| 20 |
+
predicts a per-pixel inverse-depth map (near = bright, far = dark).
|
| 21 |
+
|
| 22 |
+
It is the model used by the LiteRT `compiled_model_api/depth_estimation` Android
|
| 23 |
+
sample.
|
| 24 |
+
|
| 25 |
+
## Files
|
| 26 |
+
|
| 27 |
+
| File | Precision | Size |
|
| 28 |
+
|---|---|---|
|
| 29 |
+
| `midas_small_256_fp16.tflite` | fp16 weights | ~33 MB |
|
| 30 |
+
|
| 31 |
+
## Specs
|
| 32 |
+
|
| 33 |
+
| | |
|
| 34 |
+
|---|---|
|
| 35 |
+
| Task | Monocular depth estimation |
|
| 36 |
+
| Source | `torch.hub.load("intel-isl/MiDaS", "MiDaS_small")` |
|
| 37 |
+
| Input | `1 x 256 x 256 x 3` float32, RGB, ImageNet-normalized, NHWC (interleaved) |
|
| 38 |
+
| Output | `1 x 256 x 256` float32, relative inverse depth |
|
| 39 |
+
|
| 40 |
+
**Pre-processing:** resize to 256×256, normalize with ImageNet stats
|
| 41 |
+
(`mean = [0.485, 0.456, 0.406]`, `std = [0.229, 0.224, 0.225]` on `[0,1]` pixels),
|
| 42 |
+
write as interleaved NHWC RGB float32.
|
| 43 |
+
|
| 44 |
+
**Post-processing:** min-max normalize the output and map through a color LUT
|
| 45 |
+
(the sample uses `inferno`).
|
| 46 |
+
|
| 47 |
+
## Why this conversion
|
| 48 |
+
|
| 49 |
+
The graph lowers entirely to GPU-clean builtins — no attention, no Flex/Custom
|
| 50 |
+
ops, no `GATHER_ND`, no `>4D` reshapes:
|
| 51 |
+
|
| 52 |
+
```
|
| 53 |
+
CONV_2D x73, ADD x27, DEPTHWISE_CONV_2D x24, RELU x7, RESIZE_BILINEAR x5, RESHAPE x1
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
- **Channel-last I/O** (`to_channel_last_io`) so the model takes NHWC `1x256x256x3`
|
| 57 |
+
directly, matching the interleaved RGB the app writes (no input transpose).
|
| 58 |
+
- **fp16** via AI Edge Quantizer `FLOAT_CASTING` — half the size, runs natively on
|
| 59 |
+
the GPU delegate. Dynamic-range int8 is intentionally avoided (it favors the
|
| 60 |
+
CPU/XNNPACK path, not the GPU delegate).
|
| 61 |
+
|
| 62 |
+
## Fidelity
|
| 63 |
+
|
| 64 |
+
- Converted fp32 vs. original PyTorch (real image): **corr 1.0000**, max|diff| ~1.6e-3.
|
| 65 |
+
- fp16 vs. fp32: **corr 0.9999998** (≈0.27 % of the depth range).
|
| 66 |
+
|
| 67 |
+
## On-device (Pixel 8a, verified)
|
| 68 |
+
|
| 69 |
+
The fp16 model compiles to **234 / 234 nodes on the LiteRT GPU delegate
|
| 70 |
+
(LITERT_CL)** — full GPU residency, no CPU fallback — at **~1–3 ms / inference**
|
| 71 |
+
(best 1.1 ms). `RESIZE_BILINEAR align_corners=True` is GPU-supported as-is; no
|
| 72 |
+
model change needed.
|
| 73 |
+
|
| 74 |
+
## License & attribution
|
| 75 |
+
|
| 76 |
+
- **MiDaS** weights: MIT (Intel ISL).
|
| 77 |
+
- **EfficientNet-Lite3** backbone: Apache-2.0.
|
| 78 |
+
|
| 79 |
+
Original work: Ranftl et al., *"Towards Robust Monocular Depth Estimation:
|
| 80 |
+
Mixing Datasets for Zero-shot Cross-dataset Transfer"* (MiDaS),
|
| 81 |
+
<https://github.com/isl-org/MiDaS>.
|
| 82 |
+
|
| 83 |
+
## Reproducing the conversion
|
| 84 |
+
|
| 85 |
+
A self-contained converter (`litert-torch` + `ai-edge-quantizer`) lives in the
|
| 86 |
+
sample under `compiled_model_api/depth_estimation/conversion/`:
|
| 87 |
+
|
| 88 |
+
```bash
|
| 89 |
+
pip install litert-torch ai-edge-quantizer torch timm matplotlib pillow
|
| 90 |
+
python convert_midas_litert.py out 256
|
| 91 |
+
```
|
midas_small_256_fp16.tflite
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bec9bce704789e504ec306196fcb0aabe90fd25c2b9d7db382339741950890ca
|
| 3 |
+
size 33507904
|