PaddlePaddle / PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
https://paddlepaddle.github.io/PaddleOCR/
Apache License 2.0
42.44k stars 7.66k forks source link

svtr+stn,inference和onnx模型推理精度差异很大 #13230

Closed Acheerfulloser closed 2 months ago

Acheerfulloser commented 2 months ago

问题描述 / Problem Description

推理精度

运行环境 / Runtime Environment

复现代码 / Reproduction Code

config文件: configs/rec/rec_svtrnet.yml

inference model: python tools/infer/predict_rec.py --image_dir="doc/pics/5.png" --rec_model_dir="./models/svtr_ch_all_stn" --rec_image_shape="3, 32, 480" --rec_char_dict_path="./ppocr/utils/labels.txt"

onnx model: python tools/infer/predict_rec.py --image_dir="doc/pics/5.png" --use_onnx=True --rec_model_dir="./models/svtr_ch_all_stn/inference.onnx" --rec_image_shape="3, 32, 480" --rec_char_dict_path="./ppocr/utils/labels.txt"

完整报错 / Complete Error Message

inference model: [2024/06/30 08:11:14] ppocr INFO: Predicts of doc/pics/5.png:(')pcHPJKOMNOPKGGHF)', 0.9971622824668884) onnx model: [2024/07/01 01:28:33] ppocr INFO: Predicts of doc/pics/5.png:('OG', 0.527418851852417)

可能解决方案 / Possible solutions

训练模型和推理模型输出精度损失在10e-8以内,但是转成onnx模型就在十分位或者百分位 尝试了模型库内的en_PP-OCRv3_rec_train infer分别转成onnx,结果都能对齐,说明环境没有问题 你们能提供一个stn+svtr的模型,可以发我测试一下精度吗?谢谢,随便都行,能测试精度就行

附件 / Appendix

GreatV commented 2 months ago

是不是没有使用动态shape的问题

Acheerfulloser commented 2 months ago

@GreatV "SVTR"在export_model.py里转推理模型时,默认的shape=[None] + input_shape,input_shape是config["Eval"]["dataset"]["transforms"][-2]['SVTRRecResizeImg']['image_shape']获得的,这个和训练的值保持一致

GreatV commented 2 months ago

你的onnx模型里面输入shape是多少呀

Acheerfulloser commented 2 months ago

float32[p2o.DynamicDimension.0,3,32,480] 或者float32[1,3,32,480] 都试过