Replies: 1 comment
-
根据你的报错信息:
这是在使用 PP-OCRv3 的量化训练配置(en_PP-OCRv3_rec.yml)后,尝试导出 inference_model 时遇到的典型错误。这个问题主要发生在 PaddleOCR 进行 QAT(Quantization Aware Training)后,导出模型(export_model)时访问 config["Global"],但 config 被传成了一个 QAT 对象(class),而不是传统的 dict 类型。 问题分析PP-OCR 上游的导出脚本中,假设 config 是 dict 或 yaml 解析出来的对象,但新版本量化相关流程会把 QAT(如 paddleslim.quant.QAT 对象)直接传给 export_single_model,导致下标引用报错。典型报错发生在: if config["Global"].get("export_with_pir", False):
# ↑ QAT对象不可下标访问/不是字典 解决方案1. 检查 PaddleOCR 版本
2. 快速绕过:手动修复代码如果必须使用当前的代码,可以进入报错的 # 将
if config["Global"].get("export_with_pir", False):
# 改为
if hasattr(config, "get") and config.get("Global", {}).get("export_with_pir", False):
... 但实际上推荐直接用最新主分支的代码,很多地方做了类似兼容适配。 3. 使用后处理量化的模型导出方式如果你是 QAT 过程训练的最好方式,推荐使用官方文档中: python tools/export_model.py -c your_config.yml -o Global.pretrained_model=./output/rec/best_accuracy Global.save_inference_dir=./inference/rec 这样可以避免用 deploy/slim/quantization/export_model.py 旧脚本,减少兼容性bug。 4. 相关 Issues/Discussions
总结与建议主要原因是代码/配置对象类型不匹配,优先升级 PaddleOCR 到最新版,采用官方推荐量化和模型导出流程,遇到类型问题可手动适配,但推荐同步社区主分支。 如有模型导出成功但 onnx 推理出现 int8 权重不被支持问题,建议转用官方后处理量化( 如需全程可复现的量化导出 ONNX 教程,可参考官方quant化文档以及Discussions 13982。 如仍有报错,建议将 Paddle、PaddleSlim、PaddleOCR 全部升级至最新版后重试。 Response generated by 🤖 feifei-bot | gpt-4.1 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
报错如下,使用PP-OCRv3/en_PP-OCRv3_rec.yml进行量化训练,然后将其导出为inference_model模型
[2025/04/23 15:46:27] ppocr INFO: metric eval ***************
[2025/04/23 15:46:27] ppocr INFO: acc:0.9188640787248666
[2025/04/23 15:46:27] ppocr INFO: norm_edit_dis:0.9933991255575214
[2025/04/23 15:46:27] ppocr INFO: fps:199.93572715037868
Skipping import of the encryption module
Traceback (most recent call last):
File "/home/ubuntu/lsm/PaddleOCR/deploy/slim/quantization/export_model.py", line 189, in
main()
File "/home/ubuntu/lsm/PaddleOCR/deploy/slim/quantization/export_model.py", line 184, in main
export_single_model(model, arch_config, save_path, logger, input_shape, quanter)
File "/home/ubuntu/lsm/PaddleOCR/ppocr/utils/export_model.py", line 373, in export_single_model
if config["Global"].get("export_with_pir", False):
TypeError: 'QAT' object is not subscriptable
Beta Was this translation helpful? Give feedback.
All reactions