Skip to content

APPLE DEPTH PRO · MONOCULAR METRIC DEPTH

Apple Depth Pro:1枚の画像から鮮明なメトリック深度

Depth Pro はゼロショット単眼深度推定のための Apple の基盤モデルです。カメラ情報なしで、メートル単位の絶対距離、推定焦点距離、鮮明な境界を返します。まずブラウザで深度マップを生成し、次にローカルで再現しましょう。

Depth Pro の特徴

多くの単眼深度モデルは相対深度を予測します。順序は正しくても尺度は不明です。Depth Pro は絶対尺度のメトリック深度を予測し、画像自体から焦点距離を推定するため、EXIF のない写真でも動作します。Apple はマルチスケール Vision Transformer により、細い構造や髪の毛レベルの境界を鮮明に保ちながら、標準 GPU で約0.3秒で 2.25 MP のマップを生成すると報告しています。

ブラウザで実行

本サイトの深度マップ生成ツールは、Transformers.js で ONNX 移植版を読み込み、WebGPU で GPU 上で実行します。q4f16 の重みは約600 MB で、初回実行後にブラウザにキャッシュされます。写真は端末から出ません。

Transformers.js · WebGPU
import { AutoModelForDepthEstimation, AutoProcessor, RawImage } from "@huggingface/transformers";

const id = "onnx-community/DepthPro-ONNX";
const processor = await AutoProcessor.from_pretrained(id);
const model = await AutoModelForDepthEstimation.from_pretrained(id, { device: "webgpu", dtype: "q4f16" });

const image = await RawImage.read("photo.jpg");
const { predicted_depth, focallength_px } = await model(await processor(image));
// predicted_depth: metric depth (metres); resize to the input and normalise for display.

Python で Depth Pro を実行

Transformers 統合は後処理後にメートル単位の深度、視野角、焦点距離を返します。CUDA、Apple Silicon の MPS、CPU(低速)で動作します。

Python · transformers ≥ 4.48
import torch
from PIL import Image
from transformers import DepthProForDepthEstimation, DepthProImageProcessorFast

device = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
processor = DepthProImageProcessorFast.from_pretrained("apple/DepthPro-hf")
model = DepthProForDepthEstimation.from_pretrained("apple/DepthPro-hf").to(device).eval()

image = Image.open("photo.jpg").convert("RGB")
inputs = processor(images=image, return_tensors="pt").to(device)
with torch.no_grad():
    outputs = model(**inputs)

post = processor.post_process_depth_estimation(outputs, target_sizes=[(image.height, image.width)])[0]
depth_m = post["predicted_depth"]          # metres, shape (H, W)
focal_px = float(post["focal_length"])     # estimated focal length in pixels
print(depth_m.min().item(), depth_m.max().item(), focal_px)

公式 ml-depth-pro CLI

Apple のリポジトリには、チェックポイントを取得して任意の画像の深度マップを書き出す小さな CLI が含まれます。公開どおりのリファレンス実装が必要な場合に使用します。

Shell · official repository
git clone https://github.com/apple/ml-depth-pro.git
cd ml-depth-pro
conda create -n depth-pro -y python=3.9
conda activate depth-pro
pip install -e .
source get_pretrained_models.sh          # downloads checkpoints/depth_pro.pt
depth-pro-run -i ./data/example.jpg      # writes a depth map next to the input

Depth Pro と Depth Anything の違い

Depth Anything V2 Small は約10分の1のサイズで高速、WebGPU なしでも動作しますが、深度は相対値です。メートル値、焦点距離、合成用の鮮明なエッジが必要なら Depth Pro を、素早いプレビューや低性能デバイスには Depth Anything を選んでください。生成ツールでは同じ画像で両方を切り替えられます。

よくある質問

Depth Pro は Mac で動きますか?

はい。PyTorch モデルは MPS バックエンドで Apple Silicon 上で動作し、ブラウザツールは WebGPU 対応の Mac で動作します。Apple の0.3秒はデータセンター GPU の値で、Mac では1枚数秒かかります。

公式の Core ML / iPhone 版はありますか?

公式リリースは PyTorch です。Core ML や Core AI への変換は可能ですが Apple のリポジトリではカバーされていません。ネイティブの 1536 × 1536 入力はスマートフォンには重いため、メモリを慎重に計測してください。

メトリック尺度の精度は?

Apple は複数データセットでゼロショットのメトリック精度が最先端だと報告していますが、尺度は焦点距離の推定に依存します。1枚の画像からのメートル値は推定として扱い、計測前に既知の物体で検証してください。