Views
No views yet

1from transformers import AutoImageProcessor, Dinov2Model
2import torch
3from PIL import Image
4
5processor = AutoImageProcessor.from_pretrained('facebook/webssl-dino3b-heavy2b-224')
6model = Dinov2Model.from_pretrained('facebook/webssl-dino3b-heavy2b-224')
7
8# Process an image
9image = Image.open('path/to/image.jpg')
10inputs = processor(images=image, return_tensors="pt")
11with torch.no_grad():
12 outputs = model(**inputs)
13
14cls_features = outputs.last_hidden_state[:, 0] # CLS token features
15patch_features = outputs.last_hidden_state[:, 1:] # patch-wise token features1@article{fan2025scaling,
2 title={Scaling Language-Free Visual Representation Learning},
3 author={David Fan and Shengbang Tong and Jiachen Zhu and Koustuv Sinha and Zhuang Liu and Xinlei Chen and Michael Rabbat and Nicolas Ballas and Yann LeCun and Amir Bar and Saining Xie},
4 year={2025},
5 eprint={2504.01017},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV}
8}