File size: 1,710 Bytes
8e2a9eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd6f542
 
 
 
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
---
license: apache-2.0
library_name: pytorch
tags:
  - font-recognition
  - siglip2
  - multi-task
base_model: google/siglip2-base-patch16-naflex
models:
  - google/siglip2-base-patch16-naflex
datasets:
  - issai/DataFontID
  - issai/Wild1024
---

# FontID — SigLIP2 NaFlex, four-head font analyzer

Predicts **font family (75)**, **language (11)**, **color (64, EGA index)**, and
**style (4)** from a text-image crop. Backbone: `google/siglip2-base-patch16-naflex`
(native aspect ratio, `max_num_patches=256`); pooled feature (d=768) from the
SigLIP2 attention-pooling head feeds four independent heads
(`Linear(768→512) → LayerNorm → GELU → Dropout(0.1) → Linear(512→n)`).

## Results (DataFontID test)

| font | language | color | style |
|------|----------|-------|-------|
| 96.34 | 96.19 | 95.92 | 96.98 |

Wild1024 out-of-distribution: language 82.42, font-category 89.55.

## Usage

```python
from huggingface_hub import snapshot_download
import sys, torch, json
from transformers import AutoProcessor
from PIL import Image

path = snapshot_download("issai/FontID")
sys.path.insert(0, path)
from modeling_fontid import FontIDModel

model = FontIDModel.from_pretrained(path).eval()
proc  = AutoProcessor.from_pretrained("google/siglip2-base-patch16-naflex")
maps  = json.load(open(f"{path}/class_mappings.json"))

img = Image.open("crop.png").convert("RGB")
o = proc(images=img, max_num_patches=256, return_tensors="pt")
with torch.no_grad():
    out = model(o["pixel_values"], o["pixel_attention_mask"], o["spatial_shapes"])
for head in ["font", "lang", "color", "style"]:
    idx = int(out[head].argmax(-1))
    print(head, maps[head][str(idx)])
```

## Citation

Paper is coming soon.