MX-Font++ β€” Korean Handwriting (B@340K)

MX-Font++ trained on a Korean font set (print + Nanum handwriting) to generate Korean glyphs in a given handwriting style. This is the main handwriting model from the project ("B@340K"), i.e. training step 340000.

Custom architecture, so transformers runs it as remote code (trust_remote_code=True) β€” the modeling file ships in this repo. The original training repo is πŸ‘‰ https://github.com/HERIUN/MXFontpp-korean

Files

  • model.safetensors + config.json + modeling_mxfontpp.py β€” inference weights (generator_ema) and the self-contained model code, for transformers. 30.8M params.
  • mxfontpp_korean_hand_340k.pth β€” full training checkpoint (generator, generator_ema, discriminator, optimizer states), for resuming training in the original repo.

Usage

pip install transformers torch torchvision einops
import torch
from PIL import Image
from torchvision import transforms
from transformers import AutoModel

model = AutoModel.from_pretrained(
    "HERIUN/mxfontpp-korean-handwriting", trust_remote_code=True
).eval()

tf = transforms.Compose([
    transforms.Resize((128, 128)),
    transforms.ToTensor(),
    transforms.Normalize([0.5], [0.5]),
])

# style_imgs: a few reference glyphs of the target style  -> (B, n_ref, 1, 128, 128)
# char_imgs : the content glyph from a source font        -> (B, 1,     1, 128, 128)
style = torch.stack([tf(Image.open(p).convert("L")) for p in ref_paths]).unsqueeze(0)
char = tf(Image.open(src_path).convert("L")).unsqueeze(0).unsqueeze(0)

with torch.no_grad():
    out = model(style_imgs=style, char_imgs=char)   # (B, 1, 128, 128), sigmoid: 0 = ink, 1 = paper

Image.fromarray((out[0, 0] * 255).byte().numpy()).save("gen.png")

Notes:

  • There is no image processor and no pipeline() support: the model takes two inputs (N style references + 1 content glyph), which no single-image task signature covers. Do the preprocessing above yourself.
  • n_ref is variable; more references average toward a more stable style.

Training

  • Trained from scratch on a Korean font set (print + Nanum handwriting) β€” not finetuned from any base checkpoint.
  • Data: free Korean fonts (Google Fonts + Naver Nanum handwriting), not redistributed. List in the repo's FONTS.md.
  • Steps: 340000. Korean decomposition/primals JSON are in the code repo.

Intended use & limitations

Meant to fill the long tail of a Korean font set (glyphs beyond the common KS2350 set) in a consistent style. Per-writer / out-of-distribution style transfer is not reliable β€” the style manifold collapses toward an average hand. Finetuning attempts to fix this (style_consist / style_supcon losses in the repo) hit a βˆ’0.02~βˆ’0.04 IoU ceiling and did not break the collapse. For faithful per-writer transfer use DM-Font instead; use this model for the in-distribution tail-fill it does well.

License & credit

MIT. Built on MX-Font++ and MX-Font (NAVER Corp., MIT).

Downloads last month
88
Safetensors
Model size
30.8M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using HERIUN/mxfontpp-korean-handwriting 1