← All models

depth-estimation Β· vision Β· WebGPU (fp16) Β· ~100 MB

Depth Anything v2 β€” how far away is every pixel?

Give it one ordinary photo β€” no stereo pair, no depth sensor β€” and it estimates the distance to every pixel. That single grayscale map is the raw material for 3D parallax, portrait-style background blur, and AR occlusion. It runs entirely on your device; the photo never leaves the tab.

At a glance

Modelonnx-community/depth-anything-v2-small
Task / pipelinedepth-estimation β€” monocular (single-image) relative depth
ArchitectureDINOv2 ViT-S encoder + DPT depth head β†’ one depth value per pixel
Quantizationfp16 (half precision) ONNX
BackendWebGPU (fp16); falls back to WebAssembly where WebGPU is absent
Download~100 MB, cached after first load
LicenseApache-2.0 (Depth Anything V2 Small)
Web APIsWebGPU, Web Workers, Canvas 2D, FileReader β€” WebGPU is the only non-Baseline piece, and the page says so if it's missing

Run it

Pick or drop a photo, then estimate depth. Warmer / brighter means closer; darker means further away. Switch the colour map to read the scene differently.

Drop a photo, or click to choose
Two cats on a couch A sunlit bedroom A riverside at golden hour

Input

Selected photo

Estimated depth

farnear

See inside

The model doesn't output a picture β€” it outputs a tensor of real numbers, one per pixel: the raw relative depth. Bigger = nearer. The colour map above is just those numbers, min–max normalized to 0–255. Below is the honest view: the raw range straight from the model and how the depths are distributed across the scene.

Estimate a depth map to see the raw numbers.

Why it matters

Depth used to need special hardware β€” a stereo rig, a LiDAR sensor, a structured-light camera. Depth Anything estimates it from a single frame, small enough and fast enough to run in a web page. Once you know how far away each pixel is, a whole class of effects opens up client-side:

Use cases

Basics

One photo in, a colourised depth map out β€” read distance as colour.

Practical

Depth-driven background blur β€” fake a portrait-mode lens in the browser.

Wild

3D parallax β€” tilt a flat photo with your mouse and feel the depth.

Multi-model

Depth + background removal β†’ a pop-out composite: sharp subject over a depth-blurred scene.

How the API works

Depth is a one-liner with Transformers.js. The pipeline returns both a ready-to-display image and the raw tensor:

import { pipeline } from "@huggingface/transformers";

const estimator = await pipeline(
  "depth-estimation",
  "onnx-community/depth-anything-v2-small",
  { device: "webgpu", dtype: "fp16" },   // ~100 MB, cached after first load
);

const { depth, predicted_depth } = await estimator(imageURL);
// depth          β†’ RawImage: grayscale, min–max normalized to 0–255 (great for display)
// predicted_depth β†’ Tensor:  the raw per-pixel relative depth (dims = [H, W]); bigger = nearer

This page colourises depth on a canvas and reads predicted_depth for the real range + distribution in "See inside". Inference runs in a Web Worker, so estimating a large photo never freezes the page.

References