ocr_recognition预测attention模型报错
问题描述:使用models\PaddleCV\ocr_recognition训练attention模型(crnn_ctc模型使用正常),并在infer.py中重新保存为固化模型,使用paddle predictor预测报错,错误信息为: File "D:\pythonAPI\Python37\call_paddle_OCR.py", line 108, in test_image 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 "D:\pythonAPI\Python37\Lib\site-packages\paddle\fluid\framework.py", line 2525, in append_op
attrs=kwargs.get("attrs", None))
File "D:\pythonAPI\Python37\Lib\site-packages\paddle\fluid\layer_helper.py", line 43, in append_op
return self.main_program.current_block().append_op(*args, **kwargs)
File "D:\pythonAPI\Python37\Lib\site-packages\paddle\fluid\layers\sequence_lod.py", line 723, in sequence_expand
attrs={'ref_level': ref_level})
File "D:\LSS\OCR\ocr_recognition\attention_model.py", line 294, in attention_infer
pre_state_expanded = fluid.layers.sequence_expand(pre_state, pre_score)
File "D:\LSS\OCR\ocr_recognition\infer.py", line 63, in inference
ids = infer(images, num_classes, use_cudnn=True if args.use_gpu else False)
File "D:\LSS\OCR\ocr_recognition\infer.py", line 196, in main
inference(args)
File "D:\LSS\OCR\ocr_recognition\infer.py", line 200, in
Error Message Summary:
Error: Level number of Input(Y)'s lod should be greater than 0. [Hint: Expected y_lod.size() > 0UL, but received y_lod.size():0 <= 0UL:0.] at (D:\1.7.0\paddle\paddle\fluid\operators\sequence_ops\sequence_expand_op.cc:57) [operator < sequence_expand > error]
- 版本、环境信息: 1)PaddlePaddle版本:1.7.0 2)系统环境:win10,Python3.7 -预测代码 data = preprocess_image(image) data=[data] inputs = np.concatenate( list(map(lambda x: x[0][np.newaxis, :], data)), axis=0).astype("float32") input1=np.array([[0]], dtype='int64') input2=np.array([[1.]], dtype='float32') input_names = predictor.get_input_names() input_tensor0 = predictor.get_input_tensor(input_names[0]) input_tensor0.reshape(inputs.shape) input_tensor0.copy_from_cpu(inputs) if INFER_TYPE=="attention" :##'crnn_ctc' or 'attention' input_tensor1 = predictor.get_input_tensor(input_names[1]) input_tensor1.reshape(input1.shape) input_tensor1.copy_from_cpu(input1) input_tensor2 = predictor.get_input_tensor(input_names[2]) input_tensor2.reshape(input2.shape) input_tensor2.copy_from_cpu(input2) predictor.zero_copy_run()
- 模型保存代码: if args.save_inference:#保存 print("save freeze_model in :" + args.freeze_model_path) if args.model == "crnn_ctc": feed_var_names = ['pixel'] else: feed_var_names = ['pixel', 'init_ids', 'init_scores'] print(feed_var_names) test_program = fluid.default_main_program().clone(for_test=True) target_vars = ids fluid.io.save_inference_model(dirname=args.freeze_model_path, feeded_var_names=feed_var_names, target_vars=target_vars, main_program=test_program, executor=exe, model_filename='model', params_filename='params')
模型不保存,用同样的输入进行预测,会报错吗?
@yongqiangma 直接用infer.py预测都不报错
有可能是save_inference_model的时候发生了错误裁剪,等https://github.com/PaddlePaddle/Paddle/pull/23306 合入后再测试下吧
@prettyocean85 在ocr_recognition上使用inference_model测试了一下,发现没有报错。
再结合你的报错信息发现是输入的问题。 Error: Level number of Input(Y)'s lod should be greater than 0. [Hint: Expected y_lod.size() > 0UL, but received y_lod.size():0 <= 0UL:0.] at
你可以参考下python是如何处理输入数据的。
最简单的方法测试,修改infer.py使得其加载inference_model完成预测。

@jiweibo 修改infer.py可以完成预测,但是报错是使用零拷贝方式,数据处理是参考了python来做的,和训练用的数据没什么区别不知道为什么报错。预测代码如下(crnn_ctc模型使用正常):

@prettyocean85 看报错信息是输入tensor没有设置lod。
lod的概念请参考:https://www.paddlepaddle.org.cn/documentation/docs/zh/beginners_guide/basic_concept/lod_tensor.html#lod
另外请查看ocr_recognition中,对输入数据的处理,lod是如何设置的。
@jiweibo 添加set_lod后问题已解决,感谢