manga-translator-ui-onnx

ONNX 格式的漫画翻译模型集合,从 manga-translator-uimanga-image-translator 的 PyTorch 权重转换而来。

模型列表

Detection(文字检测)

模型 文件 大小 架构 输入 输出
Default Detector detect-20241225.onnx 292 MB DBNet ResNet34 (B, 3, H, W) [-1, 1] db_map (B, 2, H/4, W/4) + mask (B, 1, H/8, W/8)

OCR(文字识别)

模型 文件 大小 架构 输入 输出
48px CTC ocr-48px-ctc.onnx 157 MB ResNet + Transformer + CTC (B, 3, 48, W) [0, 255] logits (B, seq_len, 19264)
48px Encoder ocr-48px-encoder.onnx 97 MB ConvNeXt + 4×Transformer Enc (B, 3, 48, W) [0, 255] memory (B, seq_len, 320)

字典文件

文件 用途
alphabet-all-v7.txt 48px/48px_encoder 字典(46272 字符)
alphabet-all-v5.txt 48px_ctc 字典(95997 字符)

快速使用

Detection

import onnxruntime as ort
import numpy as np

session = ort.InferenceSession("detect-20241225.onnx", providers=["CPUExecutionProvider"])
input_data = np.random.randn(1, 3, 1536, 1536).astype(np.float32)  # [-1, 1]
db_map, mask = session.run(None, {"input": input_data})

OCR (48px_ctc)

import onnxruntime as ort
import numpy as np

session = ort.InferenceSession("ocr-48px-ctc.onnx", providers=["CPUExecutionProvider"])

# 输入: 48px 高的文字行图片 (batch, 3, 48, width)
img = np.random.randn(1, 3, 48, 256).astype(np.float32)
logits = session.run(None, {"img": img})[0]  # (1, seq_len, 19264)

# CTC greedy decode
with open("alphabet-all-v5.txt") as f:
    dictionary = [line.rstrip('\n') for line in f]

pred = np.argmax(logits[0], axis=1)  # (seq_len,)
result = []
blank = 0
last = blank
for p in pred:
    if p != blank and p != last:
        result.append(dictionary[p])
    last = p
text = ''.join(result)

OCR (48px_encoder)

session = ort.InferenceSession("ocr-48px-encoder.onnx", providers=["CPUExecutionProvider"])
img = np.random.randn(1, 3, 48, 256).astype(np.float32)
memory = session.run(None, {"img": img})[0]  # (1, seq_len, 320)
# memory 供 decoder 做自回归解码使用

模型来源

转换脚本

  • convert_detect_to_onnx.py — 将 detect-20241225.ckpt 转为 ONNX
  • convert_ocr_to_onnx_v6.py — 将 ocr_ar_48px.ckptocr-ctc.ckpt 转为 ONNX
  • fix_48px_ctc.py — 修复 48px_ctc 的 wrapper,确保精度

完整文档

  • detect-20241225-onnx-usage.md — Detection 模型完整使用文档
  • ocr-usage.md — OCR 模型完整使用文档(含预处理、解码、批量推理)

许可证

原始权重来自 manga-image-translator(GPL-3.0),本仓库继承 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