library_name: transformers
library: transformers
license: cc-by-nc-4.0
tags:
- 深度估计
- 相对深度
pipeline_tag: depth-estimation
widget:
- inference: false
Depth Anything V2基础版——Transformers版本
Depth Anything V2基于59.5万张合成标注图像和6200万+真实无标注图像训练而成,是目前最强大的单目深度估计(MDE)模型,具有以下特点:
- 比V1版本呈现更精细的细节
- 比V1版本和基于SD的模型(如Marigold、Geowizard)更鲁棒
- 比基于SD的模型更高效(快10倍)且更轻量
- 使用我们的预训练模型进行微调可获得惊人效果
本模型检查点与transformers库完全兼容。
Depth Anything V2由李贺阳等人在同名论文中提出。该模型采用与原始Depth Anything相同的架构,但通过合成数据和更大容量的教师模型实现了更精细、更鲁棒的深度预测。原始Depth Anything模型首次发表于李贺阳等人的论文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-Large-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-Large-hf")
model = AutoModelForDepthEstimation.from_pretrained("depth-anything/Depth-Anything-V2-Large-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.'}
}