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

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

Closed
RABACCA8855 opened this issue May 20, 2020 · 10 comments
Closed

Comments

@RABACCA8855
Copy link

RABACCA8855 commented May 20, 2020

开发环境:
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
Copy link
Collaborator

LDOUBLEV commented May 20, 2020

  • 建议安装paddle1.7 吧,目前还没适配paddle1.8
    安装请参考:https://paddlepaddle.org.cn/install/quick
  • 报错信息在 tools/export_model.py, 这个是生成inference 模型的脚本,是不是生成的model和params文件有问题,也麻烦提供下你运行的指令吧

@RABACCA8855
Copy link
Author

@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
Copy link
Collaborator

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

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

@RABACCA8855
Copy link
Author

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

@tink2123
Copy link
Collaborator

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

@RABACCA8855
Copy link
Author

@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
Copy link
Collaborator

在使用带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
Copy link
Author

RABACCA8855 commented May 20, 2020

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

@tink2123
Copy link
Collaborator

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

@RABACCA8855
Copy link
Author

@tink2123 好的 非常感谢!

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

3 participants