Instructions to use zeromodels/depth_anything_v2_small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/depth_anything_v2_small with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/depth_anything_v2_small") - DepthAnythingV2
How to use zeromodels/depth_anything_v2_small with DepthAnythingV2:
# Install from https://github.com/DepthAnything/Depth-Anything-V2 # Load the model and infer depth from an image import cv2 import torch from depth_anything_v2.dpt import DepthAnythingV2 # instantiate the model model = DepthAnythingV2(encoder="<ENCODER>", features=<NUMBER_OF_FEATURES>, out_channels=<OUT_CHANNELS>) # load the weights filepath = hf_hub_download(repo_id="zeromodels/depth_anything_v2_small", filename="depth_anything_v2_<ENCODER>.pth", repo_type="model") state_dict = torch.load(filepath, map_location="cpu") model.load_state_dict(state_dict).eval() raw_img = cv2.imread("your/image/path") depth = model.infer_image(raw_img) # HxW raw depth map in numpy - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +21 -21
- kf_config.json → zm_config.json +37 -37
- kf_preprocessor.json → zm_preprocessor.json +18 -18
README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
pipeline_tag: depth-estimation
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: depth-anything/Depth-Anything-V2-Small-hf
|
| 5 |
-
library_name:
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
-
-
|
| 9 |
- depth-anything-v2
|
| 10 |
- depth-estimation
|
| 11 |
- arxiv:2406.09414
|
|
@@ -14,13 +14,13 @@ tags:
|
|
| 14 |
- tf
|
| 15 |
---
|
| 16 |
|
| 17 |
-
## ***See [our collection](https://huggingface.co/collections/
|
| 18 |
|
| 19 |
# Run Depth Anything V2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 20 |
|
| 21 |
-
[](https://arxiv.org/abs/2406.09414) · [HF Papers](https://huggingface.co/papers/2406.09414)
|
| 26 |
|
|
@@ -28,7 +28,7 @@ Depth Anything V2 keeps V1's architecture and improves data (synthetic labels pl
|
|
| 28 |
|
| 29 |
For more details on the model, please go to the upstream [model card](https://huggingface.co/depth-anything/Depth-Anything-V2-Small-hf).
|
| 30 |
|
| 31 |
-
Pure-**Keras 3** conversion of [`depth-anything/Depth-Anything-V2-Small-hf`](https://huggingface.co/depth-anything/Depth-Anything-V2-Small-hf) for [
|
| 32 |
|
| 33 |
This is a **monocular depth** checkpoint (`DepthAnythingV2DepthEstimation`, relative).
|
| 34 |
|
|
@@ -39,10 +39,10 @@ import os
|
|
| 39 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 40 |
|
| 41 |
from PIL import Image
|
| 42 |
-
from
|
| 43 |
|
| 44 |
-
model = DepthAnythingV2DepthEstimation.from_weights("
|
| 45 |
-
processor = DepthAnythingV2ImageProcessor.from_weights("
|
| 46 |
|
| 47 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 48 |
output = model(processor(image)["pixel_values"], training=False)
|
|
@@ -52,25 +52,25 @@ depth = processor.post_process_depth_estimation(
|
|
| 52 |
print(depth.shape)
|
| 53 |
```
|
| 54 |
|
| 55 |
-
Load any Depth Anything V2 variant the same way with `from_weights("
|
| 56 |
|
| 57 |
| Variant | Hub | Output |
|
| 58 |
|---|---|---|
|
| 59 |
-
| `depth_anything_v2_small` | [`
|
| 60 |
-
| `depth_anything_v2_base` | [`
|
| 61 |
-
| `depth_anything_v2_large` | [`
|
| 62 |
-
| `depth_anything_v2_metric_indoor_small` | [`
|
| 63 |
-
| `depth_anything_v2_metric_indoor_base` | [`
|
| 64 |
-
| `depth_anything_v2_metric_indoor_large` | [`
|
| 65 |
-
| `depth_anything_v2_metric_outdoor_small` | [`
|
| 66 |
-
| `depth_anything_v2_metric_outdoor_base` | [`
|
| 67 |
-
| `depth_anything_v2_metric_outdoor_large` | [`
|
| 68 |
|
| 69 |
## Tips
|
| 70 |
|
| 71 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 72 |
- Indoor and outdoor metric heads are not interchangeable.
|
| 73 |
-
- See [Depth Anything V2 docs]({DOCS_URL}) and [Loading Weights](https://imvision12.github.io/
|
| 74 |
- Community / upstream weights: `DepthAnythingV2DepthEstimation.from_weights("hf:depth-anything/Depth-Anything-V2-Small-hf")`.
|
| 75 |
|
| 76 |
## Special Thanks
|
|
|
|
| 2 |
pipeline_tag: depth-estimation
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: depth-anything/Depth-Anything-V2-Small-hf
|
| 5 |
+
library_name: zeromodels
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
- depth-anything-v2
|
| 10 |
- depth-estimation
|
| 11 |
- arxiv:2406.09414
|
|
|
|
| 14 |
- tf
|
| 15 |
---
|
| 16 |
|
| 17 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/depth-anything-v1-and-v2-6a6a965e3e9e4847e424dde2) for all versions of Depth Anything V2.***
|
| 18 |
|
| 19 |
# Run Depth Anything V2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 20 |
|
| 21 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/depth_anything_v2/) [](https://huggingface.co/collections/zeromodels/depth-anything-v1-and-v2-6a6a965e3e9e4847e424dde2)
|
| 22 |
|
| 23 |
+
# zeromodels/depth_anything_v2_small
|
| 24 |
|
| 25 |
Paper: [Depth Anything V2 (arXiv:2406.09414)](https://arxiv.org/abs/2406.09414) · [HF Papers](https://huggingface.co/papers/2406.09414)
|
| 26 |
|
|
|
|
| 28 |
|
| 29 |
For more details on the model, please go to the upstream [model card](https://huggingface.co/depth-anything/Depth-Anything-V2-Small-hf).
|
| 30 |
|
| 31 |
+
Pure-**Keras 3** conversion of [`depth-anything/Depth-Anything-V2-Small-hf`](https://huggingface.co/depth-anything/Depth-Anything-V2-Small-hf) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 32 |
|
| 33 |
This is a **monocular depth** checkpoint (`DepthAnythingV2DepthEstimation`, relative).
|
| 34 |
|
|
|
|
| 39 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 40 |
|
| 41 |
from PIL import Image
|
| 42 |
+
from zeromodels.models.depth_anything_v2 import DepthAnythingV2DepthEstimation, DepthAnythingV2ImageProcessor
|
| 43 |
|
| 44 |
+
model = DepthAnythingV2DepthEstimation.from_weights("zeromodels/depth_anything_v2_small")
|
| 45 |
+
processor = DepthAnythingV2ImageProcessor.from_weights("zeromodels/depth_anything_v2_small")
|
| 46 |
|
| 47 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 48 |
output = model(processor(image)["pixel_values"], training=False)
|
|
|
|
| 52 |
print(depth.shape)
|
| 53 |
```
|
| 54 |
|
| 55 |
+
Load any Depth Anything V2 variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 56 |
|
| 57 |
| Variant | Hub | Output |
|
| 58 |
|---|---|---|
|
| 59 |
+
| `depth_anything_v2_small` | [`zeromodels/depth_anything_v2_small`](https://huggingface.co/zeromodels/depth_anything_v2_small) | relative |
|
| 60 |
+
| `depth_anything_v2_base` | [`zeromodels/depth_anything_v2_base`](https://huggingface.co/zeromodels/depth_anything_v2_base) | relative |
|
| 61 |
+
| `depth_anything_v2_large` | [`zeromodels/depth_anything_v2_large`](https://huggingface.co/zeromodels/depth_anything_v2_large) | relative |
|
| 62 |
+
| `depth_anything_v2_metric_indoor_small` | [`zeromodels/depth_anything_v2_metric_indoor_small`](https://huggingface.co/zeromodels/depth_anything_v2_metric_indoor_small) | metric indoor |
|
| 63 |
+
| `depth_anything_v2_metric_indoor_base` | [`zeromodels/depth_anything_v2_metric_indoor_base`](https://huggingface.co/zeromodels/depth_anything_v2_metric_indoor_base) | metric indoor |
|
| 64 |
+
| `depth_anything_v2_metric_indoor_large` | [`zeromodels/depth_anything_v2_metric_indoor_large`](https://huggingface.co/zeromodels/depth_anything_v2_metric_indoor_large) | metric indoor |
|
| 65 |
+
| `depth_anything_v2_metric_outdoor_small` | [`zeromodels/depth_anything_v2_metric_outdoor_small`](https://huggingface.co/zeromodels/depth_anything_v2_metric_outdoor_small) | metric outdoor |
|
| 66 |
+
| `depth_anything_v2_metric_outdoor_base` | [`zeromodels/depth_anything_v2_metric_outdoor_base`](https://huggingface.co/zeromodels/depth_anything_v2_metric_outdoor_base) | metric outdoor |
|
| 67 |
+
| `depth_anything_v2_metric_outdoor_large` | [`zeromodels/depth_anything_v2_metric_outdoor_large`](https://huggingface.co/zeromodels/depth_anything_v2_metric_outdoor_large) | metric outdoor |
|
| 68 |
|
| 69 |
## Tips
|
| 70 |
|
| 71 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 72 |
- Indoor and outdoor metric heads are not interchangeable.
|
| 73 |
+
- See [Depth Anything V2 docs]({DOCS_URL}) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 74 |
- Community / upstream weights: `DepthAnythingV2DepthEstimation.from_weights("hf:depth-anything/Depth-Anything-V2-Small-hf")`.
|
| 75 |
|
| 76 |
## Special Thanks
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,38 +1,38 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "DepthAnythingV2DepthEstimation",
|
| 6 |
-
"variant": "depth_anything_v2_small",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "depth_anything",
|
| 11 |
-
"vision_config": {
|
| 12 |
-
"backbone_dim": 384,
|
| 13 |
-
"backbone_depth": 12,
|
| 14 |
-
"backbone_num_heads": 6,
|
| 15 |
-
"out_indices": [
|
| 16 |
-
3,
|
| 17 |
-
6,
|
| 18 |
-
9,
|
| 19 |
-
12
|
| 20 |
-
],
|
| 21 |
-
"neck_hidden_sizes": [
|
| 22 |
-
48,
|
| 23 |
-
96,
|
| 24 |
-
192,
|
| 25 |
-
384
|
| 26 |
-
],
|
| 27 |
-
"fusion_hidden_size": 64,
|
| 28 |
-
"reassemble_factors": [
|
| 29 |
-
4,
|
| 30 |
-
2,
|
| 31 |
-
1,
|
| 32 |
-
0.5
|
| 33 |
-
],
|
| 34 |
-
"depth_estimation_type": "relative",
|
| 35 |
-
"max_depth": 1.0,
|
| 36 |
-
"image_size": 518
|
| 37 |
-
}
|
| 38 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.depth_anything_v2",
|
| 5 |
+
"model_class": "DepthAnythingV2DepthEstimation",
|
| 6 |
+
"variant": "depth_anything_v2_small",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "depth_anything",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"backbone_dim": 384,
|
| 13 |
+
"backbone_depth": 12,
|
| 14 |
+
"backbone_num_heads": 6,
|
| 15 |
+
"out_indices": [
|
| 16 |
+
3,
|
| 17 |
+
6,
|
| 18 |
+
9,
|
| 19 |
+
12
|
| 20 |
+
],
|
| 21 |
+
"neck_hidden_sizes": [
|
| 22 |
+
48,
|
| 23 |
+
96,
|
| 24 |
+
192,
|
| 25 |
+
384
|
| 26 |
+
],
|
| 27 |
+
"fusion_hidden_size": 64,
|
| 28 |
+
"reassemble_factors": [
|
| 29 |
+
4,
|
| 30 |
+
2,
|
| 31 |
+
1,
|
| 32 |
+
0.5
|
| 33 |
+
],
|
| 34 |
+
"depth_estimation_type": "relative",
|
| 35 |
+
"max_depth": 1.0,
|
| 36 |
+
"image_size": 518
|
| 37 |
+
}
|
| 38 |
}
|
kf_preprocessor.json → zm_preprocessor.json
RENAMED
|
@@ -1,19 +1,19 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"preprocessor_module": "
|
| 5 |
-
"preprocessor_class": "DepthAnythingV2ImageProcessor",
|
| 6 |
-
"variant": "depth_anything_v2_small",
|
| 7 |
-
"target_size": 518,
|
| 8 |
-
"image_mean": [
|
| 9 |
-
0.485,
|
| 10 |
-
0.456,
|
| 11 |
-
0.406
|
| 12 |
-
],
|
| 13 |
-
"image_std": [
|
| 14 |
-
0.229,
|
| 15 |
-
0.224,
|
| 16 |
-
0.225
|
| 17 |
-
],
|
| 18 |
-
"data_format": null
|
| 19 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.1.3",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.depth_anything_v2",
|
| 5 |
+
"preprocessor_class": "DepthAnythingV2ImageProcessor",
|
| 6 |
+
"variant": "depth_anything_v2_small",
|
| 7 |
+
"target_size": 518,
|
| 8 |
+
"image_mean": [
|
| 9 |
+
0.485,
|
| 10 |
+
0.456,
|
| 11 |
+
0.406
|
| 12 |
+
],
|
| 13 |
+
"image_std": [
|
| 14 |
+
0.229,
|
| 15 |
+
0.224,
|
| 16 |
+
0.225
|
| 17 |
+
],
|
| 18 |
+
"data_format": null
|
| 19 |
}
|