What is Depth Anything V2?
Depth Anything V2 is a model that takes a single RGB image and predicts a depth map, an estimate of how far each pixel is from the camera. It sits in the Vision & Understanding category of the Multimodal Generation tools and is open-source, written in Python. To get started: install.
Overview
Depth Anything V2 is a model that takes a single RGB image and predicts a depth map, an estimate of how far each pixel is from the camera. It targets relative depth across any scene, so you can feed it indoor, outdoor, or general photos without a calibrated setup.
It is aimed at computer-vision developers and researchers who need depth without a stereo rig, LiDAR, or special hardware. The project ships four pre-trained sizes (Small at 24.8M params up to Giant at 1.3B), so you can trade accuracy against speed and memory for your hardware.
In the multimodal computer-vision category, it sits among monocular depth estimators and improves on V1 in fine detail and robustness. You can use it from the project's own PyTorch code or load it through Hugging Face Transformers, and there are command-line scripts for both images and videos.
What it does
- Single-image (monocular) depth estimation that works across indoor, outdoor, and general scenes
- Four pre-trained model scales (Small, Base, Large, and an upcoming Giant) to balance accuracy, speed, and memory
- Runs on CUDA, Apple MPS, or CPU; device is selected automatically in the sample code
- Loadable two ways: the project's own PyTorch API or the Hugging Face Transformers depth-estimation pipeline
- Command-line scripts for batch image folders (run.py) and for videos (run_video.py)
- Adjustable input size (default 518) to trade speed for more fine-grained results
Getting started
Clone the repo, install the Python dependencies, download a checkpoint, then run inference on an image in a few lines of PyTorch.
Install
Clone the repository and install its requirements with pip.
git clone https://github.com/DepthAnything/Depth-Anything-V2
cd Depth-Anything-V2
pip install -r requirements.txtDownload a checkpoint
Download a model checkpoint (Small, Base, or Large) from Hugging Face and put it under the checkpoints directory.
Run inference in Python
Load the encoder you downloaded and call infer_image to get an HxW depth map as a NumPy array.
import cv2
import torch
from depth_anything_v2.dpt import DepthAnythingV2
DEVICE = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
model_configs = {
'vits': {'encoder': 'vits', 'features': 64, 'out_channels': [48, 96, 192, 384]},
'vitb': {'encoder': 'vitb', 'features': 128, 'out_channels': [96, 192, 384, 768]},
'vitl': {'encoder': 'vitl', 'features': 256, 'out_channels': [256, 512, 1024, 1024]},
'vitg': {'encoder': 'vitg', 'features': 384, 'out_channels': [1536, 1536, 1536, 1536]}
}
encoder = 'vitl' # or 'vits', 'vitb', 'vitg'
model = DepthAnythingV2(**model_configs[encoder])
model.load_state_dict(torch.load(f'checkpoints/depth_anything_v2_{encoder}.pth', map_location='cpu'))
model = model.to(DEVICE).eval()
raw_img = cv2.imread('your/image/path')
depth = model.infer_image(raw_img) # HxW raw depth map in numpyOr use Hugging Face Transformers
If you do not want to clone the repo, load the model through the Transformers depth-estimation pipeline (predictions may differ slightly due to a resizing difference).
from transformers import pipeline
from PIL import Image
pipe = pipeline(task="depth-estimation", model="depth-anything/Depth-Anything-V2-Small-hf")
image = Image.open('your/image/path')
depth = pipe(image)["depth"]Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Generate a depth map from a single photo when you have no stereo camera or LiDAR
- Add depth cues to 3D reconstruction, AR, or background-blur (bokeh) pipelines
- Batch-process a folder of images or run depth on a video with the included CLI scripts
- Compare model sizes to fit a depth estimator onto constrained hardware (CPU, MPS, or GPU)
How Depth Anything V2 compares
Depth Anything V2 alongside other open-source vision & understanding tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| PaddleOCR | ★ 93.5k | A toolkit for detecting and recognizing text in images across many languages, plus document parsing. |
| OpenCV | ★ 91.8k | The long-standing open-source computer-vision library for C++, Python and Java; version 5 rewrote the DNN engine and added ONNX-based LLM and VLM inference in-library. |
| Ultralytics YOLO | ★ 63.9k | A framework for training and running YOLO models for real-time object detection, segmentation, and tracking. |
| YOLOv5 | ★ 58.3k | Ultralytics' PyTorch repo for training, running and exporting YOLOv5 object-detection, instance-segmentation and classification models with plain scripts and PyTorch Hub. |
| Supervision | ★ 51.8k | A Python toolkit for processing, annotating, and visualizing detections and segmentations from many vision models. |
| MediaPipe | ★ 38k | Google's on-device ML framework: ready-to-run vision, text and audio tasks with one cross-platform API for Android, iOS, web, desktop and edge. |
| MMDetection | ★ 33.1k | An OpenMMLab toolbox with many object detection and instance segmentation algorithms for research and production. |
| Depth Anything V2 | ★ 9.3k | Estimate depth from a single image for any scene |

