MiDaS

MiDaS 是单目相对深度估计,在混合数据集上用尺度和偏移不变的损失函数训练,正是这条工作线确立了后来各家族沿用的零样本深度迁移流程。LibreYOLO 支持它的 depth 任务:预测和零样本验证,没有训练这一步。

任务
depth
尺寸
s, l at 256 to 384 px
安装
pip install libreyolo
支持层级
仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
上游
MiDaS,由 Intel Intelligent Systems Lab (Intel ISL) 发布,采用 MIT 许可。论文源码
许可
代码采用 MIT,权重采用 MIT。商用

安装

MiDaS 不需要任何可选 extra。它导入的一切都在基础安装里。

bash
pip install libreyolo

预测

MiDaS 是唯一一个 LibreYOLO 没有在自己的 Hugging Face 组织下重新发布的深度家 族。按 LibreYOLO 的文件名请求一个检查点(checkpoint),会直接从 isl-org/MiDaS 的 GitHub releases 下载对应的官方文件,校验固定的 SHA-256,并在首次使用前给它加 上 LibreYOLO 的检查点元数据;之后的运行会复用缓存的本地文件。原因见许可证一节。

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE # 本地还没有这个文件:LibreYOLO 会从官方的 isl-org/MiDaS GitHub release# 下载,并在使用前校验固定的 SHA-256model = LibreYOLO("LibreMiDaSl-depth.pt")result = model(SAMPLE_IMAGE, save=True) depth = result.depth_mapprint(depth.min, depth.max, depth.mean)
CLI
libreyolo predict model=LibreMiDaSl-depth.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
Small 变体
from libreyolo import LibreYOLO, SAMPLE_IMAGE # EfficientNet-Lite3 编码器,比 DPT-Large 的 l 尺寸更小更快model = LibreYOLO("LibreMiDaSs-depth.pt")result = model(SAMPLE_IMAGE, save=True)

result.depth_map 带的是一张稠密的相对逆深度图:值越大表示离相机越近,而且这些 值没有度量单位,也没有跨图像的统一尺度。save=True 会把这张图经过色彩映射的可 视化结果写入磁盘;Results.plot() 不覆盖这个家族,因为它只为表面法线和边缘定 义。数据源、流式处理和结果处理见预测

变体

两个变体用的是不同的编码器,而不只是同一个编码器的不同尺度。s 是 MiDaS v2.1 Small,一个 EfficientNet-Lite3 编码器。l 是 DPT-Large,一个 ViT-L/16 编码器, 配上 MiDaS 为稠密预测引入的 DPT 解码器。两者的预处理也不一样:s 用的是带上界 的保持宽高比缩放,加 ImageNet 的均值/标准差归一化,l 用的是最小的保持宽高比缩 放,均值和标准差都取 0.5。想要更轻的 CNN 就选 s,想要 transformer 解码器的精 度就选 l

这个家族不提供训练。LibreMiDaS.train() 无条件抛出 NotImplementedError

验证

val() 运行的是共用的深度验证器:它用逐图像的最小二乘尺度和偏移,把每个预测对 齐到它的真值(ground truth),然后报告标准的零样本相对深度指标,AbsRel、RMSE 和三个 delta 阈值。

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
libreyolo val model=LibreMiDaSl-depth.pt data=my-dataset.yaml

导出

任务ONNXTorchScriptExecuTorchTensorRTOpenVINOPaddleMNNRKNNncnnTFLiteCoreMLCore AI
depthdepth to ONNX:支持depth to TorchScript:支持depth to ExecuTorch:支持depth to TensorRT:支持depth to OpenVINO:支持depth to Paddle:不支持depth to MNN:不支持depth to RKNN:不支持depth to ncnn:支持depth to TFLite:不支持depth to CoreML:不支持depth to Core AI:不支持

导出的产物按文件后缀经由 LibreYOLO() 重新加载,所以一个 .onnx.engine 文件的表现和检查点一样,返回同样的 Results,只是把检测框换成了 depth_map

Python
from libreyolo import LibreYOLO model = LibreYOLO("LibreMiDaSl-depth.pt")model.export(format="onnx")model.export(format="tensorrt", half=True)
CLI
libreyolo export model=LibreMiDaSl-depth.pt format=onnxlibreyolo export model=LibreMiDaSl-depth.pt format=tensorrt half=True
使用导出的文件
from libreyolo import LibreYOLO, SAMPLE_IMAGE # 工厂按文件后缀分发,所以导出的产物加载方式和任何检查点一样,# 返回的也是同一个 Results 对象model = LibreYOLO("LibreMiDaSl-depth.onnx")result = model(SAMPLE_IMAGE) print(result.depth_map.data.shape)

许可证

请检查你所下载的具体权重在 Hugging Face 仓库中的许可。LibreYOLO 组织里的每个检查点都附有许可,同一家族内也不一定相同。该仓库是权威来源;以下摘要说明本页上次验证时适用的情况。

这里只说明涉及的许可证,不构成法律意见。如果答案对商用很重要,请自行阅读许可证并咨询法律顾问。

原始工作
MiDaS, Intel Intelligent Systems Lab (Intel ISL)
上游许可
MIT
LibreYOLO 代码
MIT
权重
采用 MIT 许可,由作者分发。LibreYOLO 不托管或镜像这些权重。
解读
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.

引用

@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},
}

复制自作者在 github.com/isl-org/MiDaS#citation 上提供的引用块。

已针对 LibreYOLO v1.5.0 验证。本页的支持表、检查点和基准测试数据由已发布的库和权重生成,并非手工编写。