项目场景:
百度飞浆OCR做识别,训练了自己的模型,在推理预测过程中报错
都是使用的v4进行训练的,CPU,PaddlePaddle2.6.1
问题描述
导出模型后,在推理预测时候,遇到了如下报错,有无大佬遇到过,尝试了各种方法。无果。。。
(OCRTest) D:\BaiduNetdiskDownload\PaddleOCR-dygraph\PaddleOCR-dygraph>python tools/infer/predict_rec.py --image_dir="D:/BaiduNetdiskDownload/PaddleOCR-dygraph/PaddleOCR-dygraph/train_data/2024_08_26_16_37_47.png" --rec_model_dir="D:/BaiduNetdiskDownload/PaddleOCR-dygraph/PaddleOCR-dygraph/output/db_lqq_infer/Student"
E0910 10:39:18.437500 19012 analysis_config.cc:125] Please use PaddlePaddle with GPU version.
[2024/09/10 10:39:19] 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
[2024/09/10 10:39:19] ppocr INFO: Traceback (most recent call last):
File "tools/infer/predict_rec.py", line 722, in main
rec_res, _ = text_recognizer(img_list)
File "tools/infer/predict_rec.py", line 670, in __call__
self.predictor.run()
ValueError: (InvalidArgument) Broadcast dimension mismatch. Operands could not be broadcast together with the shape of X = [1, 96, 3, 20] and the shape of Y = [1, 96, 4, 20]. Received [3] in X is not equal to [4] in Y at i:2.
[Hint: Expected x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1 == true, but received x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1:0 != true:1.] (at ..\paddle/phi/kernels/funcs/common_shape.h:86)
[operator < elementwise_add > error]
[2024/09/10 10:39:19] ppocr INFO: (InvalidArgument) Broadcast dimension mismatch. Operands could not be broadcast together with the shape of X = [1, 96, 3, 20] and the shape of Y = [1, 96, 4, 20]. Received [3] in X is not equal to [4] in Y at i:2.
[Hint: Expected x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1 == true, but received x_dims_array[i] == y_dims_array[i] || x_dims_array[i] <= 1 || y_dims_array[i] <= 1:0 != true:1.] (at ..\paddle/phi/kernels/funcs/common_shape.h:86)
[operator < elementwise_add > error]
问题解决
把推理命令换成下面这个
python tools/infer/predict_system.py --image_dir="D:/BaiduNetdiskDownload/PaddleOCR-dygraph/PaddleOCR-dygraph/train_data/2024_08_26_16_37_47.png" --det_model_dir="D:/BaiduNetdiskDownload/PaddleOCR-dygraph/PaddleOCR-dygraph/output/db_lqq_infer/Student" --rec_model_dir="D:/BaiduNetdiskDownload/PaddleOCR-dygraph/PaddleOCR-dygraph/inference_model/ch_PP-OCRv4_rec_infer"