mayocream commited on
Commit
2b564b5
·
verified ·
1 Parent(s): e0fc686

Publish KoharuLayout RF-DETR Seg 2XL 1152 (SafeTensors)

Browse files
README.md ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ library_name: rfdetr
4
+ pipeline_tag: image-segmentation
5
+ datasets:
6
+ - mayocream/manga109-segmentation
7
+ language:
8
+ - ja
9
+ tags:
10
+ - manga
11
+ - comics
12
+ - rf-detr
13
+ - instance-segmentation
14
+ - object-detection
15
+ - layout-analysis
16
+ - text-detection
17
+ ---
18
+
19
+ # KoharuLayout-RFDETR-Seg-2XL-1152
20
+
21
+ KoharuLayout is a high-resolution RF-DETR Seg 2XL model for manga page layout
22
+ analysis. It predicts bounding boxes and instance masks for four classes:
23
+
24
+ | ID | Class | Meaning |
25
+ |---:|---|---|
26
+ | 0 | `text` | Dialogue, captions, titles, credits, and other non-COO text |
27
+ | 1 | `onomatopoeia` | Comic onomatopoeia and sound effects (COO) |
28
+ | 2 | `bubble` | Speech and text balloons |
29
+ | 3 | `panel` | Manga panels and frames |
30
+
31
+ The model does **not** perform OCR or reading-order prediction.
32
+
33
+ ## Files
34
+
35
+ - `model.safetensors` — RF-DETR inference weights (SafeTensors only)
36
+ - `load_model.py` — strict RF-DETR Seg 2XL loader
37
+ - `inference_config.json` — class mapping and recommended inference settings
38
+ - `validation_metrics.json` — final held-out validation results
39
+
40
+ The deployment weights contain only RF-DETR tensors. The auxiliary dense
41
+ typography branch used during fine-tuning has been removed because it is not
42
+ part of RF-DETR inference.
43
+
44
+ ## Usage
45
+
46
+ ```bash
47
+ pip install "rfdetr==1.7.0" "safetensors>=0.5" huggingface_hub pillow
48
+ ```
49
+
50
+ ```python
51
+ from huggingface_hub import hf_hub_download
52
+ from PIL import Image
53
+ import importlib.util
54
+
55
+ weights = hf_hub_download(
56
+ repo_id="mayocream/koharu-layout-rfdetr-seg-2xl-1152",
57
+ filename="model.safetensors",
58
+ )
59
+ loader_path = hf_hub_download(
60
+ repo_id="mayocream/koharu-layout-rfdetr-seg-2xl-1152",
61
+ filename="load_model.py",
62
+ )
63
+ spec = importlib.util.spec_from_file_location("koharu_layout_loader", loader_path)
64
+ loader = importlib.util.module_from_spec(spec)
65
+ spec.loader.exec_module(loader)
66
+ model = loader.load_model(weights)
67
+
68
+ image = Image.open("page.jpg").convert("RGB")
69
+ detections = model.predict(
70
+ image,
71
+ threshold=0.25,
72
+ shape=(1152, 1152),
73
+ include_source_image=False,
74
+ )
75
+
76
+ print(detections.xyxy) # bounding boxes
77
+ print(detections.mask) # instance masks
78
+ print(detections.class_id) # 0=text, 1=COO, 2=bubble, 3=panel
79
+ print(detections.confidence)
80
+ ```
81
+
82
+ CUDA is strongly recommended. The model was trained and evaluated at 1152 px.
83
+
84
+ ## Recommended thresholds
85
+
86
+ A single `0.25` threshold maximizes recall, but class-specific filtering is
87
+ usually better:
88
+
89
+ | Class | Suggested threshold |
90
+ |---|---:|
91
+ | Text | 0.25–0.30 |
92
+ | COO | 0.40–0.50 |
93
+ | Bubble | 0.50 |
94
+ | Panel | 0.50 |
95
+
96
+ The lower text threshold helps retain titles, credits, and back matter. Highly
97
+ decorative pages may require tiling or a separate fallback detector.
98
+
99
+ ## Validation results
100
+
101
+ The final checkpoint was evaluated on the held-out 1,070-page Manga109 test
102
+ split at 1152 px.
103
+
104
+ | Metric | Score |
105
+ |---|---:|
106
+ | Box mAP50–95 | 0.7929 |
107
+ | Box mAP50 | 0.8941 |
108
+ | Box mAP75 | 0.8373 |
109
+ | Mask mAP50–95 | 0.5187 |
110
+ | Mask mAP50 | 0.7206 |
111
+ | Detection precision | 0.8061 |
112
+ | Detection recall | 0.7452 |
113
+ | Detection F1 | 0.7672 |
114
+
115
+ Per-class box AP:
116
+
117
+ | Class | AP |
118
+ |---|---:|
119
+ | Text | 0.8762 |
120
+ | COO | 0.4285 |
121
+ | Bubble | 0.9094 |
122
+ | Panel | 0.9575 |
123
+
124
+ ## Out-of-domain review
125
+
126
+ The model was also run qualitatively on 212 full-color Blue Archive comic pages
127
+ and 79 monochrome Marriage Toxin pages. These folders have no ground-truth
128
+ annotations, so the observations below are visual rather than accuracy claims.
129
+
130
+ - Dialogue text, bubbles, and conventional panel layouts generalized well.
131
+ - Marriage Toxin dialogue, bubbles, and panels were particularly consistent.
132
+ - Large isolated COO was often detected, but smaller effects were fragmented or
133
+ confused with ordinary text.
134
+ - Covers, logos, credits, and dense collage layouts remain difficult.
135
+ - A highly decorative collage page produced 140 low-confidence predictions,
136
+ approaching the configured 160-candidate limit.
137
+
138
+ ## Training
139
+
140
+ - Architecture: RF-DETR Seg 2XL (`rfdetr==1.7.0`)
141
+ - Resolution: 1152 × 1152
142
+ - Main supervision: Manga109 Segmentation v1.1.0
143
+ - Classes: text, onomatopoeia, bubble, panel
144
+ - Final continuation stage: 6 epochs
145
+ - Final-stage global batch: 32 (8 GPUs × 2 images × 2 accumulation steps)
146
+ - Optimizer learning rate: `3e-5`; encoder learning rate: `1e-5`
147
+ - EMA enabled; seed 42
148
+ - Additional normal-text supervision was distilled from PP-DocLayoutV3
149
+
150
+ The auxiliary typography head used for training improved mask recall but did
151
+ not materially improve box AP. It is intentionally excluded from this
152
+ deployment checkpoint.
153
+
154
+ ## Limitations
155
+
156
+ - COO is substantially weaker than text, bubble, and panel detection.
157
+ - Large display titles and credits may be missed or assigned low confidence.
158
+ - Character nameplates and small icons can be confused with bubbles.
159
+ - Dense collages can create many duplicate or low-confidence instances.
160
+ - The model has no OCR, semantic reading order, or text-to-bubble relationship
161
+ output.
162
+ - The training distribution is predominantly Japanese manga. Results on other
163
+ comic styles and languages may differ.
164
+
165
+ ## License and training-data terms
166
+
167
+ The RF-DETR software is distributed under Apache-2.0. The model was fine-tuned
168
+ using Manga109 images, which are distributed separately under Manga109's
169
+ academic-use terms. This repository does not redistribute Manga109 images.
170
+
171
+ The model repository therefore uses a custom/`other` license designation.
172
+ Users are responsible for obtaining Manga109 and complying with its terms and
173
+ all applicable rights. This model card does not grant rights to Manga109 source
174
+ images or to third-party comic content.
175
+
176
+ ## Weight integrity
177
+
178
+ SHA-256:
179
+
180
+ ```text
181
+ 0d730ea52064051f3a1669bd146a2625d511b78072f1c176e200f70cbdb9042c
182
+ ```
inference_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "RFDETRSeg2XLarge",
3
+ "rfdetr_version": "1.7.0",
4
+ "resolution": 1152,
5
+ "num_select": 160,
6
+ "classes": {
7
+ "0": "text",
8
+ "1": "onomatopoeia",
9
+ "2": "bubble",
10
+ "3": "panel"
11
+ },
12
+ "recommended_thresholds": {
13
+ "text": 0.25,
14
+ "onomatopoeia": 0.4,
15
+ "bubble": 0.5,
16
+ "panel": 0.5
17
+ },
18
+ "checkpoint": "model.safetensors",
19
+ "checkpoint_sha256": "0d730ea52064051f3a1669bd146a2625d511b78072f1c176e200f70cbdb9042c"
20
+ }
load_model.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """SafeTensors-only loader for KoharuLayout RF-DETR Seg 2XL."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ import warnings
7
+
8
+ from rfdetr import RFDETRSeg2XLarge
9
+ from rfdetr.config import PretrainWeightsCompatibilityWarning
10
+ from safetensors.torch import load_file
11
+
12
+
13
+ CLASS_NAMES = ["text", "onomatopoeia", "bubble", "panel"]
14
+
15
+
16
+ def load_model(weights: str | Path) -> RFDETRSeg2XLarge:
17
+ with warnings.catch_warnings():
18
+ warnings.simplefilter("ignore", PretrainWeightsCompatibilityWarning)
19
+ model = RFDETRSeg2XLarge(
20
+ pretrain_weights=None,
21
+ resolution=1152,
22
+ num_select=160,
23
+ num_classes=len(CLASS_NAMES),
24
+ )
25
+ incompatible = model.model.model.load_state_dict(load_file(str(weights), device="cpu"), strict=True)
26
+ if incompatible.missing_keys or incompatible.unexpected_keys:
27
+ raise RuntimeError(f"Incompatible weights: {incompatible}")
28
+ model.model.class_names = CLASS_NAMES.copy()
29
+ return model
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0d730ea52064051f3a1669bd146a2625d511b78072f1c176e200f70cbdb9042c
3
+ size 161292684
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ rfdetr==1.7.0
2
+ safetensors>=0.5
3
+ huggingface_hub>=1.0
4
+ pillow
validation_metrics.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dataset": "Manga109 Segmentation v1.1.0 held-out test split",
3
+ "pages": 1070,
4
+ "resolution": 1152,
5
+ "checkpoint_epoch": 5,
6
+ "metrics": {
7
+ "box_map_50_95": 0.79288250207901,
8
+ "box_map_50": 0.8940883278846741,
9
+ "box_map_75": 0.8372876644134521,
10
+ "box_mar": 0.850690484046936,
11
+ "precision": 0.806089460849762,
12
+ "recall": 0.745160698890686,
13
+ "f1": 0.767235279083252,
14
+ "mask_map_50_95": 0.5187143087387085,
15
+ "mask_map_50": 0.7205575704574585,
16
+ "box_ap_by_class": {
17
+ "text": 0.8761724829673767,
18
+ "onomatopoeia": 0.4284520149230957,
19
+ "bubble": 0.9094059467315674,
20
+ "panel": 0.9574995636940002
21
+ }
22
+ }
23
+ }
24
+