#18364·PaddleOCR

PP-OCRv6/v5 unified rec ONNX 模型非 ASCII 输出为 CP1252 渲染的 UTF-8 字节(PP-OCRv6_small_rec_onnx)

Author: youming-aiCreated Sep 16, 2026Updated Sep 16, 2026

问题描述

使用官方导出的 ONNX 模型时,所有非 ASCII 字符都被识别为其 UTF-8 字节的 CP1252 渲染,例如 (E6 9C AC) → 本日é(C3 A9) → éññ;ASCII/英文完全正常(conf 1.00)。同样现象出现在 PP-OCRv5_mobile_rec_onnx + 其自带字典,以及 RapidAI 重导出的 PP-OCRv6_rec_small 上。

我们按 CTCLabelDecode 语义(argmax → 字符表)解码。想请教这类 unified 模型的正确配对/后处理方式:是否需要在解码端加一步 byte → UTF-8 还原?还是发布的 checkpoint 本应直接输出字符?

Environment

  • Model: PaddlePaddle/PP-OCRv6_small_rec_onnx/inference.onnx sha256 5435fd747c9e0efe15a96d0b378d5bd157e9492ed8fd80edf08f30d02fa24634
  • Dict: the model's own inference.yml / preprocessor_config.json character list (18710 entries); runtime table ['blank'] + dict + [' ']
  • Runtime: onnxruntime 1.19.2 (Python, CPU) — identical results with onnxruntime-web (WASM)
  • Preprocess: height 48, aspect-preserving width, (x/255 - 0.5) / 0.5, BGR per inference.yml (img_mode: BGR); padding to 320 also tested, no change

What we ruled out

  • ONNX head weight linear_8.w_0 (120×18710) is byte-identical to a region of the official inference.pdiparams → the export is faithful.
  • The vocabulary matches the official preprocessor_config.json character_list entry-for-entry (only difference: index 0 is the literal "blank").
  • Python onnxruntime and onnxruntime-web produce identical argmax indices and confidences → not a runtime/quantization artifact.
  • Graph contains a single CTC head (MultiHead/CTCHead/Linear) with output fetch_name_0 (softmax over 18710 classes) and no dead nodes.
  • NFKC also shows up in the labels: ü (C3 BC) decodes as Ã14 (¼ U+00BC → 1⁄4, and U+2044 is absent from the vocabulary).

Additional note

15 CP1252 byte values have no entry in the character list (0x81 0x8D 0x8F 0x90 0x9D, undefined in CP1252, plus 0x82 0x84 0x88 0x8B 0x98 0x9B 0xA0 0xA1 0xAD), so those bytes are never emitted and the text cannot be reconstructed downstream (measured: only 48–63 % of Chinese characters and 23 % of kana have all their bytes representable).

We can provide a minimal reproduction (rendered text images + expected text + raw model outputs) if that helps.