Instructions to use zeromodels/dinov2-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/dinov2-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/dinov2-small") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +76 -76
- kf_config.json → zm_config.json +27 -27
- kf_preprocessor.json → zm_preprocessor.json +22 -22
README.md
CHANGED
|
@@ -1,76 +1,76 @@
|
|
| 1 |
-
---
|
| 2 |
-
pipeline_tag: image-feature-extraction
|
| 3 |
-
license: apache-2.0
|
| 4 |
-
base_model: facebook/dinov2-small
|
| 5 |
-
library_name:
|
| 6 |
-
tags:
|
| 7 |
-
- keras
|
| 8 |
-
-
|
| 9 |
-
- dinov2
|
| 10 |
-
- feature-extraction
|
| 11 |
-
- vision
|
| 12 |
-
- arxiv:2304.07193
|
| 13 |
-
- pytorch
|
| 14 |
-
- jax
|
| 15 |
-
- tf
|
| 16 |
-
---
|
| 17 |
-
|
| 18 |
-
## ***See [our collection](https://huggingface.co/collections/
|
| 19 |
-
|
| 20 |
-
# Run DINOv2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
-
|
| 22 |
-
[](https://arxiv.org/abs/2304.07193) · [HF Papers](https://huggingface.co/papers/2304.07193)
|
| 27 |
-
|
| 28 |
-
DINOv2 scales self-supervised ViT pretraining for strong transferable visual features without labels. These checkpoints are backbones that return patch tokens for downstream heads.
|
| 29 |
-
|
| 30 |
-
For more details on the model, please go to the upstream [model card](https://huggingface.co/facebook/dinov2-small).
|
| 31 |
-
|
| 32 |
-
Pure-**Keras 3** conversion of [`facebook/dinov2-small`](https://huggingface.co/facebook/dinov2-small) for [
|
| 33 |
-
|
| 34 |
-
This is a **self-supervised backbone** (`DinoV2Model`), not a task head.
|
| 35 |
-
|
| 36 |
-
## ✨ Quick start
|
| 37 |
-
|
| 38 |
-
```python
|
| 39 |
-
import os
|
| 40 |
-
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 41 |
-
|
| 42 |
-
from
|
| 43 |
-
|
| 44 |
-
# The processor resizes + ImageNet-normalizes, so build the model with
|
| 45 |
-
# include_normalization=False (it would otherwise normalize a second time).
|
| 46 |
-
model = DinoV2Model.from_weights(
|
| 47 |
-
"
|
| 48 |
-
)
|
| 49 |
-
processor = DinoV2ImageProcessor.from_weights("
|
| 50 |
-
|
| 51 |
-
pixel_values = processor("your_image.jpg")["pixel_values"]
|
| 52 |
-
features = model(pixel_values, training=False)
|
| 53 |
-
print(pixel_values.shape, features.shape)
|
| 54 |
-
```
|
| 55 |
-
|
| 56 |
-
Load any DINOv2 variant the same way with `from_weights("
|
| 57 |
-
|
| 58 |
-
| Variant | Hub | Backbone |
|
| 59 |
-
|---|---|---|
|
| 60 |
-
| `dinov2-small` | [`
|
| 61 |
-
| `dinov2-base` | [`
|
| 62 |
-
| `dinov2-large` | [`
|
| 63 |
-
| `dinov2-giant` | [`
|
| 64 |
-
|
| 65 |
-
## Tips
|
| 66 |
-
|
| 67 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 68 |
-
- The processor normalizes; pair it with `include_normalization=False`. To skip it, feed raw `[0, 255]` pixels and keep the default `include_normalization=True`.
|
| 69 |
-
- See [DINOv2 docs](https://imvision12.github.io/
|
| 70 |
-
- Community / upstream weights: `DinoV2Model.from_weights("hf:facebook/dinov2-small")`.
|
| 71 |
-
|
| 72 |
-
## Special Thanks
|
| 73 |
-
|
| 74 |
-
A huge thank you to the Facebook AI Research DINOv2 authors for creating and releasing these models.
|
| 75 |
-
|
| 76 |
-
License: Apache 2.0.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: image-feature-extraction
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
base_model: facebook/dinov2-small
|
| 5 |
+
library_name: zeromodels
|
| 6 |
+
tags:
|
| 7 |
+
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
+
- dinov2
|
| 10 |
+
- feature-extraction
|
| 11 |
+
- vision
|
| 12 |
+
- arxiv:2304.07193
|
| 13 |
+
- pytorch
|
| 14 |
+
- jax
|
| 15 |
+
- tf
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/dino-v1-v2-v3-6a6a94f8281a2f373f70e769) for all versions of DINOv2.***
|
| 19 |
+
|
| 20 |
+
# Run DINOv2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
+
|
| 22 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/dinov2/) [](https://huggingface.co/collections/zeromodels/dino-v1-v2-v3-6a6a94f8281a2f373f70e769)
|
| 23 |
+
|
| 24 |
+
# zeromodels/dinov2-small
|
| 25 |
+
|
| 26 |
+
Paper: [DINOv2: Learning Robust Visual Features without Supervision (arXiv:2304.07193)](https://arxiv.org/abs/2304.07193) · [HF Papers](https://huggingface.co/papers/2304.07193)
|
| 27 |
+
|
| 28 |
+
DINOv2 scales self-supervised ViT pretraining for strong transferable visual features without labels. These checkpoints are backbones that return patch tokens for downstream heads.
|
| 29 |
+
|
| 30 |
+
For more details on the model, please go to the upstream [model card](https://huggingface.co/facebook/dinov2-small).
|
| 31 |
+
|
| 32 |
+
Pure-**Keras 3** conversion of [`facebook/dinov2-small`](https://huggingface.co/facebook/dinov2-small) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 33 |
+
|
| 34 |
+
This is a **self-supervised backbone** (`DinoV2Model`), not a task head.
|
| 35 |
+
|
| 36 |
+
## ✨ Quick start
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
import os
|
| 40 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 41 |
+
|
| 42 |
+
from zeromodels.models.dino_v2 import DinoV2Model, DinoV2ImageProcessor
|
| 43 |
+
|
| 44 |
+
# The processor resizes + ImageNet-normalizes, so build the model with
|
| 45 |
+
# include_normalization=False (it would otherwise normalize a second time).
|
| 46 |
+
model = DinoV2Model.from_weights(
|
| 47 |
+
"zeromodels/dinov2-small", include_normalization=False
|
| 48 |
+
)
|
| 49 |
+
processor = DinoV2ImageProcessor.from_weights("zeromodels/dinov2-small")
|
| 50 |
+
|
| 51 |
+
pixel_values = processor("your_image.jpg")["pixel_values"]
|
| 52 |
+
features = model(pixel_values, training=False)
|
| 53 |
+
print(pixel_values.shape, features.shape)
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
Load any DINOv2 variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 57 |
+
|
| 58 |
+
| Variant | Hub | Backbone |
|
| 59 |
+
|---|---|---|
|
| 60 |
+
| `dinov2-small` | [`zeromodels/dinov2-small`](https://huggingface.co/zeromodels/dinov2-small) | ViT-S/14 |
|
| 61 |
+
| `dinov2-base` | [`zeromodels/dinov2-base`](https://huggingface.co/zeromodels/dinov2-base) | ViT-B/14 |
|
| 62 |
+
| `dinov2-large` | [`zeromodels/dinov2-large`](https://huggingface.co/zeromodels/dinov2-large) | ViT-L/14 |
|
| 63 |
+
| `dinov2-giant` | [`zeromodels/dinov2-giant`](https://huggingface.co/zeromodels/dinov2-giant) | ViT-g/14 |
|
| 64 |
+
|
| 65 |
+
## Tips
|
| 66 |
+
|
| 67 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 68 |
+
- The processor normalizes; pair it with `include_normalization=False`. To skip it, feed raw `[0, 255]` pixels and keep the default `include_normalization=True`.
|
| 69 |
+
- See [DINOv2 docs](https://imvision12.github.io/ZeroModels/dinov2/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 70 |
+
- Community / upstream weights: `DinoV2Model.from_weights("hf:facebook/dinov2-small")`.
|
| 71 |
+
|
| 72 |
+
## Special Thanks
|
| 73 |
+
|
| 74 |
+
A huge thank you to the Facebook AI Research DINOv2 authors for creating and releasing these models.
|
| 75 |
+
|
| 76 |
+
License: Apache 2.0.
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "DinoV2Model",
|
| 6 |
-
"variant": "dinov2-small",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "dinov2",
|
| 11 |
-
"vision_config": {
|
| 12 |
-
"as_backbone": false,
|
| 13 |
-
"patch_size": 14,
|
| 14 |
-
"embed_dim": 384,
|
| 15 |
-
"depth": 12,
|
| 16 |
-
"num_heads": 6,
|
| 17 |
-
"mlp_ratio": 4.0,
|
| 18 |
-
"qkv_bias": true,
|
| 19 |
-
"qk_norm": false,
|
| 20 |
-
"drop_rate": 0.0,
|
| 21 |
-
"attn_drop_rate": 0.0,
|
| 22 |
-
"layer_scale_init": 1.0,
|
| 23 |
-
"use_swiglu": false,
|
| 24 |
-
"include_normalization": true,
|
| 25 |
-
"normalization_mode": "imagenet",
|
| 26 |
-
"image_size": 224
|
| 27 |
-
}
|
| 28 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.dino_v2",
|
| 5 |
+
"model_class": "DinoV2Model",
|
| 6 |
+
"variant": "dinov2-small",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "dinov2",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"as_backbone": false,
|
| 13 |
+
"patch_size": 14,
|
| 14 |
+
"embed_dim": 384,
|
| 15 |
+
"depth": 12,
|
| 16 |
+
"num_heads": 6,
|
| 17 |
+
"mlp_ratio": 4.0,
|
| 18 |
+
"qkv_bias": true,
|
| 19 |
+
"qk_norm": false,
|
| 20 |
+
"drop_rate": 0.0,
|
| 21 |
+
"attn_drop_rate": 0.0,
|
| 22 |
+
"layer_scale_init": 1.0,
|
| 23 |
+
"use_swiglu": false,
|
| 24 |
+
"include_normalization": true,
|
| 25 |
+
"normalization_mode": "imagenet",
|
| 26 |
+
"image_size": 224
|
| 27 |
+
}
|
| 28 |
}
|
kf_preprocessor.json → zm_preprocessor.json
RENAMED
|
@@ -1,23 +1,23 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"preprocessor_module": "
|
| 5 |
-
"preprocessor_class": "DinoV2ImageProcessor",
|
| 6 |
-
"variant": "dinov2-small",
|
| 7 |
-
"resize_size": 256,
|
| 8 |
-
"crop_size": 224,
|
| 9 |
-
"mean": [
|
| 10 |
-
0.48500001430511475,
|
| 11 |
-
0.4560000002384186,
|
| 12 |
-
0.4059999883174896
|
| 13 |
-
],
|
| 14 |
-
"std": [
|
| 15 |
-
0.2290000021457672,
|
| 16 |
-
0.2240000069141388,
|
| 17 |
-
0.22499999403953552
|
| 18 |
-
],
|
| 19 |
-
"do_center_crop": true,
|
| 20 |
-
"do_normalize": true,
|
| 21 |
-
"do_resize": true,
|
| 22 |
-
"data_format": "channels_last"
|
| 23 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.dino_v2",
|
| 5 |
+
"preprocessor_class": "DinoV2ImageProcessor",
|
| 6 |
+
"variant": "dinov2-small",
|
| 7 |
+
"resize_size": 256,
|
| 8 |
+
"crop_size": 224,
|
| 9 |
+
"mean": [
|
| 10 |
+
0.48500001430511475,
|
| 11 |
+
0.4560000002384186,
|
| 12 |
+
0.4059999883174896
|
| 13 |
+
],
|
| 14 |
+
"std": [
|
| 15 |
+
0.2290000021457672,
|
| 16 |
+
0.2240000069141388,
|
| 17 |
+
0.22499999403953552
|
| 18 |
+
],
|
| 19 |
+
"do_center_crop": true,
|
| 20 |
+
"do_normalize": true,
|
| 21 |
+
"do_resize": true,
|
| 22 |
+
"data_format": "channels_last"
|
| 23 |
}
|