dinov2-large / README.md
IMvision12's picture
Fix Collection badge link to the current zeromodels collection slug
8199280 verified
|
Raw
History Blame Contribute Delete
3.46 kB
---
pipeline_tag: image-feature-extraction
license: apache-2.0
base_model: facebook/dinov2-large
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
[![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-black?logo=github)](https://github.com/IMvision12/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-DINOv2-blue)](https://imvision12.github.io/ZeroModels/dinov2/) [![Collection](https://img.shields.io/badge/HF-DINOv2%20collection-yellow)](https://huggingface.co/collections/zeromodels/dino-v1-v2-v3-6a8eaf5a43e1a5079d6cc817)
# zeromodels/dinov2-large
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-large).
Pure-**Keras 3** conversion of [`facebook/dinov2-large`](https://huggingface.co/facebook/dinov2-large) 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-large", include_normalization=False
)
processor = DinoV2ImageProcessor.from_weights("zeromodels/dinov2-large")
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-large")`.
## Special Thanks
A huge thank you to the Facebook AI Research DINOv2 authors for creating and releasing these models.
License: Apache 2.0.