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
File size: 3,455 Bytes
1cc6ee0 923b74a 1cc6ee0 923b74a 1cc6ee0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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 73 74 75 76 77 | ---
pipeline_tag: image-feature-extraction
license: apache-2.0
base_model: facebook/dinov2-small
library_name: zeromodels
tags:
- keras
- zeromodels
- dinov2
- feature-extraction
- vision
- arxiv:2304.07193
- pytorch
- jax
- tf
---
## ***See [our collection](https://huggingface.co/collections/zeromodels/dino-v1-v2-v3-6a8eaf5a43e1a5079d6cc817) for all versions of DINOv2.***
# Run DINOv2 with Keras 3: JAX, PyTorch, or TensorFlow
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/dinov2/) [](https://huggingface.co/collections/zeromodels/dino-v1-v2-v3-6a8eaf5a43e1a5079d6cc817)
# zeromodels/dinov2-small
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)
DINOv2 scales self-supervised ViT pretraining for strong transferable visual features without labels. These checkpoints are backbones that return patch tokens for downstream heads.
For more details on the model, please go to the upstream [model card](https://huggingface.co/facebook/dinov2-small).
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**.
This is a **self-supervised backbone** (`DinoV2Model`), not a task head.
## ✨ Quick start
```python
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from zeromodels.models.dino_v2 import DinoV2Model, DinoV2ImageProcessor
# The processor resizes + ImageNet-normalizes, so build the model with
# include_normalization=False (it would otherwise normalize a second time).
model = DinoV2Model.from_weights(
"zeromodels/dinov2-small", include_normalization=False
)
processor = DinoV2ImageProcessor.from_weights("zeromodels/dinov2-small")
pixel_values = processor("your_image.jpg")["pixel_values"]
features = model(pixel_values, training=False)
print(pixel_values.shape, features.shape)
```
Load any DINOv2 variant the same way with `from_weights("zeromodels/<variant>")`:
| Variant | Hub | Backbone |
|---|---|---|
| `dinov2-small` | [`zeromodels/dinov2-small`](https://huggingface.co/zeromodels/dinov2-small) | ViT-S/14 |
| `dinov2-base` | [`zeromodels/dinov2-base`](https://huggingface.co/zeromodels/dinov2-base) | ViT-B/14 |
| `dinov2-large` | [`zeromodels/dinov2-large`](https://huggingface.co/zeromodels/dinov2-large) | ViT-L/14 |
| `dinov2-giant` | [`zeromodels/dinov2-giant`](https://huggingface.co/zeromodels/dinov2-giant) | ViT-g/14 |
## Tips
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
- The processor normalizes; pair it with `include_normalization=False`. To skip it, feed raw `[0, 255]` pixels and keep the default `include_normalization=True`.
- See [DINOv2 docs](https://imvision12.github.io/ZeroModels/dinov2/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
- Community / upstream weights: `DinoV2Model.from_weights("hf:facebook/dinov2-small")`.
## Special Thanks
A huge thank you to the Facebook AI Research DINOv2 authors for creating and releasing these models.
License: Apache 2.0.
|