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
metadata
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 for all versions of DINOv2.

Run DINOv2 with Keras 3: JAX, PyTorch, or TensorFlow

GitHub Docs Collection

zeromodels/dinov2-large

Paper: DINOv2: Learning Robust Visual Features without Supervision (arXiv:2304.07193) · HF Papers

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.

Pure-Keras 3 conversion of facebook/dinov2-large for zeromodels. One implementation runs unmodified on TensorFlow / Torch / JAX.

This is a self-supervised backbone (DinoV2Model), not a task head.

✨ Quick start

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 ViT-S/14
dinov2-base zeromodels/dinov2-base ViT-B/14
dinov2-large zeromodels/dinov2-large ViT-L/14
dinov2-giant 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 and 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.