Commit ·
7fb6304
0
Parent(s):
Duplicate from tori29umai/rtdetrv4-x-manga109s_v2
Browse filesCo-authored-by: tori29umai <tori29umai@users.noreply.huggingface.co>
- .gitattributes +36 -0
- README.md +383 -0
- model.onnx +3 -0
- sampe1.png +3 -0
- sampe2.png +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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en
|
| 6 |
+
library_name: onnx
|
| 7 |
+
pipeline_tag: object-detection
|
| 8 |
+
tags:
|
| 9 |
+
- object-detection
|
| 10 |
+
- manga
|
| 11 |
+
- comic
|
| 12 |
+
- rt-detr
|
| 13 |
+
- rt-detrv4
|
| 14 |
+
- d-fine
|
| 15 |
+
- onnx
|
| 16 |
+
- manga109
|
| 17 |
+
datasets:
|
| 18 |
+
- Manga109-s
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# RT-DETRv4-X Manga109-s v2
|
| 22 |
+
|
| 23 |
+
**[日本語](#日本語) | [English](#english)**
|
| 24 |
+
|
| 25 |
+
漫画ページから **コマ枠 (frame) / 人物 (body) / 台詞 (text) / 顔 (face)** の 4 クラスを検出する RT-DETRv4 (X size) モデル。Manga109-s の見開きを単ページに分割した 15,263 枚 (単ページ 14,796 + 見開き保持 467) で 30 epoch ファインチューンしたもので、v1 (3 クラス) に **`face` クラスを追加**したバージョンです。
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## 日本語
|
| 30 |
+
|
| 31 |
+
### 概要
|
| 32 |
+
|
| 33 |
+
漫画ページから 4 クラス (コマ枠・人物・台詞・顔) を検出する RT-DETRv4 (X size) モデル:
|
| 34 |
+
|
| 35 |
+
- `0: body` — 人物 (キャラクター本体)
|
| 36 |
+
- `1: text` — 台詞 / 吹き出し領域
|
| 37 |
+
- `2: frame` — コマ枠
|
| 38 |
+
- `3: face` — 顔 (v2 で追加)
|
| 39 |
+
|
| 40 |
+
Manga109-s の見開きを単ページ分割した 15,263 枚 (単ページ 14,796 + 見開き保持 467) で 30 epoch ファインチューン、DINOv2 ViT-B/14 特徴蒸留付き。bbox がセンター線をまたぐページは分割せず見開きのまま保持しているため、学習・推論ともに単ページと見開き両方に対応します。v1 では `body` のみで人物全体を取っていましたが、v2 では `body` (体) と `face` (顔) を分離検出することで、表情解析やキャラクタークロップなど顔単位の下流処理に対応できるようにしています。ComfyUI ワークフロー、自動化されたコマ単位処理パイプライン、漫画ドメインの研究を想定しています。
|
| 41 |
+
|
| 42 |
+
| | |
|
| 43 |
+
|---|---|
|
| 44 |
+
| ベースアーキテクチャ | [RT-DETRv4](https://github.com/lyuwenyu/RT-DETR) X-size (HGNetv2-B5 backbone + DFINETransformer decoder) |
|
| 45 |
+
| 蒸留教師モデル | [DINOv2 ViT-B/14](https://github.com/facebookresearch/dinov2) (Apache 2.0) |
|
| 46 |
+
| 学習データ | [Manga109-s](http://www.manga109.org/ja/download_s.html) — 商用利用許諾済 87 タイトル |
|
| 47 |
+
| 入力解像度 | 1280 × 1280 |
|
| 48 |
+
| クラス数 | 4 (body / text / frame / face) |
|
| 49 |
+
|
| 50 |
+
### 検出例
|
| 51 |
+
|
| 52 |
+
bbox の色分け: <span style="color:#9acd32">**黄緑 = frame (コマ)**</span> / <span style="color:#1e90ff">**青 = body (人物)**</span> / <span style="color:#dc143c">**赤 = text (セリフ)**</span> / <span style="color:#ff69b4">**ピンク = face (顔)**</span>
|
| 53 |
+
|
| 54 |
+

|
| 55 |
+
|
| 56 |
+
完成原稿 (ペン入れ済み) の例。コマ・人物・台詞・顔の 4 クラスすべて高精度で取れています。
|
| 57 |
+
|
| 58 |
+

|
| 59 |
+
|
| 60 |
+
**ラフな手書きネーム (下描き / ストーリーボード)** の例。学習データは完成原稿だけですが、線画の途中段階でもコマ枠・人物・台詞・顔をある程度検出できます。
|
| 61 |
+
|
| 62 |
+
### 精度
|
| 63 |
+
|
| 64 |
+
Manga109-s validation split (1,212 ページ, 30,252 bbox) で評価 (`best_stg2`, epoch 27):
|
| 65 |
+
|
| 66 |
+
| 指標 | 値 |
|
| 67 |
+
|---|---|
|
| 68 |
+
| 平均 mAP | **75.0%** |
|
| 69 |
+
| 平均 AP50 | **96.0%** |
|
| 70 |
+
| 平均 AP75 | **79.3%** |
|
| 71 |
+
| 平均 AR100 | **81.6%** |
|
| 72 |
+
| AP (small) | 21.4% |
|
| 73 |
+
| AP (medium) | 56.2% |
|
| 74 |
+
| AP (large) | 80.6% |
|
| 75 |
+
|
| 76 |
+
検出ヒット率を表す AP50 が 96% に達しており、実用上ほぼ取りこぼしなし。残りの伸びしろは IoU 厳格化 (AP75) と、特に小サイズ bbox (細かい台詞や群衆中の小さな顔) であり、検出漏れではなく **bbox 枠の精度向上**が今後の改善ポイント。
|
| 77 |
+
|
| 78 |
+
### ファイル
|
| 79 |
+
|
| 80 |
+
| ファイル | 説明 |
|
| 81 |
+
|---|---|
|
| 82 |
+
| `model.onnx` | ONNX (opset 17, 静的入力 `1×3×1280×1280`) |
|
| 83 |
+
|
| 84 |
+
### 推論
|
| 85 |
+
|
| 86 |
+
ONNX グラフの入出力:
|
| 87 |
+
|
| 88 |
+
- **入力**: `images` (float32, NCHW, [0, 1] に正規化), `orig_target_sizes` (int64, `[N, 2]` = `[width, height]`)
|
| 89 |
+
- **出力**: `labels` (int, `[N, 300]`), `boxes` (float32, `[N, 300, 4]`, 元画像座標の xyxy), `scores` (float32, `[N, 300]`)
|
| 90 |
+
|
| 91 |
+
`onnxruntime` での最低限のサンプル:
|
| 92 |
+
|
| 93 |
+
```python
|
| 94 |
+
import numpy as np
|
| 95 |
+
import onnxruntime as ort
|
| 96 |
+
from PIL import Image, ImageDraw
|
| 97 |
+
|
| 98 |
+
CLASS_NAMES = {0: "body", 1: "text", 2: "frame", 3: "face"}
|
| 99 |
+
INPUT_SIZE = 1280
|
| 100 |
+
CONF_THRESHOLD = 0.5
|
| 101 |
+
|
| 102 |
+
session = ort.InferenceSession(
|
| 103 |
+
"model.onnx",
|
| 104 |
+
providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
image = Image.open("page.jpg").convert("RGB")
|
| 108 |
+
W, H = image.size
|
| 109 |
+
|
| 110 |
+
# 前処理: 1280x1280 にリサイズ → CHW float32 [0, 1]
|
| 111 |
+
resized = image.resize((INPUT_SIZE, INPUT_SIZE), Image.BILINEAR)
|
| 112 |
+
arr = np.asarray(resized, dtype=np.float32) / 255.0
|
| 113 |
+
arr = arr.transpose(2, 0, 1)[None] # 1x3x1280x1280
|
| 114 |
+
orig_size = np.array([[W, H]], dtype=np.int64)
|
| 115 |
+
|
| 116 |
+
labels, boxes, scores = session.run(
|
| 117 |
+
None, {"images": arr, "orig_target_sizes": orig_size}
|
| 118 |
+
)
|
| 119 |
+
labels, boxes, scores = labels[0], boxes[0], scores[0]
|
| 120 |
+
|
| 121 |
+
# 信頼度閾値で絞る (boxes は既に元画像の座標で出てくる)
|
| 122 |
+
keep = scores >= CONF_THRESHOLD
|
| 123 |
+
print(f"Detected {int(keep.sum())} objects")
|
| 124 |
+
for cid, (x1, y1, x2, y2), s in zip(labels[keep], boxes[keep], scores[keep]):
|
| 125 |
+
print(f" {CLASS_NAMES[int(cid)]:5s} conf={s:.3f} "
|
| 126 |
+
f"bbox=({x1:.0f},{y1:.0f},{x2:.0f},{y2:.0f})")
|
| 127 |
+
|
| 128 |
+
# 可視化
|
| 129 |
+
draw = ImageDraw.Draw(image)
|
| 130 |
+
colors = {0: "blue", 1: "red", 2: "yellow", 3: "hotpink"}
|
| 131 |
+
for cid, (x1, y1, x2, y2) in zip(labels[keep], boxes[keep]):
|
| 132 |
+
draw.rectangle([x1, y1, x2, y2], outline=colors[int(cid)], width=3)
|
| 133 |
+
image.save("output.png")
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
CPU で動かす場合は `providers=["CPUExecutionProvider"]` のみで OK。GPU 用には `onnxruntime-gpu` をインストール。
|
| 137 |
+
|
| 138 |
+
### 学習設定
|
| 139 |
+
|
| 140 |
+
| | |
|
| 141 |
+
|---|---|
|
| 142 |
+
| エポック | 30 (flat 15 + cosine 11 + no_aug 4) |
|
| 143 |
+
| バッチサイズ | 16 (single GPU) |
|
| 144 |
+
| オプティマイザ | AdamW — `lr=2.5e-4`, backbone `lr=2.5e-6`, `weight_decay=1.25e-4` |
|
| 145 |
+
| 拡張 | Mosaic / RandomPhotometricDistort / RandomZoomOut / RandomIoUCrop, Mixup (epoch 2–15) |
|
| 146 |
+
| 蒸留 | DINOv2 ViT-B/14 特徴蒸留, `loss_distill` weight 20 (adaptive) |
|
| 147 |
+
| train / val | train: 15,263 枚 (単ページ 14,796 + 見開き保持 467) / val: 1,212 枚 (単ページ 1,116 + 見開き保持 96)、bbox は 370,738 / 30,252 |
|
| 148 |
+
| クラス別 bbox 数 (train) | body 109,480 / text 105,139 / frame 75,581 / face 80,538 |
|
| 149 |
+
| クラス別 bbox 数 (val) | body 8,645 / text 8,433 / frame 6,541 / face 6,633 |
|
| 150 |
+
|
| 151 |
+
Manga109-s の見開きページは原則センター線で単ページに分割して学習。ただし **bbox がセンター線をまたぐページ** (見開きを横断するコマやキャラクターを含むページ) は分割せず**見開きのまま保持**してアノテーションを残す mixed-mode。これは推論時の典型的なシナリオ (1 度に 1 ページ) と入出力を揃えつつ、学習中に「センター線をまたぐ正解 bbox」を欠落させないため。
|
| 152 |
+
|
| 153 |
+
### v1 との差分
|
| 154 |
+
|
| 155 |
+
| 項目 | v1 | v2 |
|
| 156 |
+
|---|---|---|
|
| 157 |
+
| クラス数 | 3 (body / text / frame) | 4 (body / text / frame / **face**) |
|
| 158 |
+
| train bbox 総数 | 290,200 | 370,738 (+ face 80,538) |
|
| 159 |
+
| val bbox 総数 | 23,619 | 30,252 (+ face 6,633) |
|
| 160 |
+
| 想定ユースケース | コマ・人物・台詞のレイアウト解析 | 上記 + **顔単位**のクロップ・表情解析 |
|
| 161 |
+
|
| 162 |
+
`body` の定義は v1 と同一 (人物全体の bbox)。v2 では `face` を追加で別 bbox として持っており、`body` 内に `face` がネストする形になります (`face ⊂ body` ではなく独立したアノテーションとして検出される)。
|
| 163 |
+
|
| 164 |
+
### ライセンス・帰属表示
|
| 165 |
+
|
| 166 |
+
**モデル本体: Apache License 2.0**
|
| 167 |
+
|
| 168 |
+
本モデルは **[Manga109-s](http://www.manga109.org/ja/download_s.html)** を学習データとして使用しています。Manga109-s の規約に従って以下を明示します:
|
| 169 |
+
|
| 170 |
+
- データセット本体は**同梱しません**。Manga109-s の取得は[公式サイト](http://www.manga109.org/ja/download_s.html)からの正規入手に従ってください。
|
| 171 |
+
- このモデルを使って Manga109-s 収録漫画画像の **複製・改変を商材化することは規約により禁止**されています。
|
| 172 |
+
- Manga109-s に基づく結果を公表する際は下記 2 論文の引用が必要です。
|
| 173 |
+
|
| 174 |
+
### 引用 (BibTeX)
|
| 175 |
+
|
| 176 |
+
```bibtex
|
| 177 |
+
@article{multimedia_aizawa_2020,
|
| 178 |
+
author={Kiyoharu Aizawa and Azuma Fujimoto and Atsushi Otsubo and Toru Ogawa and Yusuke Matsui and Koki Tsubota and Hikaru Ikuta},
|
| 179 |
+
title={Building a Manga Dataset ``Manga109'' with Annotations for Multimedia Applications},
|
| 180 |
+
journal={IEEE MultiMedia},
|
| 181 |
+
volume={27},
|
| 182 |
+
number={2},
|
| 183 |
+
pages={8--18},
|
| 184 |
+
doi={10.1109/mmul.2020.2987895},
|
| 185 |
+
year={2020}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
@article{mtap_matsui_2017,
|
| 189 |
+
author={Yusuke Matsui and Kota Ito and Yuji Aramaki and Azuma Fujimoto and Toru Ogawa and Toshihiko Yamasaki and Kiyoharu Aizawa},
|
| 190 |
+
title={Sketch-based Manga Retrieval using Manga109 Dataset},
|
| 191 |
+
journal={Multimedia Tools and Applications},
|
| 192 |
+
volume={76},
|
| 193 |
+
number={20},
|
| 194 |
+
pages={21811--21838},
|
| 195 |
+
doi={10.1007/s11042-016-4020-z},
|
| 196 |
+
year={2017}
|
| 197 |
+
}
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
### 謝辞
|
| 201 |
+
|
| 202 |
+
- [RT-DETRv4 / D-FINE](https://github.com/lyuwenyu/RT-DETR) (Apache 2.0) — 本モデルのベースアーキテクチャと学習コード
|
| 203 |
+
- [DINOv2](https://github.com/facebookresearch/dinov2) (Apache 2.0) — 蒸留教師モデル
|
| 204 |
+
- [HGNetv2](https://github.com/PaddlePaddle/PaddleClas) (Apache 2.0) — backbone
|
| 205 |
+
|
| 206 |
+
---
|
| 207 |
+
|
| 208 |
+
## English
|
| 209 |
+
|
| 210 |
+
### Overview
|
| 211 |
+
|
| 212 |
+
RT-DETRv4 (X-size) finetuned on **Manga109-s** for 4-class object detection on Japanese manga pages:
|
| 213 |
+
|
| 214 |
+
- `0: body` — characters / human figures
|
| 215 |
+
- `1: text` — dialogue balloons & text regions
|
| 216 |
+
- `2: frame` — panel borders
|
| 217 |
+
- `3: face` — character faces (added in v2)
|
| 218 |
+
|
| 219 |
+
This is the v2 release of [RT-DETRv4-X Manga109-s](../rtdetrv4-x-manga109s), with an additional **`face`** class on top of the original 3 classes. While v1 captured whole characters via `body`, v2 separates `body` (full figure) and `face` (head only), enabling face-level downstream tasks such as expression analysis or character cropping. Trained on 15,263 images (14,796 single pages + 467 retained spreads, split from Manga109-s) for 30 epochs with DINOv2 ViT-B/14 feature distillation. Pages whose bboxes cross the centerline are kept as full spreads, so the model handles both single pages and spreads at inference time. Intended for ComfyUI workflows, automated panel-level pipelines, and manga-domain research.
|
| 220 |
+
|
| 221 |
+
| | |
|
| 222 |
+
|---|---|
|
| 223 |
+
| Base architecture | [RT-DETRv4](https://github.com/lyuwenyu/RT-DETR) X-size (HGNetv2-B5 backbone + DFINETransformer decoder) |
|
| 224 |
+
| Distillation teacher | [DINOv2 ViT-B/14](https://github.com/facebookresearch/dinov2) (Apache 2.0) |
|
| 225 |
+
| Training data | [Manga109-s](http://www.manga109.org/en/download_s.html) — 87 commercially-licensed titles |
|
| 226 |
+
| Input resolution | 1280 × 1280 |
|
| 227 |
+
| Number of classes | 4 (body / text / frame / face) |
|
| 228 |
+
|
| 229 |
+
### Examples
|
| 230 |
+
|
| 231 |
+
bbox color coding: <span style="color:#9acd32">**yellow-green = frame (panel)**</span> / <span style="color:#1e90ff">**blue = body (character)**</span> / <span style="color:#dc143c">**red = text (dialogue)**</span> / <span style="color:#ff69b4">**pink = face**</span>
|
| 232 |
+
|
| 233 |
+

|
| 234 |
+
|
| 235 |
+
A finished, inked manga page. All four classes (panel / character / dialogue / face) are picked up with high precision.
|
| 236 |
+
|
| 237 |
+

|
| 238 |
+
|
| 239 |
+
A **rough hand-drawn "name" (storyboard / pre-inking sketch)**. Although the training data only contains finished manga, the model still recognises panels, characters, dialogue regions and faces reasonably well at the rough-draft stage.
|
| 240 |
+
|
| 241 |
+
### Performance
|
| 242 |
+
|
| 243 |
+
Evaluated on the Manga109-s validation split (1,212 pages, 30,252 boxes) with `best_stg2` (epoch 27):
|
| 244 |
+
|
| 245 |
+
| Metric | Value |
|
| 246 |
+
|---|---|
|
| 247 |
+
| mean mAP | **75.0%** |
|
| 248 |
+
| mean AP50 | **96.0%** |
|
| 249 |
+
| mean AP75 | **79.3%** |
|
| 250 |
+
| mean AR100 | **81.6%** |
|
| 251 |
+
| AP (small) | 21.4% |
|
| 252 |
+
| AP (medium) | 56.2% |
|
| 253 |
+
| AP (large) | 80.6% |
|
| 254 |
+
|
| 255 |
+
AP50 reaches 96% — virtually no missed detections in practical use. The remaining headroom is in IoU strictness (AP75) and especially in small-size bboxes (tiny dialogue balloons, faces in crowd scenes). The bottleneck is bbox-tightness, not recall.
|
| 256 |
+
|
| 257 |
+
### Files
|
| 258 |
+
|
| 259 |
+
| File | Description |
|
| 260 |
+
|---|---|
|
| 261 |
+
| `model.onnx` | ONNX, opset 17, static `1×3×1280×1280` input |
|
| 262 |
+
|
| 263 |
+
### Inference
|
| 264 |
+
|
| 265 |
+
The ONNX graph exposes:
|
| 266 |
+
|
| 267 |
+
- **inputs**: `images` (float32, NCHW, normalised to [0, 1]), `orig_target_sizes` (int64, `[N, 2]` = `[width, height]`)
|
| 268 |
+
- **outputs**: `labels` (int, `[N, 300]`), `boxes` (float32, `[N, 300, 4]`, `xyxy` in original image coordinates), `scores` (float32, `[N, 300]`)
|
| 269 |
+
|
| 270 |
+
Minimum working example with `onnxruntime`:
|
| 271 |
+
|
| 272 |
+
```python
|
| 273 |
+
import numpy as np
|
| 274 |
+
import onnxruntime as ort
|
| 275 |
+
from PIL import Image, ImageDraw
|
| 276 |
+
|
| 277 |
+
CLASS_NAMES = {0: "body", 1: "text", 2: "frame", 3: "face"}
|
| 278 |
+
INPUT_SIZE = 1280
|
| 279 |
+
CONF_THRESHOLD = 0.5
|
| 280 |
+
|
| 281 |
+
session = ort.InferenceSession(
|
| 282 |
+
"model.onnx",
|
| 283 |
+
providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
image = Image.open("page.jpg").convert("RGB")
|
| 287 |
+
W, H = image.size
|
| 288 |
+
|
| 289 |
+
# Preprocess: resize to 1280x1280, CHW float32 in [0, 1]
|
| 290 |
+
resized = image.resize((INPUT_SIZE, INPUT_SIZE), Image.BILINEAR)
|
| 291 |
+
arr = np.asarray(resized, dtype=np.float32) / 255.0
|
| 292 |
+
arr = arr.transpose(2, 0, 1)[None] # 1x3x1280x1280
|
| 293 |
+
orig_size = np.array([[W, H]], dtype=np.int64)
|
| 294 |
+
|
| 295 |
+
labels, boxes, scores = session.run(
|
| 296 |
+
None, {"images": arr, "orig_target_sizes": orig_size}
|
| 297 |
+
)
|
| 298 |
+
labels, boxes, scores = labels[0], boxes[0], scores[0]
|
| 299 |
+
|
| 300 |
+
# Filter by confidence (boxes are already in original image coordinates)
|
| 301 |
+
keep = scores >= CONF_THRESHOLD
|
| 302 |
+
print(f"Detected {int(keep.sum())} objects")
|
| 303 |
+
for cid, (x1, y1, x2, y2), s in zip(labels[keep], boxes[keep], scores[keep]):
|
| 304 |
+
print(f" {CLASS_NAMES[int(cid)]:5s} conf={s:.3f} "
|
| 305 |
+
f"bbox=({x1:.0f},{y1:.0f},{x2:.0f},{y2:.0f})")
|
| 306 |
+
|
| 307 |
+
# Visualise
|
| 308 |
+
draw = ImageDraw.Draw(image)
|
| 309 |
+
colors = {0: "blue", 1: "red", 2: "yellow", 3: "hotpink"}
|
| 310 |
+
for cid, (x1, y1, x2, y2) in zip(labels[keep], boxes[keep]):
|
| 311 |
+
draw.rectangle([x1, y1, x2, y2], outline=colors[int(cid)], width=3)
|
| 312 |
+
image.save("output.png")
|
| 313 |
+
```
|
| 314 |
+
|
| 315 |
+
For CPU-only inference, use `providers=["CPUExecutionProvider"]`. For GPU, install `onnxruntime-gpu`.
|
| 316 |
+
|
| 317 |
+
### Training
|
| 318 |
+
|
| 319 |
+
| | |
|
| 320 |
+
|---|---|
|
| 321 |
+
| Epochs | 30 (flat 15 + cosine 11 + no-aug 4) |
|
| 322 |
+
| Batch size | 16 (single GPU) |
|
| 323 |
+
| Optimiser | AdamW — `lr=2.5e-4`, backbone `lr=2.5e-6`, `weight_decay=1.25e-4` |
|
| 324 |
+
| Augmentation | Mosaic / RandomPhotometricDistort / RandomZoomOut / RandomIoUCrop, Mixup (epoch 2–15) |
|
| 325 |
+
| Distillation | DINOv2 ViT-B/14 feature distillation, `loss_distill` weight 20 (adaptive) |
|
| 326 |
+
| Train / val split | train: 15,263 images (14,796 single pages + 467 retained spreads) / val: 1,212 images (1,116 single pages + 96 retained spreads); 370,738 / 30,252 bboxes |
|
| 327 |
+
| Per-class bbox count (train) | body 109,480 / text 105,139 / frame 75,581 / face 80,538 |
|
| 328 |
+
| Per-class bbox count (val) | body 8,645 / text 8,433 / frame 6,541 / face 6,633 |
|
| 329 |
+
|
| 330 |
+
Manga109-s spreads were split at the centerline into single pages prior to training, **except** when an annotated bbox crossed the centerline — in that case the page was retained as a spread (mixed mode). This keeps the inference contract single-page-friendly while preserving cross-spread groundtruth boxes (e.g. panels or characters that span both pages) instead of clipping them away.
|
| 331 |
+
|
| 332 |
+
### Differences from v1
|
| 333 |
+
|
| 334 |
+
| Item | v1 | v2 |
|
| 335 |
+
|---|---|---|
|
| 336 |
+
| Number of classes | 3 (body / text / frame) | 4 (body / text / frame / **face**) |
|
| 337 |
+
| Train bbox total | 290,200 | 370,738 (+ face 80,538) |
|
| 338 |
+
| Val bbox total | 23,619 | 30,252 (+ face 6,633) |
|
| 339 |
+
| Use case | Layout analysis of panels / characters / dialogue | Above + **face-level** cropping & expression analysis |
|
| 340 |
+
|
| 341 |
+
The definition of `body` is unchanged from v1 (full-figure bbox). v2 additionally emits `face` as a separate, independent bbox — `face` is **not** strictly nested under `body`; both are detected in parallel.
|
| 342 |
+
|
| 343 |
+
### License & Attribution
|
| 344 |
+
|
| 345 |
+
**Model: Apache License 2.0.**
|
| 346 |
+
|
| 347 |
+
This model was trained on **[Manga109-s](http://www.manga109.org/en/download_s.html)**, whose terms of use require the following acknowledgements:
|
| 348 |
+
|
| 349 |
+
- The dataset itself is **not bundled** with this release. Obtain Manga109-s through the official channel.
|
| 350 |
+
- Using this model to **commercially redistribute or sell reproductions / derivatives of Manga109-s manga images is prohibited** by the dataset terms.
|
| 351 |
+
- The two papers below must be cited when reporting results that depend on Manga109-s.
|
| 352 |
+
|
| 353 |
+
### Citation
|
| 354 |
+
|
| 355 |
+
```bibtex
|
| 356 |
+
@article{multimedia_aizawa_2020,
|
| 357 |
+
author={Kiyoharu Aizawa and Azuma Fujimoto and Atsushi Otsubo and Toru Ogawa and Yusuke Matsui and Koki Tsubota and Hikaru Ikuta},
|
| 358 |
+
title={Building a Manga Dataset ``Manga109'' with Annotations for Multimedia Applications},
|
| 359 |
+
journal={IEEE MultiMedia},
|
| 360 |
+
volume={27},
|
| 361 |
+
number={2},
|
| 362 |
+
pages={8--18},
|
| 363 |
+
doi={10.1109/mmul.2020.2987895},
|
| 364 |
+
year={2020}
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
@article{mtap_matsui_2017,
|
| 368 |
+
author={Yusuke Matsui and Kota Ito and Yuji Aramaki and Azuma Fujimoto and Toru Ogawa and Toshihiko Yamasaki and Kiyoharu Aizawa},
|
| 369 |
+
title={Sketch-based Manga Retrieval using Manga109 Dataset},
|
| 370 |
+
journal={Multimedia Tools and Applications},
|
| 371 |
+
volume={76},
|
| 372 |
+
number={20},
|
| 373 |
+
pages={21811--21838},
|
| 374 |
+
doi={10.1007/s11042-016-4020-z},
|
| 375 |
+
year={2017}
|
| 376 |
+
}
|
| 377 |
+
```
|
| 378 |
+
|
| 379 |
+
### Acknowledgements
|
| 380 |
+
|
| 381 |
+
- [RT-DETRv4 / D-FINE](https://github.com/lyuwenyu/RT-DETR) (Apache 2.0) — base architecture and training code
|
| 382 |
+
- [DINOv2](https://github.com/facebookresearch/dinov2) (Apache 2.0) — distillation teacher
|
| 383 |
+
- [HGNetv2](https://github.com/PaddlePaddle/PaddleClas) (Apache 2.0) — backbone
|
model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a5c27646a2ae2e9c85671a1db30504debc9b0b816dc585235435c5e86c2c2b9
|
| 3 |
+
size 250159393
|
sampe1.png
ADDED
|
Git LFS Details
|
sampe2.png
ADDED
|
Git LFS Details
|