manga-translator-ui-onnx
ONNX 格式的漫画翻译模型集合,从 manga-translator-ui 和 manga-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)
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"])
img = np.random.randn(1, 3, 48, 256).astype(np.float32)
logits = session.run(None, {"img": img})[0]
with open("alphabet-all-v5.txt") as f:
dictionary = [line.rstrip('\n') for line in f]
pred = np.argmax(logits[0], axis=1)
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]
模型来源
转换脚本
convert_detect_to_onnx.py — 将 detect-20241225.ckpt 转为 ONNX
convert_ocr_to_onnx_v6.py — 将 ocr_ar_48px.ckpt 和 ocr-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 许可证。