Instructions to use zeromodels/dinov2-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/dinov2-large 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-large") - Notebooks
- Google Colab
- Kaggle
Add kf_preprocessor.json; load processor via from_weights
Browse files- README.md +75 -72
- kf_preprocessor.json +23 -0
README.md
CHANGED
|
@@ -1,72 +1,75 @@
|
|
| 1 |
-
---
|
| 2 |
-
pipeline_tag: image-feature-extraction
|
| 3 |
-
license: apache-2.0
|
| 4 |
-
base_model: facebook/dinov2-large
|
| 5 |
-
library_name: kerasformers
|
| 6 |
-
tags:
|
| 7 |
-
- keras
|
| 8 |
-
- kerasformers
|
| 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/kerasformers/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/KerasFormers) [](https://imvision12.github.io/KerasFormers/dinov2/) [](https://huggingface.co/collections/kerasformers/dino-v1-v2-v3-6a6a94f8281a2f373f70e769)
|
| 23 |
-
|
| 24 |
-
# kerasformers/dinov2_vitl14
|
| 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-large).
|
| 31 |
-
|
| 32 |
-
Pure-**Keras 3** conversion of [`facebook/dinov2-large`](https://huggingface.co/facebook/dinov2-large) for [kerasformers](https://github.com/IMvision12/KerasFormers). 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 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
model = DinoV2Model.from_weights(
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
| 59 |
-
|
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: image-feature-extraction
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
base_model: facebook/dinov2-large
|
| 5 |
+
library_name: kerasformers
|
| 6 |
+
tags:
|
| 7 |
+
- keras
|
| 8 |
+
- kerasformers
|
| 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/kerasformers/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/KerasFormers) [](https://imvision12.github.io/KerasFormers/dinov2/) [](https://huggingface.co/collections/kerasformers/dino-v1-v2-v3-6a6a94f8281a2f373f70e769)
|
| 23 |
+
|
| 24 |
+
# kerasformers/dinov2_vitl14
|
| 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-large).
|
| 31 |
+
|
| 32 |
+
Pure-**Keras 3** conversion of [`facebook/dinov2-large`](https://huggingface.co/facebook/dinov2-large) for [kerasformers](https://github.com/IMvision12/KerasFormers). 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 kerasformers.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 |
+
"kerasformers/dinov2_vitl14", include_normalization=False
|
| 48 |
+
)
|
| 49 |
+
processor = DinoV2ImageProcessor.from_weights("kerasformers/dinov2_vitl14")
|
| 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("kerasformers/<variant>")`:
|
| 57 |
+
|
| 58 |
+
| Variant | Hub | Backbone |
|
| 59 |
+
|---|---|---|
|
| 60 |
+
| `dinov2_vits14` | [`kerasformers/dinov2_vits14`](https://huggingface.co/kerasformers/dinov2_vits14) | ViT-S/14 |
|
| 61 |
+
| `dinov2_vitb14` | [`kerasformers/dinov2_vitb14`](https://huggingface.co/kerasformers/dinov2_vitb14) | ViT-B/14 |
|
| 62 |
+
| `dinov2_vitl14` | [`kerasformers/dinov2_vitl14`](https://huggingface.co/kerasformers/dinov2_vitl14) | ViT-L/14 |
|
| 63 |
+
|
| 64 |
+
## Tips
|
| 65 |
+
|
| 66 |
+
- Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
|
| 67 |
+
- The processor normalizes; pair it with `include_normalization=False`. To skip it, feed raw `[0, 255]` pixels and keep the default `include_normalization=True`.
|
| 68 |
+
- See [DINOv2 docs](https://imvision12.github.io/KerasFormers/dinov2/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
|
| 69 |
+
- Community / upstream weights: `DinoV2Model.from_weights("hf:facebook/dinov2-large")`.
|
| 70 |
+
|
| 71 |
+
## Special Thanks
|
| 72 |
+
|
| 73 |
+
A huge thank you to the Facebook AI Research DINOv2 authors for creating and releasing these models.
|
| 74 |
+
|
| 75 |
+
License: Apache 2.0.
|
kf_preprocessor.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "kerasformers",
|
| 3 |
+
"kerasformers_version": "1.2.1",
|
| 4 |
+
"preprocessor_module": "kerasformers.models.dino_v2",
|
| 5 |
+
"preprocessor_class": "DinoV2ImageProcessor",
|
| 6 |
+
"variant": "dinov2_vitl14",
|
| 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 |
+
}
|