Depth estimation
Depth Anything V2 Small
Sees how far away every part of a photo is, from a single image: the small, Apache-2.0 version of the leading monocular depth model.
About this model
Depth Anything V2 estimates depth from one ordinary photo: for every pixel, how near or far it is relative to the rest of the scene. It works on indoor and outdoor scenes, people, objects and landscapes without any setup.
The Small model (24.8 million parameters) uses a DINOv2 ViT-S encoder and a DPT decoder, trained on synthetic images with precise depth and then on 62 million real images labeled by a larger teacher model.
The output is relative inverse depth: larger values are nearer, and values compare only within one photo (there are no meters). depth_map() shows it as an image; depth_at(x, y) gives the value at a pixel.
What you can build
- Blur or replace the background behind the subject (portrait effects)
- Separate foreground from background for AR and photo editing
- Order objects by distance or find the nearest thing in front of a camera
- 3D-photo and parallax effects from a single image
People crossing street
f16Mike Petrucci mikepetrucci, CC0, https://commons.wikimedia.org/wiki/File:People_crossing_street_(Unsplash).jpg
depth_map() on the Metal (FP16 pack), drawn near pale yellow to far dark blue. depth_at() down the middle: top 0.00, centre 0.27, bottom 10.19 (larger is nearer).
Harbor boats
f16W.carter, Public domain, https://commons.wikimedia.org/wiki/File:North_Harbor_Lysekil_with_motor_boat.jpg
depth_map() on the Metal (FP16 pack), drawn near pale yellow to far dark blue. depth_at() down the middle: top 0.00, centre 1.44, bottom 7.17 (larger is nearer).
Cyclists road
f16Judgefloro, CC0, https://commons.wikimedia.org/wiki/File:0014Outdoor_location_photo_shoot_group_photographs_of_deaf-mute_road_cyclists_34.jpg
depth_map() on the Metal (FP16 pack), drawn near pale yellow to far dark blue. depth_at() down the middle: top 0.00, centre 3.06, bottom 5.18 (larger is nearer).
Variants & downloads
Choose the build for your appModel files are hosted on Google Drive. Large files may open a confirmation page before downloading.
Small
SlabWeights stored as int8 in blocks of 64. Slab decodes them to float when loading, so it runs at the same speed; depth moves slightly more than with FP16 (see Accuracy).
Platforms: macos · android
depth-anything-v2-small-int8.slab
30.6 MB · Hosted download
SHA-256 checksum
ec710b1ed24d7c9efe90f6c6351291c31f9148f38dacea7ef7c0fc75196aa34eLICENSE-Depth-Anything-V2.txt
11 KB
SHA-256 checksum
8b21a7ca65452932f2f1418faf0e89fbdef475974b5ebef02a0552313d6e251cConversion details
- command
- git clone https://github.com/DepthAnything/Depth-Anything-V2 && git -C Depth-Anything-V2 checkout a561b849ebae10a6f5ef49e26c83cbbcd36c71bf curl -L -o depth_anything_v2_vits.pth https://huggingface.co/depth-anything/Depth-Anything-V2-Small/resolve/03876f8651c73a60fe4c2c48294e09fcb6838fcf/depth_anything_v2_vits.pth python -c "import sys, torch; sys.path.insert(0, 'Depth-Anything-V2'); from depth_anything_v2.dpt import DepthAnythingV2; m = DepthAnythingV2(encoder='vits', features=64, out_channels=[48, 96, 192, 384]); m.load_state_dict(torch.load('depth_anything_v2_vits.pth', map_location='cpu', weights_only=True)); torch.onnx.export(m.eval(), torch.randn(1, 3, 518, 518), 'model.onnx', input_names=['image'], output_names=['depth'], opset_version=17, dynamo=False)" slab-load convert model.onnx model.slab --input image=1x3x518x518 --meta task=depth --meta resize=stretch --meta interpolation=bicubic --meta normalize=imagenet --meta color=rgb slab-load quantize model.slab depth-anything-v2-small-int8.slab slab-load meta set depth-anything-v2-small-int8.slab default_backend.macos=gpu
Integration examples
Python
python
import slab
cfg = slab.Config(cache_dir="/tmp/slab_cache", license=open("license.slablic.txt").read())
session = slab.Session(cfg, "depth-anything-v2-small-f16.slab", warmup=True)
photo = slab.Frame.open("photo.jpg")
out = session.run(slab.Input(frame=photo))
view = out.depth_map() # Gray8 Frame, the photo's size: 255 nearest, 0 farthest
print(out.depth_at(photo.width / 2, photo.height / 2)) # raw value at the centre (larger is nearer)
Device & backend compatibility
Pack default: macos / GPU. The fastest backend on the Mac (about 28 ms per photo); the Neural Engine takes 65 ms and 35 s to prepare.
| Platform | Engine | Status | Precision |
|---|---|---|---|
| apple | CPU CPU | Supported Measured on macOS. | f32 |
| apple | Metal GPU | Supported Measured on macOS. The default. | f32 |
| apple | Apple Neural Engine NPU | Supported Measured on macOS. The Neural Engine computes in FP16. | f16 |
| android | CPU CPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. | f32 |
| android | Vulkan GPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. | f32 |
| android | Qualcomm Hexagon NPU (QNN) NPU | Not supported Tried on a Samsung Galaxy S23 Ultra (Hexagon v73): One of the model's nodes does not translate to QNN in Slab yet. | — |
Performance
Results depend on the device, runtime, and test conditions. Each measurement keeps its own context.
Mac with Apple M1 Max
Slab · CPU
macOS 26.6.2
562.6 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 552.9 ms median. depth_map() at 1920 x 1080 adds about 9 ms; depth_at() under a microsecond.
Mac with Apple M1 Max
Slab · GPU
macOS 26.6.2
27.6 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 29.0 ms median. depth_map() at 1920 x 1080 adds about 9 ms; depth_at() under a microsecond.
Mac with Apple M1 Max
Slab · NPU
macOS 26.6.2
65.1 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 65.5 ms median. depth_map() at 1920 x 1080 adds about 9 ms; depth_at() under a microsecond.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · CPU
Android 17
2.35 s
Measured time · scope below
Median of 10 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 2097 ms median. open_ms: opening the session. Peak memory (resident) after the runs: 357 MB.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · GPU
Android 17
570.0 ms
Measured time · scope below
Median of 17 warm runs of the model (Slab's run time). From a 1920 x 1080 photo, resizing included: 571 ms median. open_ms: opening the session with the GPU programs already in the cache folder (the first open on a device compiles them, about 0.3 s more). Peak memory (resident) after the runs: 172 MB.
Accuracy checks
macos · CPU · int8
The upstream PyTorch model on the same 518 x 518 stretch (PIL bicubic), its output resized bilinearly to the photo; 23 public-domain and CC0 photos (Wikimedia Commons). Depth is relative, so Slab's depth_map() is fitted to the reference by scale and shift before scoring
Correlation 0.9995 (0.9980 on the worst photo), remaining error 0.84% of the depth range. On identical input tensors the raw output is within 2.3e-01 of PyTorch (relative to its largest value). Against the upstream infer_image (aspect ratio kept, short side 518, OpenCV bicubic): correlation 0.9964, error 2.21%.
macos · GPU · int8
The upstream PyTorch model on the same 518 x 518 stretch (PIL bicubic), its output resized bilinearly to the photo; 23 public-domain and CC0 photos (Wikimedia Commons). Depth is relative, so Slab's depth_map() is fitted to the reference by scale and shift before scoring
Correlation 0.9995 (0.9980 on the worst photo), remaining error 0.84% of the depth range. On identical input tensors the raw output is within 2.3e-01 of PyTorch (relative to its largest value). Against the upstream infer_image (aspect ratio kept, short side 518, OpenCV bicubic): correlation 0.9964, error 2.21%.
macos · NPU · int8
The upstream PyTorch model on the same 518 x 518 stretch (PIL bicubic), its output resized bilinearly to the photo; 23 public-domain and CC0 photos (Wikimedia Commons). Depth is relative, so Slab's depth_map() is fitted to the reference by scale and shift before scoring
Correlation 0.9995 (0.9979 on the worst photo), remaining error 0.84% of the depth range. On identical input tensors the raw output is within 2.6e-01 of PyTorch (relative to its largest value). Against the upstream infer_image (aspect ratio kept, short side 518, OpenCV bicubic): correlation 0.9965, error 2.21%.
Before you choose this model
- Relative depth only: no distances in meters, and values from two photos are not comparable.
- Mirrors, glass and screens can confuse it.
- The pack runs at a fixed 518 x 518 and stretches the photo to it. The upstream script keeps the aspect ratio; across our photos the two maps correlate at 0.9965 (2.2% of the range apart after matching scale and shift).
- On the Neural Engine it takes about 35 s to prepare; use the GPU.
- Only the Small model is Apache-2.0; Depth Anything V2 Base and Large are non-commercial.