库名称: transformers
库: transformers
许可证: cc-by-nc-4.0
标签:
- 深度
- 相对深度
任务标签: 深度估计
小部件:
- 推理: false
Depth Anything V2 基础版 – Transformers版本
Depth Anything V2 基于59.5万张合成标注图像和6200万+真实无标注图像训练而成,是目前最强大的单目深度估计(MDE)模型,具有以下特点:
- 比Depth Anything V1展现更精细的细节
- 比Depth Anything V1和基于SD的模型(如Marigold、Geowizard)更鲁棒
- 比基于SD的模型更高效(速度快10倍)且更轻量
- 使用我们的预训练模型进行微调时表现惊艳
该模型检查点与transformers库兼容。
Depth Anything V2由Lihe Yang等人在同名论文中提出。其架构与原始Depth Anything版本相同,但通过合成数据和更大容量的教师模型实现了更精细、更鲁棒的深度预测。原始Depth Anything模型由Lihe Yang等人在论文Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data中首次提出,并在该代码库发布。
在线演示。
模型描述
Depth Anything V2采用DPT架构,以DINOv2为骨干网络。
该模型基于约60万张合成标注图像和约6200万真实无标注图像训练,在相对深度和绝对深度估计任务上均达到最先进水平。

Depth Anything概览图。摘自原论文。
使用场景与限制
您可将该原始模型用于零样本深度估计等任务。访问模型中心探索其他任务版本。
使用方法
以下示例展示如何使用该模型进行零样本深度估计:
from transformers import pipeline
from PIL import Image
import requests
pipe = pipeline(task="depth-estimation", model="depth-anything/Depth-Anything-V2-Base-hf")
url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)
depth = pipe(image)["depth"]
或使用模型与处理器类:
from transformers import AutoImageProcessor, AutoModelForDepthEstimation
import torch
import numpy as np
from PIL import Image
import requests
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
image_processor = AutoImageProcessor.from_pretrained("depth-anything/Depth-Anything-V2-Base-hf")
model = AutoModelForDepthEstimation.from_pretrained("depth-anything/Depth-Anything-V2-Base-hf")
inputs = image_processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
predicted_depth = outputs.predicted_depth
prediction = torch.nn.functional.interpolate(
predicted_depth.unsqueeze(1),
size=image.size[::-1],
mode="bicubic",
align_corners=False,
)
更多代码示例请参阅文档。
引用
@misc{yang2024depth,
title={Depth Anything V2},
author={Lihe Yang and Bingyi Kang and Zilong Huang and Zhen Zhao and Xiaogang Xu and Jiashi Feng and Hengshuang Zhao},
year={2024},
eprint={2406.09414},
archivePrefix={arXiv},
primaryClass={id='cs.CV' full_name='Computer Vision and Pattern Recognition' is_active=True alt_name=None in_archive='cs' is_general=False description='Covers image processing, computer vision, pattern recognition, and scene understanding. Roughly includes material in ACM Subject Classes I.2.10, I.4, and I.5.'}
}