For the complete documentation index, see llms.txt. This page is also available as Markdown.

Depth Anything V2

Use Depth Anything V2 for monocular depth estimation on a Dedicated Deployment or self-hosted Inference

Depth Anything V2 is a monocular depth estimation model. It returns a normalized depth map (values between 0 and 1) for any input image.

Depth Anything V2 is not available on the Serverless Cloud API. Run it on a Dedicated Deployment or self-hosted Inference.

Code sample

1

Get your API Key

Create a Roboflow account, find your key on the Roboflow API settings page and make it available to your shell:

export ROBOFLOW_API_KEY="your-key-here"
2

Install the dependencies

Install the Inference SDK:

pip install -U inference-sdk opencv-python supervision
3

Run the model

Set api_url to your Dedicated Deployment URL or a local Inference server. The script colorizes the depth map and writes a side-by-side comparison with the input.

import os
import cv2
import numpy as np
import supervision as sv
from inference_sdk import InferenceHTTPClient

image = sv.load_image_from_url("https://media.roboflow.com/notebooks/examples/bicycle.png")
client = InferenceHTTPClient(
    api_url="https://your-deployment.roboflow.cloud",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.depth_estimation(image)

depth = np.array(result["normalized_depth"], dtype=np.float32)
depth = cv2.resize(depth, (image.shape[1], image.shape[0]))
depth_vis = (depth * 255).astype(np.uint8)
depth_color = cv2.applyColorMap(depth_vis, cv2.COLORMAP_INFERNO)

cv2.imwrite("depth_annotated.png", np.hstack([image, depth_color]))

Inference speed

Latency measured with Roboflow Inference on 1x NVIDIA L4, batch size 1, mean after warmup.

Model
Latency (ms)

depth-anything-v2

40.1

Measured on the Small checkpoint.

Set api_url to match your deployment target:

Available models

The depth estimation endpoint and the depth_estimation@v1 Workflow block serve two model families behind one ordinal-depth contract: an image-sized map normalized per image, where 1.0 is nearest and 0.0 is farthest.

  • Depth Anything (relative depth): depth-anything-v2/small, depth-anything-v3/small, depth-anything-v3/base

  • YOLO26 depth (metric depth, normalized on this path, substantially faster): yolo26n-depth-768, yolo26s-depth-768, yolo26m-depth-768, yolo26l-depth-768, yolo26x-depth-768

The shared output preserves shape, range, and near-to-far ordering across models, but intermediate values are not geometrically equivalent between model families. Values are ordinal proximity scores, not physical distances, and must not be compared numerically across different images or model families. For absolute metric depth in meters from the YOLO26 checkpoints, load them directly with inference_models.AutoModel.

Response formats

The /infer/depth-estimation endpoint serializes normalized_depth according to the request's depth_map_format field:

  • json (default): a nested list of floats between 0 and 1. Wire-compatible with older clients, but roughly 17 MB for a 1080x810 image.

  • png16: a base64 16-bit grayscale PNG (quantization step 1/65535, typically more than 10x smaller and much faster to serve).

  • png8: a base64 8-bit grayscale PNG (256 depth levels, roughly another order of magnitude smaller). Fine for visualization and thresholding, lossy for derivative-based geometric use.

The SDK's depth_estimation() method defaults to json, so existing integrations keep receiving the nested list. Pass depth_map_format="png16" (or "png8") to opt in to the compact payload: the SDK decodes it back into a numpy.ndarray (call .tolist() if you need JSON-serializable output).

Use with Inference (self-hosted)

You can also load the model directly with the inference package.

1

Install the package

Use inference-gpu[transformers] on a GPU machine.

2

Authenticate with Hugging Face

The weights are pulled from Hugging Face, so set a Hugging Face token:

3

Run the model

normalized_depth holds the per-image depth map, and image holds a colorized visualization where lighter colors are nearer and darker colors are farther.

Execution modes in Workflows

When used in a Workflow, depth estimation runs in one of two modes:

  • Local execution: the model runs on your Inference server (GPU recommended).

  • Remote execution: the model is invoked over HTTP on a remote Inference server through the depth_estimation() client method.

Last updated

Was this helpful?