license: apache-2.0
tags:
- 深度估计
- 相对深度
pipeline_tag: depth-estimation
library: transformers
widget:
- inference: 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-Small-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-Small-hf")
model = AutoModelForDepthEstimation.from_pretrained("depth-anything/Depth-Anything-V2-Small-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.'}
}