Views
No views yet
facebook/dinov2-small backbone
with a trainable MLP head that predicts an aesthetic score from image embeddings.| Component | Details |
|---|---|
| Backbone | facebook/dinov2-small (frozen, not included in this checkpoint) |
| Input | CLS token — shape (B, 384) |
| Head | Linear(384->256) -> GELU -> Dropout(0.3) -> Linear(256->1) |
| Output | Scalar aesthetic score per image |
.pt file contains only the MLPHead state dict (4 tensors).
The DINOv2 backbone is loaded separately from facebook/dinov2-small.1import torch
2import torch.nn as nn
3from transformers import AutoImageProcessor, Dinov2Model
4from huggingface_hub import hf_hub_download
5from PIL import Image
6
7class MLPHead(nn.Module):
8 def __init__(self, embed_dim=384, hidden_dim=256, dropout_p=0.3):
9 super().__init__()
10 self.net = nn.Sequential(
11 nn.Linear(embed_dim, hidden_dim),
12 nn.GELU(),
13 nn.Dropout(dropout_p),
14 nn.Linear(hidden_dim, 1),
15 )
16 def forward(self, x):
17 return self.net(x).squeeze(-1)
18
19# Load backbone
20processor = AutoImageProcessor.from_pretrained("facebook/dinov2-small")
21backbone = Dinov2Model.from_pretrained("facebook/dinov2-small").eval()
22
23# Load head
24ckpt_path = hf_hub_download(repo_id="grantmwilkinson/dinov2-small-mlphead-aesthetic", filename="dinov2-small_MLPHead_best.pt")
25head = MLPHead()
26head.load_state_dict(torch.load(ckpt_path, map_location="cpu", weights_only=True))
27head.eval()
28
29# Inference
30image = Image.open("your_image.jpg").convert("RGB")
31inputs = processor(images=image, return_tensors="pt")
32
33with torch.no_grad():
34 cls_token = backbone(**inputs).last_hidden_state[:, 0] # (1, 384)
35 score = head(cls_token) # (1,)
36
37print(f"Aesthetic score: {score.item():.4f}")