PaddleOCR icon indicating copy to clipboard operation
PaddleOCR copied to clipboard

Paddle OCR 的训练模型转换为ONNX模型后识别效果发生改变,原来可以正确识别的,转换后识别错误了,请问是什么原因?

Open duodance opened this issue 2 years ago • 1 comments

duodance avatar Oct 29 '22 01:10 duodance

Same problem. The only thing I figured out recognition works correct with batch sizes 1, If we increase batch sizes, it start predict wrong. The other thing we noticed, if you resize images up to 420 in width it predict correct. However long lines of text will not be recognized.

grinay avatar Nov 15 '22 12:11 grinay

I also met this issue, and there are two solutions:

  • change the resize method and add a padding operator in the https://github.com/PaddlePaddle/PaddleOCR/blob/d8d76d59c90d922782a4c812f9c720ac77877d5a/tools/infer/predict_rec.py#L332-L341
  • retraining the model with padding=False.

Since the infer_rec.py calls https://github.com/PaddlePaddle/PaddleOCR/blob/d8d76d59c90d922782a4c812f9c720ac77877d5a/ppocr/data/imaug/rec_img_aug.py#L464-L476 and it contains a padding operator (default setting is True), the inference model can yield the consistent results as the training model, while the ONNX model calls resize_norm_img_svtr and the width ratio of the characters are inconsistent with the original.

This issue may relevant to https://github.com/PaddlePaddle/PaddleOCR/issues/7551.

thsno02 avatar Mar 09 '23 08:03 thsno02