realphongha commited on
Commit
20f75a0
Β·
verified Β·
1 Parent(s): df65255

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +95 -0
README.md CHANGED
@@ -1,5 +1,100 @@
1
  ---
 
 
 
 
 
 
 
 
 
2
  license: other
3
  license_name: dinov3-license
4
  license_link: https://ai.meta.com/resources/models-and-libraries/dinov3-license/
5
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: en
3
+ library_name: onnx
4
+ tags:
5
+ - image-classification
6
+ - multi-label-classification
7
+ - danbooru
8
+ - anime
9
+ - onnx
10
+ pipeline_tag: image-classification
11
  license: other
12
  license_name: dinov3-license
13
  license_link: https://ai.meta.com/resources/models-and-libraries/dinov3-license/
14
  ---
15
+
16
+ # DanbooruTagQuery
17
+
18
+ Lightweight multi-label anime image tagger using a pretrained **DINOv3 ViT backbone** and a **cross-attention tag query head**.
19
+
20
+ - 11,424 tags (general + character + copyright)
21
+ - 448Γ—448 input, ONNX-exported
22
+
23
+ [GitHub repo](https://github.com/realphongha/DanbooruTagQuery)
24
+
25
+ ## Model description
26
+
27
+ Image β†’ ViT backbone (DINOv3) β†’ patch tokens β†’ cross-attention β†’ per-tag logits.
28
+
29
+ Each tag is a **single learnable embedding vector** (a "query"). An `nn.MultiheadAttention` layer computes attention between all tag queries and all ViT patch tokens; each query's attended feature is projected through a scalar linear classifier. No MLP, no positional encoding β€” the query itself encodes "what to look for". This design is modular: the head can be swapped without touching the dataset, training loop, or metrics.
30
+
31
+ ```text
32
+ Input image (448Γ—448)
33
+ β”‚
34
+ β–Ό
35
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
36
+ β”‚ DINOv3 β”‚ pretrained ViT backbone
37
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
38
+ β”‚ tokens: (B, N_patches+5, D)
39
+ β–Ό
40
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
41
+ β”‚ Tag Query Head β”‚
42
+ β”‚ β”‚
43
+ β”‚ tag_queries: β”‚ learned (num_tags, D)
44
+ β”‚ (num_tags, D) ─────┼─→ cross-attention ──→ tag features (B, num_tags, D)
45
+ β”‚ β”‚ queries attend to ViT patch tokens
46
+ β”‚ classifier: β”‚
47
+ β”‚ Linear(Dβ†’1) β”€β”€β”€β”€β”€β”€β”€β”˜ β†’ logits (B, num_tags)
48
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
49
+ β”‚
50
+ β–Ό
51
+ sigmoid(logits) β†’ per-tag probabilities
52
+ ```
53
+
54
+ ## Evaluation
55
+
56
+ Evaluated against popular community taggers on the **intersection evaluation subset** (3,383 tags present in every model's vocabulary), drawn from a held-out danbooru2025 test set of images with post ID > 7220105 (avoids contamination with WD-SwinV2 training data). Each model ran at its native resolution; thresholds searched over `[0.10, 0.15, …, 0.95]`.
57
+
58
+ | Model | Params | Input | Latency | mAP | Macro F1 | Micro F1 | Best threshold |
59
+ |---|---|---|---|---|---|---|---|
60
+ | **Ours (L/16) - trained from scratch** | 319.0M | 448Γ—448 | 36.6ms | **0.5352** | **0.4775** | **0.6884** | 0.20 |
61
+ | WD-eva02 | 315.2M | 448Γ—448 | 50.3ms | 0.4822 | 0.4344 | 0.6684 | 0.30 |
62
+ | **Ours (B/16) - trained from scratch** | 96.8M | 448Γ—448 | 24.9ms | 0.4693 | 0.4195 | 0.6684 | 0.20 |
63
+ | WD-SwinV2 | 98.0M | 448Γ—448 | 35.8ms | 0.4603 | 0.4140 | 0.6474 | 0.15 |
64
+ | ML-Danbooru | 68.9M | 448Γ—448 | 34.0ms | 0.4023 | 0.3490 | 0.5952 | 0.60 |
65
+ | JoyTag | 91.5M | 448Γ—448 | 20.2ms | 0.3783 | 0.3429 | 0.6179 | 0.35 |
66
+ | DeepDanbooru (CNN) | 161.0M | 512Γ—512 | 33.6ms | 0.2100 | 0.1920 | 0.4692 | 0.15 |
67
+
68
+ Key results:
69
+
70
+ - **Ours (L/16)** leads all baselines by **+0.053 mAP** over WD-eva02 (the strongest comparable model) with 33% faster inference (36.6ms vs 50.3ms).
71
+ - **Ours (B/16)** outperforms all models in the <100M class (WD-SwinV2 +0.009 mAP, JoyTag +0.091 mAP) at 24.9ms latency.
72
+
73
+ *Latency measured on a single NVIDIA RTX 5090 (PyTorch eager for local runs; ONNX Runtime for ONNX-exported models).*
74
+
75
+ ## Intended uses
76
+
77
+ - Tagging anime / illustration images (general, character, and copyright tags)
78
+ - Generating caption / metadata text for image collections
79
+ - Danbooru-style workflows, e.g. injecting a tag preset into image-generation UIs
80
+ - Batch CLI tagging of local image folders
81
+
82
+ **Note: this model tags adult (NSFW) content.** Danbooru contains explicit imagery and its tag vocabulary reflects that. Do not use in contexts where such content is unacceptable.
83
+
84
+ ## Huggingface space
85
+ You can try our models here:
86
+ [realphongha/DanbooruTagQuery](https://huggingface.co/spaces/realphongha/DanbooruTagQuery)
87
+
88
+ ## Training data
89
+ - Source: [`trojblue/danbooru2025-metadata`](https://huggingface.co/datasets/trojblue/danbooru2025-metadata)
90
+ - Filters: deleted/banned/flagged/pending images removed, score > 10, file size 50 KB–20 MB, dimensions β‰₯ 224Γ—224
91
+ - Tags: `tag_string_general` + `tag_string_character` + `tag_string_copyright` unified; tags with frequency β‰₯ 100; images with β‰₯ 2 tags
92
+ - Vocabulary: **11,424 tags**; ~1M training images; last 100K images held out as validation
93
+ - Noise tags removed via `data/ignored_tags.txt`
94
+
95
+ ## Acknowledgements
96
+
97
+ - [DINOv3](https://github.com/facebookresearch/dinov3) (Meta AI) β€” pretrained ViT backbones (licensed under the DINOv3 License)
98
+ - [`trojblue/danbooru2025-metadata`](https://huggingface.co/datasets/trojblue/danbooru2025-metadata) β€” training data
99
+ - Baseline reimplementations live in [`src/compared_models/`](https://github.com/realphongha/DanbooruTagQuery/tree/master/src/compared_models): DeepDanbooru, WD-tagger, ML-Danbooru, JoyTag
100
+ - [timm](https://github.com/huggingface/pytorch-image-models) for backbone loading and [ONNX Runtime](https://onnxruntime.ai/) for deployment