MiDaS
MiDaS 是单目相对深度估计,在混合数据集上用尺度和偏移不变的损失函数训练,正是这条工作线确立了后来各家族沿用的零样本深度迁移流程。LibreYOLO 支持它的 depth 任务:预测和零样本验证,没有训练这一步。
- 任务
- depth
- 尺寸
- s, l at 256 to 384 px
- 安装
pip install "libreyolo[midas]"- 支持层级
- 仅推理,自 v1.5.0 起。仅支持预测、验证和导出。训练相关的功能不适用。
- 许可
- 代码采用 MIT,权重采用 MIT。商用
安装
MiDaS 需要 midas extra 来提供 timm 编码器。
pip install "libreyolo[midas]"预测
s 和 l 检查点依据发布者的 MIT 授权从 LibreYOLO 镜像下载,并缓存在本地。
from libreyolo import LibreYOLO, SAMPLE_IMAGE # 首次使用时下载镜像检查点model = LibreYOLO("LibreMiDaSl-depth.pt")result = model(SAMPLE_IMAGE, save=True) depth = result.depth_mapprint(depth.min, depth.max, depth.mean)libreyolo predict model=LibreMiDaSl-depth.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=Truefrom 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 阈值。
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"])libreyolo val model=LibreMiDaSl-depth.pt data=my-dataset.yaml导出
| 任务 | ONNX | TorchScript | ExecuTorch | TensorRT | OpenVINO | Paddle | MNN | RKNN | ncnn | TFLite | CoreML | Core AI |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Depth | Depth 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。
from libreyolo import LibreYOLO model = LibreYOLO("LibreMiDaSl-depth.pt")model.export(format="onnx")model.export(format="tensorrt", half=True)libreyolo export model=LibreMiDaSl-depth.pt format=onnxlibreyolo export model=LibreMiDaSl-depth.pt format=tensorrt half=Truefrom 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 许可,重新发布在 huggingface.co/LibreYOLO
- 解读
- The upstream repository and released weights declare MIT. LibreYOLO mirrors the s and l checkpoints under that publisher grant.
引用
@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 上提供的引用块。