模型概述
模型特點
模型能力
使用案例
🚀 單目深度估計模型 dpt-beit-large-384
單目深度估計模型 dpt-beit-large-384 基於 BEiT 骨幹網絡,能夠從單張圖像中推斷出詳細的深度信息,在生成式 AI、3D 重建和自動駕駛等領域具有廣泛的應用價值。
🚀 快速開始
安裝依賴
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
使用模型進行零樣本深度估計
from transformers import DPTImageProcessor, 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)
# 本地文件獲取圖像
# path = "../image/000000039769.jpg"
# image = Image.open(path)
processor = DPTImageProcessor.from_pretrained("Intel/dpt-beit-large-384")
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-beit-large-384")
# 為模型準備圖像
inputs = 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)
depth
使用管道 API
from transformers import pipeline
pipe = pipeline(task="depth-estimation", model="Intel/dpt-beit-large-384")
result = pipe("http://images.cocodataset.org/val2017/000000181816.jpg")
result["depth"]
✨ 主要特性
- 基於 BEiT 骨幹網絡:DPT 模型使用 BEiT 模型作為骨幹網絡,並添加了頸部和頭部用於單目深度估計。
- 多領域應用:單目深度估計旨在從單張圖像或相機視圖中推斷詳細的深度信息,可應用於生成式 AI、3D 重建和自動駕駛等領域。
- 持續發展:隨著計算機視覺中變壓器架構的興起,MiDaS v3.1 結合了有前景的基於變壓器的編碼器和傳統的卷積編碼器,旨在全面研究深度估計技術。
📦 安裝指南
安裝依賴
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
版本要求
確保更新 PyTorch 和 Transformers,版本不匹配可能會產生錯誤,如:"TypeError: unsupported operand type(s) for //: 'NoneType' and 'NoneType'"。經測試,以下版本運行正常:
import torch
import transformers
print(torch.__version__)
print(transformers.__version__)
out: '2.2.1+cpu'
out: '4.37.2'
💻 使用示例
基礎用法
from transformers import DPTImageProcessor, 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)
# 本地文件獲取圖像
# path = "../image/000000039769.jpg"
# image = Image.open(path)
processor = DPTImageProcessor.from_pretrained("Intel/dpt-beit-large-384")
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-beit-large-384")
# 為模型準備圖像
inputs = 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)
depth
高級用法
from transformers import pipeline
pipe = pipeline(task="depth-estimation", model="Intel/dpt-beit-large-384")
result = pipe("http://images.cocodataset.org/val2017/000000181816.jpg")
result["depth"]
📚 詳細文檔
模型概述
單目深度估計旨在從單張圖像或相機視圖中推斷詳細的深度信息,但由於問題的約束不足,從單張圖像的單個像素中推導深度具有挑戰性。最近的進展歸功於基於學習的方法,特別是 MiDaS,它利用數據集混合和尺度與平移不變損失。MiDaS 不斷發展,推出了具有更強大骨幹網絡的版本和適用於移動設備的輕量級變體。隨著變壓器架構在計算機視覺中的興起,MiDaS v3.1 結合了有前景的基於變壓器的編碼器和傳統的卷積編碼器,旨在全面研究深度估計技術。
模型描述
DPT 模型使用 BEiT 模型作為骨幹網絡,並添加了頸部和頭部用於單目深度估計。之前發佈的 MiDaS v3.0 僅使用了原始視覺變壓器 ViT,而 MiDaS v3.1 提供了基於 BEiT、Swin、SwinV2、Next-ViT 和 LeViT 的額外模型。
模型細節
屬性 | 詳情 |
---|---|
模型作者 - 公司 | Intel |
日期 | 2024 年 3 月 7 日 |
版本 | 1 |
類型 | 計算機視覺 - 單目深度估計 |
論文或其他資源 | MiDaS v3.1 – A Model Zoo for Robust Monocular Relative Depth Estimation 和 GitHub 倉庫 |
許可證 | MIT |
問題或評論 | 社區標籤 和 Intel 開發者 Discord |
預期用途
預期用途 | 描述 |
---|---|
主要預期用途 | 可以使用原始模型進行零樣本單目深度估計。請參閱 模型中心 以查找針對您感興趣的任務進行微調的版本。 |
主要預期用戶 | 任何進行單目深度估計的人 |
超出範圍的用途 | 此模型在大多數情況下需要針對您的特定任務進行微調。該模型不應被用於故意為人們創造敵對或疏遠的環境。 |
定量分析
模型 | 方形分辨率 HRWSI RMSE | 方形分辨率混合 MVS REL | 方形分辨率 ReDWeb RMSE |
---|---|---|---|
BEiT 384-L | 10.82 | 10.82 | 10.82 |
Swin-L 訓練 1 | 0.0708 | 0.0724 | 0.0826 |
Swin-L 訓練 2 | 0.0713 | 0.0720 | 0.0831 |
ViT-L | 0.071 | 0.072 | 0.082 |
Next-ViT-L-1K-6M | 0.075 | 0.073 | 0.085 |
DeiT3-L-22K-1K | 0.070 | 0.070 | 0.080 |
ViT-L-Hybrid | 0.075 | 0.075 | 0.085 |
DeiT3-L | 0.077 | 0.075 | 0.087 |
ConvNeXt-XL | 0.075 | 0.075 | 0.085 |
ConvNeXt-L | 0.076 | 0.076 | 0.087 |
EfficientNet-L2 | 0.165 | 0.277 | 0.219 |
ViT-L 反轉 | 0.071 | 0.073 | 0.081 |
Swin-L 等距 | 0.072 | 0.074 | 0.083 |
倫理考慮和限制
dpt-beit-large-384 可能會產生事實錯誤的輸出,不應依賴它來產生事實準確的信息。由於預訓練模型和微調數據集的限制,該模型可能會生成淫穢、有偏見或其他冒犯性的輸出。因此,在部署 dpt-beit-large-384 的任何應用程序之前,開發人員應進行安全測試。
注意事項和建議
用戶(直接用戶和下游用戶)應瞭解模型的風險、偏差和限制。以下是一些瞭解 Intel AI 軟件的有用鏈接:
免責聲明
此模型的許可證不構成法律建議。我們不對使用此模型的第三方的行為負責。在將此模型用於商業目的之前,請諮詢律師。
BibTeX 引用
@article{DBLP:journals/corr/abs-2103-13413,
author = {Ren{\'{e}} Reiner Birkl, Diana Wofk, Matthias Muller},
title = {MiDaS v3.1 – A Model Zoo for Robust Monocular Relative Depth Estimation},
journal = {CoRR},
volume = {abs/2307.14460},
year = {2021},
url = {https://arxiv.org/abs/2307.14460},
eprinttype = {arXiv},
eprint = {2307.14460},
timestamp = {Wed, 26 Jul 2023},
biburl = {https://dblp.org/rec/journals/corr/abs-2307.14460.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
📄 許可證
本模型採用 MIT 許可證。






