YuzuMarker Font Detection — Safetensors conversion

An unofficial, tensor-only Safetensors conversion of the CJK font recognizer from JeffersonQin/YuzuMarker.FontDetection. The converted checkpoint is the one the upstream demo Space runs. The original author is Haoyun Qin. This repository is maintained by mayocream and isn't an official release.

Model details

  • Architecture: torchvision ResNet-50 with its last layer replaced by 2048 → 6162.
  • Input: an RGB crop around the text, stretched to 512×512 without keeping its aspect ratio, scaled to 0–1, not normalized.
  • Outputs, in order:
    • 6,150 font logits (softmax), one per font file in fonts.json.
    • 2 text-direction logits (softmax): ltr, ttb.
    • 10 regression values (sigmoid): text colour RGB, text size, stroke width, stroke colour RGB, line spacing, and angle. Sizes and spacing are fractions of the crop's width, and the angle is angle / 180 + 0.5.
  • Format: Safetensors with the original FP32 values (BatchNorm's num_batches_tracked stays int64).

config.json records the same layout and preprocessing.

Files and provenance

  • model.safetensors: 320 tensors in torchvision ResNet-50 names.
  • fonts.json: the class index of each font, with its path in the training font collection and its language. The upstream demo reads this list from font_demo_cache.bin in its Space's base image; it was read here without executing the pickle.
  • config.json: architecture, preprocessing and output layout.
  • LICENSE: the upstream MIT license.
  • kernels.json: each font's script kernel, aligned with fonts.json (below).
  • Source checkpoint: name=4x-epoch=18-step=368676.ckpt (SHA-256 4544568829be10a98653a2c965f82fb229d5e02146578ccb3402518d9c022b1a).
  • Upstream code: 0a94e165.

Conversion guarantees

  • The source was loaded with torch.load(weights_only=True).
  • Only the model's tensors were exported. Optimizer, scheduler and trainer state were dropped.
  • The only change to the names is the removal of the wrapper prefix model._orig_mod.model.. Shapes, dtypes and values are preserved.
  • The output was reloaded and compared tensor by tensor with torch.equal.
  • On 18 test images, all 6,162 outputs of the converted and original models were identical.
  • The Safetensors header records the source file, its SHA-256, epoch and step.

Kernels

kernels.json gives each font, by its index in fonts.json, the broad style it belongs to, so a font's probability can be summed into its kernel's. It was labelled for Koharu, not by upstream, and holds no font data.

The 19 kernels follow the classifications of Morisawa, Founder and DynaComware: antique, mincho, fangsong, gothic, rounded, kaisho, gyokai, gyosho, sosho, reisho, tensho, kointai, weibei, textbook, brush, handwriting, pop, design, decorative.

Each label comes from the first of these that names one:

  1. a review by eye of the font's upstream sample image;
  2. the kernel its file name carries, such as 明朝, 黑, 丸ゴ, 楷 or Kyokasho;
  3. the vendor's own category;
  4. the folder of the training pack;
  5. an ink classifier on the sample image, trusted only for mincho, gothic and rounded;
  6. the majority of the font's family;
  7. its nearest neighbours in the model's own embedding.

On stratified samples, labels from names were right 51 times in 57, and labels from neighbours on Chinese and Korean fonts about 3 times in 4.

Training data

According to the upstream repository, the model was trained only on synthetic images: text rendered with PIL onto random crops of images scraped from pixiv. The fonts were the CJK font pack published by VCB-Studio. The Japanese text was song lyrics from uta-net, and the Chinese and Korean text was random common characters, mixed with English words. This checkpoint comes from the run on the fourfold synthetic set. The fonts aren't included here.

Intended use and limitations

  • It names the closest of 6,150 font files, many of them commercial, not a font you may have.
  • Upstream reports accuracy only for other checkpoints, measured on its own synthetic test split: at best 48.99% top-1 among 6,150 fonts. This checkpoint's accuracy isn't reported.
  • Upstream hasn't evaluated it on real images.
  • Crops are stretched to a square, so long single lines and columns reach the network distorted.

License

MIT, as upstream:

Copyright (c) 2021 gyro永不抽风

The full text is in LICENSE.

Downloads last month
74
Safetensors
Model size
36.2M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support