depth-estimation Β· vision Β· WebGPU (fp16) Β· ~100 MB
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.
| Model | onnx-community/depth-anything-v2-small |
|---|---|
| Task / pipeline | depth-estimation β monocular (single-image) relative depth |
| Architecture | DINOv2 ViT-S encoder + DPT depth head β one depth value per pixel |
| Quantization | fp16 (half precision) ONNX |
| Backend | WebGPU (fp16); falls back to WebAssembly where WebGPU is absent |
| Download | ~100 MB, cached after first load |
| License | Apache-2.0 (Depth Anything V2 Small) |
| Web APIs | WebGPU, Web Workers, Canvas 2D, FileReader β WebGPU is the only non-Baseline piece, and the page says so if it's missing |
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.
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.
| predicted_depth shape | β |
|---|---|
| raw depth range | β |
| mean raw depth | β |
| pixels estimated | β |
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:
One photo in, a colourised depth map out β read distance as colour.
Depth-driven background blur β fake a portrait-mode lens in the browser.
3D parallax β tilt a flat photo with your mouse and feel the depth.
Depth + background removal β a pop-out composite: sharp subject over a depth-blurred scene.
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.