库名称: transformers
库: transformers
许可证: cc-by-nc-4.0
标签:
- 深度估计
- 相对深度
管道标签: 深度估计
小部件:
- 推理: 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: 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="深度估计", 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="双三次",
align_corners=False,
)
更多示例请参阅文档。
引用文献
@misc{yang2024depth,
title={Depth Anything V2},
author={李贺阳 and 康兵义 and 黄子龙 and 赵振 and 许晓刚 and 冯佳时 and 赵恒爽},
year={2024},
eprint={2406.09414},
archivePrefix={arXiv},
primaryClass={id='cs.CV' full_name='计算机视觉与模式识别' is_active=True alt_name=None in_archive='cs' is_general=False description='涵盖图像处理、计算机视觉、模式识别和场景理解。大致对应ACM学科分类I.2.10、I.4和I.5的内容'}
}