yolov5-kao — 花押検出 YOLOv5x

日本の古文書(中世〜近世の手書き文書)から 花押(かおう)を矩形で検出する YOLOv5x。単一クラス kao。 東京大学史料編纂所「花押データベース」由来のデータで学習。

花押は文書末尾の署名位置に据えられる図案化された自署で、差出人同定の鍵となる。本モデルはその位置の検出のみを行い、誰の花押かの同定(人物比定)は行わない。

🚀 デモ / Demo: nakamura196/yolov5-kao — ブラウザから画像をアップロードして試せます。

English: A YOLOv5x detector that localizes kaō (花押, stylized personal monogram signatures) in pre-modern Japanese handwritten documents as single-class bounding boxes. Trained on data derived from the Kaō Database of the Historiographical Institute, the University of Tokyo. Detection only — it does not identify whose monogram a detection is.

権利・ライセンス / License

⚠️ 学習データは東京大学史料編纂所「花押データベース」由来で、元データは権利留保です。 本モデル重みは other (kaou-db-derived-rights-reserved) 扱いです。

  • 非営利の学術研究・教育目的での利用(推論・評価・ファインチューニング)は、出典明記の上で可能です。
  • 商用利用・重みの再配布は事前に確認してください(本リポジトリの Community タブ へ)。
  • 詳細は LICENSE を参照してください。
  • なお学習に用いた YOLOv5 (v6.x) 本体は Ultralytics による GPL-3.0 です。

English: Trained on data derived from the rights-reserved Kaō Database of the Historiographical Institute. Non-commercial academic research and educational use is permitted with attribution. For commercial use or weight redistribution, please ask first via the Community tab. Note that upstream YOLOv5 (v6.x) itself is GPL-3.0 by Ultralytics.

ファイル / Files

ファイル 内容
best.pt YOLOv5 重み(YOLOv5x, 単一クラス kao, fp16, 173MB)。torch.hub.load('ultralytics/yolov5', 'custom', path=...)
best.onnx ONNX 版(opset 12, fp32, 346MB)。入力 images [batch,3,1024,1024]batch のみ dynamic)/ 出力 output0 [batch,N,6]NMS 必須の生出力, N=64512)

推論パラメタ目安 / Suggested parameters: conf=0.25, iou=0.45, imgsz=1024

ONNX 出力形式の注意 / Output layout

YOLOv5 系の出力は YOLOv8/v11 系([batch,5,N])とレイアウトが異なります

output0[b, i, :] = (cx, cy, w, h, obj_conf, cls_conf)
score = obj_conf * cls_conf

座標は letterbox 後のピクセル(0..1024)。元画像へは pad を引いて scale で割り戻します。

H/W は 1024 固定です(batch のみ dynamic)。YOLOv5 の Detect はアンカーグリッドをエクスポート時のサイズで焼き込むため、任意解像度は入れられません。

使い方 / Usage

Python (YOLOv5 / torch.hub)

import torch
from huggingface_hub import hf_hub_download

weights = hf_hub_download("nakamura196/yolov5-kao", "best.pt")
model = torch.hub.load("ultralytics/yolov5", "custom", path=weights)
model.conf, model.iou = 0.25, 0.45

results = model("letter.jpg", size=1024)
print(results.pandas().xyxy[0])   # xmin, ymin, xmax, ymax, confidence, name
results.save()

ONNX (onnxruntime) — 前処理・後処理込み / full pre/post-processing

import cv2
import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download

CONF, IOU, SIZE = 0.25, 0.45, 1024

def letterbox(im, size=SIZE):
    h, w = im.shape[:2]
    r = min(size / h, size / w)
    nh, nw = round(h * r), round(w * r)
    canvas = np.full((size, size, 3), 114, np.uint8)
    top, left = (size - nh) // 2, (size - nw) // 2
    canvas[top:top + nh, left:left + nw] = cv2.resize(im, (nw, nh))
    return canvas, r, left, top

img = cv2.imread("letter.jpg")
inp, r, dx, dy = letterbox(img)
x = inp[:, :, ::-1].transpose(2, 0, 1)[None].astype(np.float32) / 255.0  # BGR→RGB, NCHW, 0–1

onnx_path = hf_hub_download("nakamura196/yolov5-kao", "best.onnx")
sess = ort.InferenceSession(onnx_path)
pred = sess.run(None, {"images": x})[0][0]        # (N, 6)

score = pred[:, 4] * pred[:, 5]                   # obj * cls
keep = score > CONF
cx, cy, w, h = pred[keep, 0], pred[keep, 1], pred[keep, 2], pred[keep, 3]
boxes = np.stack([cx - w / 2, cy - h / 2, w, h], 1)   # x,y,w,h (letterbox coords)
idx = cv2.dnn.NMSBoxes(boxes.tolist(), score[keep].tolist(), CONF, IOU)

H, W = img.shape[:2]
for i in np.asarray(idx).flatten():
    bx, by, bw, bh = boxes[i]
    x1, y1 = max(0, (bx - dx) / r), max(0, (by - dy) / r)      # back to original coords
    x2, y2 = min(W, (bx + bw - dx) / r), min(H, (by + bh - dy) / r)
    print(round(x1), round(y1), round(x2), round(y2), round(float(score[keep][i]), 3))

ブラウザ / Browser (onnxruntime-web)

同じ前処理・後処理で WebGPU / WASM どちらでも動作します(画像を外部に送らずクライアント内で完結)。 WASM EP での実測(Chrome headless, Apple Silicon, 1024px 1枚): セッション生成 1.1 秒 / 推論 15.4 秒。WebGPU 利用時はこれより大幅に高速です。

fp32 で 346MB あるため、モバイル端末ではロード時にタブが落ちることがあります。PC 推奨。

学習 / Training

  • ベース: yolov5x.pt(Ultralytics YOLOv5 v6.x)/ 単一クラス kao / imgsz=1024 / epochs=300 / batch=4
  • 学習日: 2022-08-11(Google Colab)
  • データ: 東京大学史料編纂所「花押データベース」由来の検出データセット
  • パラメタ数: 86.2M(fp16 で保存)
  • ONNX export: opset 12 / dynamic_axes={'images': {0: 'batch'}} / Detect.inplace=False

Base yolov5x.pt, single class, imgsz 1024, 300 epochs, batch 4, trained 2022-08-11 on Colab using a detection dataset derived from the Kaō Database above.

評価 / Evaluation

学習時の val 指標はチェックポイントに残っていません(best_fitness が未保存)。代わりに、学習データとは別の中世古文書コーパスへの適用結果を以下に示します。

未知コーパスへの適用(n=419 候補)

本モデルが出力した検出候補 419 件を、LLM マルチエージェント(書跡学/文書形式学/古文書学の 3 視点 + 統合 Reviewer)で正誤判定した結果:

判定 件数 比率
OK(花押と確定) 265 63.2%
NG(非花押・誤検出) 111 26.5%
要専門家確認(合議不成立) 43 10.3%

→ 確定分のみの精度 OK/(OK+NG) = **70.5%**。 一方 recall は高水準で、翻刻テキスト中の「(花押)」マーカー期待数と検出数を画像単位で突合した結果、検出漏れが疑われる画像は 393 中 1 件のみでした。

信頼度スコアの較正 / Confidence calibration

confidence n FP 率
0.0–0.3 15 0.467
0.3–0.5 62 0.548
0.5–0.7 66 0.394
0.7–0.9 90 0.322
0.9–1.0 186 0.081

conf を 0.9 以上に絞れば FP 率は 8% まで下がります。一方 0.3–0.5 帯は FP 率 55% と実質コインフリップで、単純な低閾値運用には向きません。用途に応じて閾値を上げることを強く推奨します。

⚠️ 上記は学習データ外の中世古文書 1 コーパスでの値であり、LLM 支援による判定(全件の人手 GT ではない)です。絶対的な精度指標としてではなく、運用上の目安として扱ってください。

できないこと・制約 / Limitations

  • 検出のみ: 「誰の花押か」の人物同定は行いません。
  • 系統的な誤検出が 2 種類あることが判明しています:
    • 草名(そうみょう): 自筆の草書体署名を花押として拾う。図案性が高く、形状だけでは花押と区別しにくい。差出人が特定の人物に偏る文書群では系統的に発生する。
    • 影字(かげじ): 紙背から透けて見える本紙側の花押・文字(裏写り)を検出する。
  • 信頼度スコアは中低域で較正が不十分(上表)。
  • 学習は史料編纂所 花押データベース由来。近代文書・版本・非日本語文書は未検証です。
  • 入力 1024×1024 固定(ONNX)。極端に大きい原本は縮小されるため、小さな花押では recall が落ちる可能性があります。

English: Detection only — it does not identify whose monogram it is. Two systematic false-positive modes are known: sōmyō (cursive autograph signatures, mistaken for monograms) and kageji (show-through of ink from the other side of the paper). Confidence is poorly calibrated below 0.9. Trained on medieval/early-modern Japanese documents; unverified elsewhere. ONNX input is fixed at 1024×1024.

引用 / Citation

@misc{nakamura2026yolov5kao,
  author       = {Nakamura, Satoru},
  title        = {yolov5-kao: YOLOv5x kao (monogram signature) detection
                  for pre-modern Japanese documents},
  year         = {2026},
  publisher    = {Hugging Face},
  howpublished = {\url{https://huggingface.co/nakamura196/yolov5-kao}}
}

学習データ原典として「東京大学史料編纂所 花押データベース」も併せて言及してください。 Please also acknowledge the source database (Historiographical Institute, the University of Tokyo) when citing.

関連モデル / Related models

モデル 用途
yolov11x-komonjo-char 古文書のくずし字文字検出
yolov11x-codh-char 古典籍のくずし字文字検出
metom-komonjo-onnx くずし字の単字認識

出典・謝辞 / Acknowledgements

  • 学習データ原典: 東京大学史料編纂所「花押データベース」/ 画像 IIIF (clioimg.hi.u-tokyo.ac.jp)
  • 検出器: Ultralytics YOLOv5 (GPL-3.0)
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for nakamura196/yolov5-kao

Quantized
(32)
this model

Space using nakamura196/yolov5-kao 1