depth-estimation Β· vision Β· WebGPU (fp16) / WASM (q8) Β· ~210 MB
Before Depth Anything, there was DPT: the 2021 Dense Prediction Transformer that first
showed a Vision Transformer could read distance out of a single photo. This is Intel's
dpt-hybrid-midas β a ViT-hybrid encoder trained the MiDaS way β running entirely on
your device. One flat photo in, a distance-per-pixel map out. The photo never leaves the tab.
| Model | Xenova/dpt-hybrid-midas (ONNX port of Intel/dpt-hybrid-midas) |
|---|---|
| Task / pipeline | depth-estimation β monocular (single-image) relative depth |
| Architecture | DPT: ViT-hybrid encoder (ResNet-50 stem β ViT-Base) + DPT decode head, MiDaS-trained β one depth value per pixel |
| Quantization | fp16 (WebGPU) / q8 8-bit (WASM) ONNX |
| Backend | WebGPU (fp16) when a real adapter exists; otherwise WebAssembly (q8) β honest fallback, still real inference |
| Download | ~210 MB (q8) / ~267 MB (fp16), cached after first load |
| License | Apache-2.0 (Intel DPT / MiDaS) |
| Web APIs | WebGPU, Web Workers, Canvas 2D, FileReader β WebGPU is the only non-Baseline piece, and the page says so if it's missing |
DPT-Hybrid is a bigger, older model than Depth Anything Small, so on the CPU (WASM) path the first estimate after loading can take several seconds β honest progress is shown, and it is genuinely running on your device.
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.
DPT doesn't output a picture β it outputs a tensor of real numbers, one per pixel: raw relative inverse depth (MiDaS convention β 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 | β |
Both give you a per-pixel depth map from one photo, and both normalise to the same brighter-is-nearer image β so they're drop-in swappable in an app. What differs is what's under the hood, and it shows up in the details each one recovers.
| DPT (this page) | Depth Anything v2 | |
|---|---|---|
| Backbone | ViT-hybrid (ResNet-50 stem + ViT-Base) | DINOv2 self-supervised ViT |
| Training | MiDaS multi-dataset mix (2021) | 62M unlabelled + pseudo-labelled images (2024) |
| Output | relative inverse depth | relative inverse depth |
| Size (q8) | ~210 MB | ~40β100 MB |
| Feel | solid global geometry, softer fine edges | crisper thin structures & edges |
Want to compare on the same photo? Open Depth Anything Basics in another tab and run the same sample.
Depth used to need special hardware β a stereo rig, a LiDAR sensor, a structured-light camera. DPT estimates it from a single frame, and it's small and standard 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.
DPT + SegFormer β how far away is each thing? Depth averaged per semantic class.
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",
"Xenova/dpt-hybrid-midas",
{ device: "webgpu", dtype: "fp16" }, // ~267 MB fp16 / ~210 MB q8, 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 inverse depth (dims = [H, W]); bigger = nearer
The pipeline id and output shape are identical to Depth Anything's β only the model string
changes β so swapping depth backbones is a one-line edit. 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.