查看 Markdown

Depth Anything V2

Depth Anything V2 是一个 DINOv2 编码器搭配 DPT 解码器,从单张图像预测稠密的相对逆深度图。LibreYOLO 支持它的 depth 任务:预测和零样本验证,没有训练这一步。

任务
depth
尺寸
s, b, l, g at 518 px
安装
pip install libreyolo
支持层级
仅推理,自 v 起。仅支持预测、验证和导出。训练相关的功能不适用。
上游
Depth Anything V2,由 The University of Hong Kong and TikTok 发布,采用 Apache-2.0 (Small checkpoint); CC-BY-NC-4.0 (Base and Large checkpoints) 许可。论文源码
许可
代码采用 Apache-2.0,权重采用 Apache-2.0 (Small checkpoint); CC-BY-NC-4.0 (Base and Large checkpoints)。商用

安装

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

bash
pip install libreyolo

预测

权重在首次使用时从 Hugging Face 下载,并缓存在本地。

Python
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreDepthAnythingV2s-depth.pt")result = model(SAMPLE_IMAGE, save=True) depth = result.depth_mapprint(depth.min, depth.max, depth.mean)
CLI
libreyolo predict model=LibreDepthAnythingV2s-depth.pt source=https://raw.githubusercontent.com/LibreYOLO/libreyolo/release/libreyolo/assets/parkour.jpg save=True
读取深度图
from libreyolo import LibreYOLO, SAMPLE_IMAGE model = LibreYOLO("LibreDepthAnythingV2s-depth.pt")result = model(SAMPLE_IMAGE) depth = result.depth_map    # DepthMap:稠密的 (H, W),值越大越近raw = depth.data                # 张量,没有度量单位,也没有跨图像的尺度normalized = depth.normalized() # 重新缩放到 [0, 1] 用于可视化

result.depth_map 带的是一张稠密的相对逆深度图:值越大表示离相机越近,而且这些 值没有度量单位,也没有跨图像的统一尺度。save=True 会把这张图经过色彩映射的可 视化结果写入磁盘;Results.plot() 不覆盖这个家族,因为它只为表面法线和边缘定 义。输入分辨率必须能被 14 整除,也就是 DPT head 所依赖的 DINOv2 patch 网格; LibreYOLO 在运行前会检查这一点,不满足就抛出异常。数据源、流式处理和结果处理见 预测

变体

四种编码器尺寸,s/b/l/g,对应 ViT-S/B/L/G。下面的检查点(checkpoint)表只列出 s、b 和 l;没有发布 Giant 检查点。四种共享同样的输入分辨率,所以选尺寸换的是编 码器容量,而不是图像尺寸。许可证也是一个因素:Small 检查点采用 Apache-2.0 许 可,而 Base 和 Large 采用 CC-BY-NC-4.0,见下面的许可证一节。

这个家族不提供训练和微调。LibreDepthAnythingV2.train() 无条件抛出 NotImplementedError;请改用 weights/convert_depth_anything_v2_weights.py 转换一个兼容的上游检查点。

验证

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

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

检查点

这个家族已发布的全部权重文件。

文件输入(px)权重许可
depth
LibreDepthAnythingV2s-depth.ptapache-2.0
LibreDepthAnythingV2l-depth.ptcc-by-nc-4.0
LibreDepthAnythingV2b-depth.ptcc-by-nc-4.0

上面的每个文件目前都在 LibreYOLO 组织中,并会在首次使用时下载。

许可证

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

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

原始工作
Depth Anything V2, The University of Hong Kong and TikTok
上游许可
Apache-2.0 (Small checkpoint); CC-BY-NC-4.0 (Base and Large checkpoints)
LibreYOLO 代码
MIT
权重
采用 Apache-2.0 (Small checkpoint); CC-BY-NC-4.0 (Base and Large checkpoints) 许可,重新发布在 huggingface.co/LibreYOLO
解读
The two licenses are not interchangeable. The Small checkpoint is Apache-2.0, a permissive license: it can be used in commercial and closed-source products, it asks you to keep its license text and attribution notices with any redistributed copy, and it grants a patent license. The Base and Large checkpoints are CC-BY-NC-4.0, which forbids commercial use outright and requires attribution on any redistribution, so treat them as research and evaluation weights unless you obtain separate terms from the authors. LibreYOLO's own code for this family is MIT throughout, and training is not offered for this family so there is no self-trained-weights exception to reach for.

引用

@article{depth_anything_v2,
  title={Depth Anything V2},
  author={Yang, Lihe and Kang, Bingyi and Huang, Zilong and Zhao, Zhen and Xu, Xiaogang and Feng, Jiashi and Zhao, Hengshuang},
  journal={arXiv:2406.09414},
  year={2024}
}

复制自作者在 github.com/DepthAnything/Depth-Anything-V2#citation 上提供的引用块。

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