Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用多语言检测模型转onnx时报错 #36

Open
yunqianluo opened this issue Feb 11, 2025 · 1 comment
Open

使用多语言检测模型转onnx时报错 #36

yunqianluo opened this issue Feb 11, 2025 · 1 comment

Comments

@yunqianluo
Copy link

yunqianluo commented Feb 11, 2025

非常棒的工作。使用多语言检测模型onnx时出现了下面的情况
1、运行环境
numpy 1.26.4
onnxruntime 1.14.1
onnxruntime-gpu 1.14.1
opencv-contrib-python 4.7.0.72
opencv-python 4.11.0.86
opencv-python-headless 4.7.0.72
opt-einsum 3.3.0
packaging 24.2
paddle2onnx 1.2.4
paddlepaddle 2.6.0
2、使用多语言检测模型Multilingual_PP-OCRv3_det_infer出现错误
import cv2
import time
from onnxocr.onnx_paddleocr import ONNXPaddleOcr,sav2Img
import sys

det_model_dir = '/data/app/paddlepaddle/Multilingual_PP-OCRv3_det_infer.onnx'
rec_model_dir = '/data/app/paddlepaddle/cyrillic_PP-OCRv3_rec_infer.onnx'
rec_char_dict_path = '/data/app/paddlepaddle/OnnxOCR-main/onnxocr/dict/cyrillic_dict.txt'
cls_model_dir = '/data/app/paddlepaddle/ch_ppocr_mobile_v2.0_cls_infer.onnx'

det_limit_side_len = 960

model = ONNXPaddleOcr(det_limit_side_len=det_limit_side_len, det_model_dir=det_model_dir, rec_model_dir=rec_model_dir, rec_char_dict_path=rec_char_dict_path, cls_model_dir=cls_model_dir, use_angle_cls=True, use_gpu=False, use_onnx=True)

imgpath = ''
img = cv2.imread('./onnxocr/test_images/ru.png')
s = time.time()
result = model.ocr(img)
e = time.time()
print("total time: {:.3f}".format(e - s))
print("result:", result)
for box in result[0]:
print(box)

sav2Img(img, result)
运行时出现下列错误:

outputs = self.det_onnx_session.run(self.det_output_name, input_feed=input_feed)
File "/home/xxxx/anaconda3paddle/envs/paddle2onnx/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 200, in run
return self._sess.run(output_names, input_feed, run_options)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: x for the following indices
index: 3 Got: 832 Expected: 960
Please fix either the inputs or the model.

请问一下这是什么原因?

@jingsongliujing
Copy link
Owner

识别模型的输入大小不对,修改这里:https://github.com/jingsongliujing/OnnxOCR/blob/main/onnxocr/utils.py
或者切换到master分支用master分支的代码

Image

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants