🚀 深度任意模型(小型模型,Transformer版本)
深度任意模型(Depth Anything)是一个用于深度估计的模型。它由Lihe Yang等人在论文《深度任意:释放大规模无标签数据的力量》中提出,并首次在此仓库发布。此外,还提供了在线演示。
需要注意的是,发布深度任意模型的团队并未为该模型撰写模型卡片,此模型卡片由Hugging Face团队编写。
🚀 快速开始
深度任意模型可以用于零样本深度估计等任务。你可以在模型中心查找其他版本以满足你的需求。
✨ 主要特性
- 先进架构:深度任意模型采用了DPT架构,并以DINOv2作为骨干网络。
- 大规模训练:该模型在约6200万张图像上进行训练,在相对和绝对深度估计任务中均取得了最先进的结果。
📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
以下是使用该模型进行零样本深度估计的示例代码:
from transformers import pipeline
from PIL import Image
import requests
pipe = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-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("LiheYoung/depth-anything-small-hf")
model = AutoModelForDepthEstimation.from_pretrained("LiheYoung/depth-anything-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,
)
更多代码示例请参考文档。
📚 详细文档
模型描述
深度任意模型利用DPT架构和DINOv2骨干网络,在约6200万张图像上进行训练,在相对和绝对深度估计任务中均取得了最先进的结果。

深度任意模型概述。取自原始论文。
预期用途和局限性
你可以使用原始模型进行零样本深度估计等任务。
引用信息
@misc{yang2024depth,
title={Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data},
author={Lihe Yang and Bingyi Kang and Zilong Huang and Xiaogang Xu and Jiashi Feng and Hengshuang Zhao},
year={2024},
eprint={2401.10891},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
📄 许可证
本模型采用Apache 2.0许可证。