Downloads · 30 days
3
5% of all-time downloads
keras/depth_anything_v2_base
depth_anything_v2_base is a machine learning model from keras. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for keras-hub.
Depth Anything V2 is a family of monocular depth estimation (MDE) models that represent a significant leap forward in generating high-quality, fine-grained depth maps from single images. Built upon the success of the…
Downloads · 30 days
3
5% of all-time downloads
All-time downloads
56
Public
Repo size
395 MB
Likes
0
Public
Click a slice to open those files.
.h5395 MB · 100%
From the Hugging Face model README
Depth Anything V2 is a family of monocular depth estimation (MDE) models that represent a significant leap forward in generating high-quality, fine-grained depth maps from single images. Built upon the success of the original Depth Anything, V2 is trained on a massive dataset comprising 595K synthetic labeled images and over 62M real unlabeled images. This hybrid training strategy allows the model to capture intricate details while remaining robust to diverse real-world scenarios. Depth-Anything-V2 is designed to be a versatile backbone for any computer vision pipeline requiring spatial awareness, offering three main variants (Small, Base, and Large) to balance performance and computational cost.
Depth-Anything-V2 utilizes a "Large-Scale Unlabeled Data" approach combined with high-quality synthetic data. The synthetic data provides precise ground-truth depth labels, while the unlabeled real images allow the model to learn a broad and robust representation of the physical world. The training pipeline focuses on relative depth estimation with a high degree of zero-shot generalization.
Weights for the Small variant are released under the Apache 2.0 License, while the Base and Large variants are released under the CC-BY-NC-4.0 License.
Keras and KerasHub can be installed with:
pip install -U -q keras-hub
pip install -U -q keras
The following model checkpoints are available. Use the preset names below to load the models.
| Preset | Parameters | Description |
|---|---|---|
depth_anything_v2_small | ~24.8M | The most lightweight variant, based on ViT-Small. Ideal for real-time mobile and edge applications. |
depth_anything_v2_base | ~97.5M | A mid-sized model based on ViT-Base. Offers a strong balance between speed and precision. |
depth_anything_v2_large | ~335.3M | The most powerful variant based on ViT-Large. Delivers state-of-the-art accuracy and fine-grained depth detail. |
import keras
import numpy as np
import requests
from PIL import Image
from keras_hub.src.models.depth_anything.depth_anything_depth_estimator import (
DepthAnythingDepthEstimator,
)
image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = image.resize((518, 518))
depth_estimator = DepthAnythingDepthEstimator.from_preset(
"depth_anything_v2_base,
depth_estimation_type="relative",
max_depth=None,
)
images = np.expand_dims(np.array(image).astype("float32"), axis=0)
outputs = depth_estimator.predict({"images": images})["depths"]
depth = keras.ops.nn.relu(outputs[0, ..., 0])
depth = (depth - keras.ops.min(depth)) / (
keras.ops.max(depth) - keras.ops.min(depth)
)
depth = keras.ops.convert_to_numpy(depth) * 255
Image.fromarray(depth.astype("uint8")).save("depth_map.png")
import keras
import numpy as np
import requests
from PIL import Image
from keras_hub.src.models.depth_anything.depth_anything_depth_estimator import (
DepthAnythingDepthEstimator,
)
image = Image.open(requests.get("http://images.cocodataset.org/val2017/000000039769.jpg", stream=True).raw)
image = image.resize((518, 518))
depth_estimator = DepthAnythingDepthEstimator.from_preset(
"hf://keras/depth_anything_v2_base,
depth_estimation_type="relative",
max_depth=None,
)
images = np.expand_dims(np.array(image).astype("float32"), axis=0)
outputs = depth_estimator.predict({"images": images})["depths"]
depth = keras.ops.nn.relu(outputs[0, ..., 0])
depth = (depth - keras.ops.min(depth)) / (
keras.ops.max(depth) - keras.ops.min(depth)
)
depth = keras.ops.convert_to_numpy(depth) * 255
Image.fromarray(depth.astype("uint8")).save("depth_map.png")