#16232运行onnx模型推理时,报错"invalid input 'img' in NormalizeImage"

lightlprlightlpr
opened 2 months ago
Author

🔎 Search before asking

  • I have searched the PaddleOCR Docs and found no similar bug report.
  • I have searched the PaddleOCR Issues and found no similar bug report.
  • I have searched the PaddleOCR Discussions and found no similar bug report.

🐛 Bug (问题描述)

按照在线文档 http://www.paddleocr.ai/latest/version2.x/legacy/paddle2onnx.html?h=onnx#_3 文档里给的步骤,在release/3.1版本上运行PP-OCRv4_mobile_det_infer, PP-OCRv4_mobile_rec_infer和ch_ppocr_mobile_v2.0_cls_infer,报下面的错误,不知道3.1版本是否支持onnx推理?

$ python3 tools/infer/predict_system.py --use_gpu=False --use_onnx=True --det_model_dir=./inference/det_onnx/model.onnx --rec_model_dir=./inference/rec_onnx/model.onnx --cls_model_dir=./inference/cls_onnx/model.onnx --image_dir=./docs/images/demo.gif [2025/08/14 08:50:15] ppocr INFO: In PP-OCRv3, rec_image_shape parameter defaults to '3, 48, 320', if you are using recognition model with PP-OCRv2 or an older version, please set --rec_image_shape='3,32,320 <ppocr.data.imaug.operators.DetResizeForTest object at 0x7f4d86e74ee0> <ppocr.data.imaug.operators.NormalizeImage object at 0x7f4d86e74f70> image shape----- (512, 960, 3) <class 'numpy.ndarray'> Normalize shape 0.003921569 [[[0.485 0.456 0.406]]] (1, 1, 3) Traceback (most recent call last): File "/train-data/research/PaddleOCR/tools/infer/predict_system.py", line 326, in <module> main(args) File "/train-data/research/PaddleOCR/tools/infer/predict_system.py", line 227, in main dt_boxes, rec_res, time_dict = text_sys(img) File "/train-data/research/PaddleOCR/tools/infer/predict_system.py", line 109, in __call__ dt_boxes, elapse = self.text_detector(img) File "/train-data/research/PaddleOCR/tools/infer/predict_det.py", line 407, in __call__ dt_boxes, elapse = self.predict(img) File "/train-data/research/PaddleOCR/tools/infer/predict_det.py", line 250, in predict data = transform(data, self.preprocess_op) File "/train-data/research/PaddleOCR/ppocr/data/imaug/__init__.py", line 74, in transform data = op(data) File "/train-data/research/PaddleOCR/ppocr/data/imaug/operators.py", line 84, in __call__ assert isinstance(img, np.ndarray), "invalid input 'img' in NormalizeImage" AssertionError: invalid input 'img' in NormalizeImage

🏃‍♂️ Environment (运行环境)

OS ubuntu18, conda python 3.9.13 PaddleOCR 3.1

🌰 Minimal Reproducible Example (最小可复现问题的Demo)

python3 tools/infer/predict_system.py --use_gpu=False --use_onnx=True --det_model_dir=./inference/det_onnx/model.onnx --rec_model_dir=./inference/rec_onnx/model.onnx --cls_model_dir=./inference/cls_onnx/model.onnx --image_dir=./docs/images/demo.gif