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
43.9k stars 7.8k forks source link

使用rec_r34_vd_tps_bilstm_ctc模型预测失败,请问如何解决? #78

Closed RABACCA8855 closed 4 years ago

RABACCA8855 commented 4 years ago

开发环境: win10,conda安装paddlepaddle=1.8。 已经成功生成model和params文件,只是部署预测的时候出了错。

运行predict_system的时候报错如下: Traceback (most recent call last): File "E:/jiajun LUO/OCR/PaddleOCR-develop/tools/infer/predict_system.py", line 121, in dt_boxes, rec_res = text_sys(img) File "E:/jiajun LUO/OCR/PaddleOCR-develop/tools/infer/predict_system.py", line 81, in call rec_res, elapse = self.text_recognizer(img_crop_list) File "E:\jiajun LUO\OCR\PaddleOCR-develop\tools\infer\predict_rec.py", line 81, in call self.predictor.zero_copy_run() paddle.fluid.core_avx.EnforceNotMet:


C++ Call Stacks (More useful to developers):

Windows not support stack backtrace yet.


Python Call Stacks (More useful to users):

File "F:\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\framework.py", line 2610, in append_op attrs=kwargs.get("attrs", None)) File "F:\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\layer_helper.py", line 43, in append_op return self.main_program.current_block().append_op(*args, **kwargs) File "F:\Anaconda3\envs\paddle\lib\site-packages\paddle\fluid\layers\nn.py", line 13779, in grid_sampler helper.append_op(type='grid_sampler', inputs=ipts, outputs={'Output': out}) File "E:\jiajun LUO\OCR\PaddleOCR-develop\ppocr\modeling\stns\tps.py", line 259, in call batch_I_r = layers.grid_sampler(x=image, grid=batch_P_prime) File "E:\jiajun LUO\OCR\PaddleOCR-develop\ppocr\modeling\architectures\rec_model.py", line 98, in call inputs = self.tps(image) File "E:\jiajun LUO\OCR\PaddleOCR-develop\tools\program.py", line 198, in build_export image, outputs = model(mode='export') File "E:/jiajun LUO/OCR/PaddleOCR-develop/tools/export_model.py", line 68, in main config, eval_program, startup_prog) File "E:/jiajun LUO/OCR/PaddleOCR-develop/tools/export_model.py", line 94, in main()


Error Message Summary:

InvalidArgumentError: Input(X) dims[3] and Input(Grid) dims[2] should be equal, but received X dimension3 != Grid dimension2 [Hint: Expected grid_dims[2] == x_dims[3], but received grid_dims[2]:100 != x_dims[3]:382.] at (D:\1.8.0cpu2\paddle\paddle\fluid\operators\grid_sampler_op.cc:72) [operator < grid_sampler > error]

LDOUBLEV commented 4 years ago
RABACCA8855 commented 4 years ago

@LDOUBLEV 我的运行指令如下:

python3 tools/export_model.py -c configs/rec/rec_r34_vd_tps_bilstm_ctc.yml -o Global.checkpoints=./ch_lite/ec_r34_vd_tps_bilstm_ctc/best_accuracy \ Global.save_inference_dir=./inference/rec/rec_r34_vd_tps_bilstm_ctc/

在/inference/rec/rec_r34_vd_tps_bilstm_ctc/ 成功生成了model和params文件。

tink2123 commented 4 years ago

在使用带tps的模型进行预测时,请添加参数 --rec_image_shape="3, 32, 100" --rec_char_type="en" 图片

后续我们会优化模型,简化预测过程,感谢使用

RABACCA8855 commented 4 years ago

@tink2123 你好 我已经设置了相同的参数,并且更换了预测图片(英文),安装了paddlepaddle1.7.2,但是还是报了相同的错误。按照相同的方法下载了rec_crnn.tar,转化成iinference的model和params之后,就能预测成功。

tink2123 commented 4 years ago

预测时添加参数也报错吗? 预测时的命令可以发一下吗?

RABACCA8855 commented 4 years ago

@tink2123 这是我预测命令。帖子的错误就是加载rec_r34_vd_tps_bilstm_ctc模型的时候报错的,但是加载rec_crnn就能预测成功。 python3 tools/infer/predict_system.py --image_dir="./doc/imgs/" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/"

tink2123 commented 4 years ago

在使用带tps的模型进行预测时,请添加参数 --rec_image_shape="3, 32, 100" --rec_char_type="en"

请试一下这个命令: python3 tools/infer/predict_system.py --image_dir="./doc/imgs/" --det_model_dir="./inference/det/" --rec_model_dir="./inference/rec/" --rec_image_shape="3, 32, 100" --rec_char_type="en"

rec_crnn 模型中没有grid_sampler这个op,所以没有影响。

RABACCA8855 commented 4 years ago

@tink2123 已经成功了,谢谢你!我原本只是在rec_r34_vd_tps_bilstm_ctc.yml中修改参数,并且在utility中的 parser.add_argument中添加default路径,直接运行predict_system的,没注意修改rec_image_shape和rec_char_type的默认值。另外多问一句,这个模型只能预测英文小写字母和数字,是吧?

tink2123 commented 4 years ago

是的,目前发布的模型中,除了9m轻量级模型外,都只能预测英文。需要的话,您可以使用自己的中文数据训练后进行预测。

RABACCA8855 commented 4 years ago

@tink2123 好的 非常感谢!