Use AIUnderstand AIBuild with AI
Build with AI·Model deep dive·· 4 min read

Depth Pro 2: Metric Depth From One Photo or a Whole Video

Apple's Depth Pro 2 predicts depth in meters for every pixel of a photo, video or live feed. Four sizes from 24M to 872M parameters, research-only license.

The code in this post comes from the model's docs and hasn't been run in our CI yet. If something breaks, let us know.

Depth Pro 2 is a depth-estimation model from Apple’s machine learning research group. From an ordinary camera image, it estimates metric depth, meaning distance in meters, for every pixel. It works on a single photo, a whole video, or a live feed, at the input’s full resolution. The card says its depth is sharp at object edges and steady from frame to frame.

One thing to read before anything else: the license is for research use only. More on that below.

Key specs

Each size is its own repository with its own weights.

Model Repository Parameters Download size
S apple/DepthPro2-S 24M 97 MB
B apple/DepthPro2-B 97M 386 MB
L apple/DepthPro2-L 334M 1.3 GB
H+ apple/DepthPro2-H 872M 3.5 GB
  • Larger sizes give sharper, steadier depth. Smaller ones run faster.
  • All sizes share a focal length estimator, apple/DepthPro2-focal (23.5M parameters, 94 MB). It predicts the focal length when the photo or video doesn’t provide one.
  • Architecture, per the card: a multi-view transformer processes one or more frames jointly, and a DPT decoder predicts an inverse depth map for each frame.
  • The card reports that Depth Pro 2 outperforms prior single-frame and multi-frame methods on sharpness (Boundary F1) and temporal consistency (jitter), averaged over the Sintel and Spring datasets. The card gives this as a chart, not a table of numbers, so treat it as a headline claim and test on your own footage.

Install

The card installs the code from GitHub:

Terminal window
pip install "git+https://github.com/apple-aiml-research/ml-depth-pro-2"

The loading code below also imports torch, huggingface_hub and safetensors, and the video example imports av. The card doesn’t list install commands for those, so install them as your environment needs.

Load the model

This is the card’s setup code. The card notes that bfloat16 is how the models run on a GPU, and the example moves the model to cuda.

load_model.py
from functools import partial
import torch
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
from depth_pro_2 import DepthPro2, load_rgb, upright
from depth_pro_2.model import to_normalized_tensor
from depth_pro_2.network.fov import FOVEstimator
# apple/DepthPro2-S, -B, -L or -H; bfloat16 is how the models run on a GPU.
model = DepthPro2.from_pretrained("apple/DepthPro2-H", precision=torch.bfloat16)
# The focal length estimator all sizes share, for photos and videos without a focal length.
weights = hf_hub_download("apple/DepthPro2-focal", "model.safetensors")
model.fov = FOVEstimator(torch.bfloat16)
model.fov.load_state_dict(load_file(weights))
model = model.to("cuda").eval()
transform = partial(to_normalized_tensor, device=torch.device("cuda"))

To try a smaller size, change "apple/DepthPro2-H" to -S, -B or -L.

Depth for a single photo

image_depth.py
# Run after load_model.py (same session).
# f_px is the focal length recorded in the photo, or None.
image, f_px = load_rgb("photo.jpg")
depth = model.infer(transform(image), f_px=f_px)["depth"] # meters, (H, W)

load_rgb returns the image and the focal length recorded in the photo, or None if there isn’t one. The result is a depth map in meters with shape (H, W). The card adds that depth is infinite where the scene is infinitely far away, such as the sky. If you post-process the map, handle those infinite values.

Depth for a video

video_depth.py
# Run after load_model.py (same session).
import av
# 16 frames at a time: one prediction per frame, in order.
video = av.open("video.mp4")
frames = (transform(upright(f)) for f in video.decode(video=0))
for prediction in model.infer_video(frames):
depth = prediction["depth"] # meters, (H, W)

infer_video takes a stream of frames and yields one prediction per frame, in order. The card’s comment says frames are handled 16 at a time. The code repository also has a command line and a live-feed example, per the card; those aren’t reproduced on the card itself, so check the repo.

Gotchas

  • Research-only license. The weights use the Apple Machine Learning Research Model license (apple-amlr), which the card describes as for research use only: non-commercial scientific research and academic development. Don’t build a product on it without reading the license yourself.
  • Install from GitHub. The card installs the package from a git URL.
  • GPU assumed. The example uses CUDA and bfloat16. The card doesn’t show a CPU path.
  • Focal length matters for metric depth. If your photo has no recorded focal length, f_px is None and the shared focal length estimator predicts it. The card doesn’t give accuracy numbers for that estimate, so check results against something you can measure.
  • Infinite depth. Sky and other infinitely distant regions come back as infinite values.
  • The card shows no memory or speed figures for any size, beyond download size and parameter counts. Benchmark on your own hardware.

When to pick it

Pick Depth Pro 2 if you are doing research or academic work that needs depth in real units from a normal camera, especially on video where frame-to-frame flicker would ruin a per-frame model’s output. The S and B sizes are small downloads, so they are an easy way to try the idea before moving up to L or H+.

Skip it if you need a commercially licensed model, since the research-only terms rule that out. Skip it too if you need a CPU-only setup or a documented speed target. The card shows neither.

Related