🚀 模型卡片:基于DINOv2主干的DPT模型
本模型使用DPT(密集预测变换器)架构,并以DINOv2作为主干网络,可用于强大的深度估计任务。它基于Oquab等人发表的论文 DINOv2: Learning Robust Visual Features without Supervision 开发。
📚 详细文档
模型详情
DPT(Dense Prediction Transformer)模型采用DINOv2作为主干网络,该模型由Oquab等人在 DINOv2: Learning Robust Visual Features without Supervision 中提出。

DPT架构。取自 原始论文。
参考资源
使用Transformers库调用模型
from transformers import AutoImageProcessor, DPTForDepthEstimation
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("facebook/dpt-dinov2-large-kitti")
model = DPTForDepthEstimation.from_pretrained("facebook/dpt-dinov2-large-kitti")
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,
)
output = prediction.squeeze().cpu().numpy()
formatted = (output * 255 / np.max(output)).astype("uint8")
depth = Image.fromarray(formatted)
💻 使用示例
基础用法
from transformers import AutoImageProcessor, DPTForDepthEstimation
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("facebook/dpt-dinov2-large-kitti")
model = DPTForDepthEstimation.from_pretrained("facebook/dpt-dinov2-large-kitti")
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,
)
output = prediction.squeeze().cpu().numpy()
formatted = (output * 255 / np.max(output)).astype("uint8")
depth = Image.fromarray(formatted)
📄 许可证
本模型使用Apache-2.0许可证。
模型使用说明
预期用途
该模型旨在展示使用DPT框架并以DINOv2作为主干网络可以得到一个强大的深度估计器。
BibTeX引用和引用信息
@misc{oquab2023dinov2,
title={DINOv2: Learning Robust Visual Features without Supervision},
author={Maxime Oquab and Timothée Darcet and Théo Moutakanni and Huy Vo and Marc Szafraniec and Vasil Khalidov and Pierre Fernandez and Daniel Haziza and Francisco Massa and Alaaeldin El-Nouby and Mahmoud Assran and Nicolas Ballas and Wojciech Galuba and Russell Howes and Po-Yao Huang and Shang-Wen Li and Ishan Misra and Michael Rabbat and Vasu Sharma and Gabriel Synnaeve and Hu Xu and Hervé Jegou and Julien Mairal and Patrick Labatut and Armand Joulin and Piotr Bojanowski},
year={2023},
eprint={2304.07193},
archivePrefix={arXiv},
primaryClass={cs.CV}
}