> This is the documentation for LibreYOLO 1.5.0. Current version: https://www.libreyolo.com/docs/models/midas

# MiDaS
MiDaS is monocular relative depth estimation trained with scale-and-shift invariant loss across mixed datasets, the line of work that established the zero-shot depth transfer protocol later families reuse. LibreYOLO supports it for the depth task: predict and zero-shot validation, with no training path.
Tasks: depth. Install: pip install libreyolo.
Verified against LibreYOLO v1.5.0.

## Install

MiDaS needs no optional extra. Everything it imports is in the base install.

```bash
pip install libreyolo
```

## Predict

MiDaS is the one depth family LibreYOLO does not republish on its own Hugging
Face organization. Requesting a checkpoint by its LibreYOLO filename downloads
the matching official asset directly from the `isl-org/MiDaS` GitHub releases,
checks it against a pinned SHA-256, and wraps it with LibreYOLO's checkpoint
metadata before first use; later runs reuse the cached local file. See
Licensing for why.

**Python**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

# Not on disk yet: LibreYOLO downloads it from the official isl-org/MiDaS
# GitHub release and checks it against a pinned SHA-256 before use.
model = LibreYOLO("LibreMiDaSl-depth.pt")
result = model(SAMPLE_IMAGE, save=True)

depth = result.depth_map
print(depth.min, depth.max, depth.mean)
```

**CLI**

```bash
libreyolo predict model=LibreMiDaSl-depth.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
```

**Small variant**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

# EfficientNet-Lite3 encoder, smaller and faster than the DPT-Large l size.
model = LibreYOLO("LibreMiDaSs-depth.pt")
result = model(SAMPLE_IMAGE, save=True)
```

`result.depth_map` carries a dense relative inverse-depth map: higher
values mean closer to the camera, and the values have no metric unit or
cross-image scale. `save=True` writes a colormapped visualization of that map
to disk; `Results.plot()` does not cover this family, since it is defined for
surface normals and edges only. See [prediction](/docs/v1.5.0/predict) for sources,
streaming and result handling.

## Variants

Two variants with different encoders, not just different scales of the same
one. `s` is MiDaS v2.1 Small, an EfficientNet-Lite3 encoder. `l` is DPT-Large,
a ViT-L/16 encoder with the DPT decoder MiDaS introduced for dense prediction.
They also preprocess differently: `s` uses an upper-bound aspect resize with
ImageNet mean/std normalization, `l` uses a minimal aspect resize with mean and
std of 0.5. Pick `s` for a lighter CNN, `l` for the transformer decoder's
accuracy.

Training is not offered for this family. `LibreMiDaS.train()` raises
`NotImplementedError` unconditionally.

## Validate

`val()` runs the shared depth validator: it aligns each prediction to its
ground truth with a per-image least-squares scale and shift, then reports the
standard zero-shot relative-depth metrics, AbsRel, RMSE and the three delta
thresholds.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreMiDaSl-depth.pt")
metrics = model.val(data="my-dataset.yaml")

print(metrics["metrics/abs_rel"])
print(metrics["metrics/rmse"])
print(metrics["metrics/delta1"])
```

**CLI**

```bash
libreyolo val model=LibreMiDaSl-depth.pt data=my-dataset.yaml
```

## Export

| Task | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| depth | yes | yes | yes | yes | yes |  |  |  | yes |  |  |  |

A "yes" means the export is supported. An empty cell means the exporter refuses that combination.

An exported artifact loads back through `LibreYOLO()` on its file suffix, so a
`.onnx` or `.engine` file behaves like a checkpoint and returns the same
`Results`, with `depth_map` in place of boxes.

**Python**

```python
from libreyolo import LibreYOLO

model = LibreYOLO("LibreMiDaSl-depth.pt")
model.export(format="onnx")
model.export(format="tensorrt", half=True)
```

**CLI**

```bash
libreyolo export model=LibreMiDaSl-depth.pt format=onnx
libreyolo export model=LibreMiDaSl-depth.pt format=tensorrt half=True
```

**Use the exported file**

```python
from libreyolo import LibreYOLO, SAMPLE_IMAGE

# The factory routes on the file suffix, so an exported artifact loads
# like any checkpoint and returns the same Results object.
model = LibreYOLO("LibreMiDaSl-depth.onnx")
result = model(SAMPLE_IMAGE)

print(result.depth_map.data.shape)
```

## Licensing

Check the license on the Hugging Face repository of the specific weights you download. That repository is authoritative and licenses are not always uniform across a family. This is a description of the licenses involved, not legal advice.

- Original work: MiDaS, Intel Intelligent Systems Lab (Intel ISL)
- Upstream license: MIT
- Upstream source: https://github.com/isl-org/MiDaS
- LibreYOLO code: MIT
- Weights: MIT, distributed by their authors. LibreYOLO does not host or mirror them.
- Interpretation: The isl-org/MiDaS repository, code and released checkpoints included, is MIT. LibreYOLO's own port code is MIT as well. LibreYOLO does not republish the checkpoints on its own Hugging Face organization, though: the family downloads the two official release assets directly from GitHub and checks them against a pinned SHA-256 before wrapping them, because an internal LibreYOLO policy (ADR 0006) requires the training-dataset mixture's commercial-redistribution terms to be cleared before LibreYOLO hosts a depth checkpoint itself, and that clearance has not happened for MiDaS. The bytes you get are upstream's own MIT-licensed release either way.

## Citation

```bibtex
@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"
}

@article{Ranftl2021,
	author    = {Ren\'{e} Ranftl and Alexey Bochkovskiy and Vladlen Koltun},
	title     = {Vision Transformers for Dense Prediction},
	journal   = {ICCV},
	year      = {2021},
}
```

Copied from https://github.com/isl-org/MiDaS#citation


## MiDaS architecture

- Small EfficientNet-Lite3: [SVG](/diagrams/models/midas/s-depth.svg), [interactive diagram](/diagrams/models/midas/s-depth.html)
- Large ViT-L/16: [SVG](/diagrams/models/midas/l-depth.svg), [interactive diagram](/diagrams/models/midas/l-depth.html)
