🚀 DepthPro:单目深度估计
DepthPro是一个用于零样本度量单目深度估计的基础模型,能够生成具有出色清晰度和细粒度细节的高分辨率深度图。它采用多尺度视觉Transformer(ViT)架构,可快速且精确地进行深度估计。
🚀 快速开始
使用以下代码开始使用该模型:
import requests
from PIL import Image
import torch
from transformers import DepthProImageProcessorFast, DepthProForDepthEstimation
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
url = 'https://huggingface.co/datasets/mishig/sample_images/resolve/main/tiger.jpg'
image = Image.open(requests.get(url, stream=True).raw)
image_processor = DepthProImageProcessorFast.from_pretrained("apple/DepthPro-hf")
model = DepthProForDepthEstimation.from_pretrained("apple/DepthPro-hf").to(device)
inputs = image_processor(images=image, return_tensors="pt").to(device)
with torch.no_grad():
outputs = model(**inputs)
post_processed_output = image_processor.post_process_depth_estimation(
outputs, target_sizes=[(image.height, image.width)],
)
field_of_view = post_processed_output[0]["field_of_view"]
focal_length = post_processed_output[0]["focal_length"]
depth = post_processed_output[0]["predicted_depth"]
depth = (depth - depth.min()) / (depth.max() - depth.min())
depth = depth * 255.
depth = depth.detach().cpu().numpy()
depth = Image.fromarray(depth.astype("uint8"))
✨ 主要特性
- 高分辨率与细节:能够合成具有无与伦比清晰度和高频细节的高分辨率深度图。
- 度量准确性:预测结果是度量性的,具有绝对尺度,无需依赖相机内参等元数据。
- 快速高效:在标准GPU上,可在0.3秒内生成225万像素的深度图。
- 多尺度架构:采用多尺度视觉Transformer(ViT)架构,结合共享的Dinov2编码器和DPT-like融合阶段,实现精确的深度估计。
📚 详细文档
模型详情
DepthPro是一个用于零样本度量单目深度估计的基础模型,旨在生成具有出色清晰度和细粒度细节的高分辨率深度图。它采用基于多尺度视觉Transformer(ViT)的架构,将图像下采样、分割成补丁,并使用共享的Dinov2编码器进行处理。提取的补丁级特征被合并、上采样,并使用类似DPT的融合阶段进行细化,从而实现精确的深度估计。
论文摘要如下:
我们提出了一个用于零样本度量单目深度估计的基础模型。我们的模型Depth Pro能够合成具有无与伦比清晰度和高频细节的高分辨率深度图。预测结果是度量性的,具有绝对尺度,无需依赖相机内参等元数据。并且该模型速度快,在标准GPU上可在0.3秒内生成225万像素的深度图。这些特性得益于一系列技术贡献,包括用于密集预测的高效多尺度视觉Transformer、结合真实和合成数据集以实现高度量准确性和精细边界跟踪的训练协议、用于估计深度图中边界准确性的专用评估指标,以及从单张图像进行的最先进的焦距估计。大量实验分析了具体的设计选择,并证明了Depth Pro在多个维度上优于先前的工作。
这是一个已发布在Hugging Face Hub上的🤗 transformers 模型的模型卡片。
- 开发者:Aleksei Bochkovskii、Amaël Delaunoy、Hugo Germain、Marcel Santos、Yichao Zhou、Stephan R. Richter、Vladlen Koltun。
- 模型类型:DepthPro
- 许可证:Apple-ASCL
模型来源
- HF文档:DepthPro
- 代码仓库:https://github.com/apple/ml-depth-pro
- 论文:https://arxiv.org/abs/2410.02073
训练详情
训练数据
DepthPro模型在以下数据集上进行训练:

预处理
图像经过以下预处理步骤:
- 缩放比例为
1/225.
- 归一化处理,均值为
[0.5, 0.5, 0.5]
,标准差为 [0.5, 0.5, 0.5]
- 调整大小为
1536x1536
像素
训练超参数

评估

模型架构和目标

DepthProForDepthEstimation
模型使用 DepthProEncoder
对输入图像进行编码,并使用 FeatureFusionStage
融合编码器的输出特征。
DepthProEncoder
进一步使用两个编码器:
patch_encoder
- 输入图像按照
scaled_images_ratios
配置中的多个比例进行缩放。
- 每个缩放后的图像被分割成大小为
patch_size
的小 补丁,重叠区域由 scaled_images_overlap_ratios
确定。
- 这些补丁由
patch_encoder
进行处理。
image_encoder
- 输入图像也被缩放到
patch_size
并由 image_encoder
进行处理。
这两个编码器可以分别通过 patch_model_config
和 image_model_config
进行配置,默认情况下,它们都是独立的 Dinov2Model
。
两个编码器的输出 (last_hidden_state
) 和 patch_encoder
的选定中间状态 (hidden_states
) 由基于 DPT
的 FeatureFusionStage
进行融合,以进行深度估计。
该网络还配备了一个焦距估计头。一个小型卷积头接收来自深度估计网络的冻结特征和来自独立ViT图像编码器的特定任务特征,以预测水平角视场。
📄 许可证
该模型使用的许可证为apple-amlr。
📖 引用
@misc{bochkovskii2024depthprosharpmonocular,
title={Depth Pro: Sharp Monocular Metric Depth in Less Than a Second},
author={Aleksei Bochkovskii and Amaël Delaunoy and Hugo Germain and Marcel Santos and Yichao Zhou and Stephan R. Richter and Vladlen Koltun},
year={2024},
eprint={2410.02073},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2410.02073},
}
👨💻 模型卡片作者
Armaghan Shakir