Repository: PaddlePaddle/models

Issue:
ocr_recognition预测问题
1.ctc模型预测报错：
Traceback (most recent call last):
  File "infer.py", line 153, in <module>
    main()
  File "infer.py", line 149, in main
    inference(args)
  File "infer.py", line 34, in inference
    get_feeder_data = get_ctc_feeder_for_infer
NameError: name 'get_ctc_feeder_for_infer' is not defined
2.attention模型预测报错：
Traceback (most recent call last):
  File "infer.py", line 153, in <module>
    main()
  File "infer.py", line 149, in main
    inference(args)
  File "infer.py", line 93, in inference
    return_numpy=False)
  File "/opt/_internal/cpython-3.6.0/lib/python3.6/site-packages/paddle/fluid/executor.py", line 565, in run
    use_program_cache=use_program_cache)
  File "/opt/_internal/cpython-3.6.0/lib/python3.6/site-packages/paddle/fluid/executor.py", line 642, in _run
    exe.run(program.desc, scope, 0, True, True, fetch_var_name)
paddle.fluid.core.EnforceNotMet: Invoke operator sequence_expand error.
Python Callstacks:
  File "/opt/_internal/cpython-3.6.0/lib/python3.6/site-packages/paddle/fluid/framework.py", line 1654, in append_op
    attrs=kwargs.get("attrs", None))
  File "/opt/_internal/cpython-3.6.0/lib/python3.6/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op
    return self.main_program.current_block().append_op(*args, **kwargs)
  File "/opt/_internal/cpython-3.6.0/lib/python3.6/site-packages/paddle/fluid/layers/nn.py", line 3940, in sequence_expand
    attrs={'ref_level': ref_level})
  File "/ssd1/xiege/model/models-develop/PaddleCV/ocr_recognition/attention_model.py", line 218, in simple_attention
    x=decoder_state_proj, y=encoder_proj)
  File "/ssd1/xiege/model/models-develop/PaddleCV/ocr_recognition/attention_model.py", line 279, in attention_infer
    decoder_size)
  File "infer.py", line 44, in inference
    ids = infer(images, num_classes, use_cudnn=True if args.use_gpu else False)
  File "infer.py", line 149, in main
    inference(args)
  File "infer.py", line 153, in <module>
    main()
C++ Callstacks:
Enforce failed. Expected x_dims[0] == static_cast<int64_t>(y_lod[ref_level].size()) - 1, but received x_dims[0]:2 != static_cast<int64_t>(y_lod[ref_level].size()) - 1:1.
When Input(X)'s lod is null, the dims[0] of Input(X) should match the size of Input(Y)'s referred level lod. at [/paddle/paddle/fluid/operators/sequence_ops/sequence_expand_op.cc:76]


Discussion:
能问下，你的ctc模型能训练吗，或者在哪里修改了，我用attention训练后预测也是出现的一模一样的错误，paddle我用的1.4.1，python3.7
@L-lei https://github.com/PaddlePaddle/models/blob/develop/PaddleCV/ocr_recognition/infer.py#L3
这一行需要加上get_ctc_feeder_for_infer
第2个错是因为beam size == 2的情况，网络配置有问题。建议先设置beam size为1.

Resolving patch:
diff --git a/PaddleCV/ocr_recognition/attention_model.py b/PaddleCV/ocr_recognition/attention_model.py
--- a/PaddleCV/ocr_recognition/attention_model.py
+++ b/PaddleCV/ocr_recognition/attention_model.py
@@ -11,7 +11,7 @@
 eos = 1
 gradient_clip = 10
 LR = 1.0
-beam_size = 2
+beam_size = 1
 learning_rate_decay = None
 
 
diff --git a/PaddleCV/ocr_recognition/infer.py b/PaddleCV/ocr_recognition/infer.py
--- a/PaddleCV/ocr_recognition/infer.py
+++ b/PaddleCV/ocr_recognition/infer.py
@@ -1,6 +1,6 @@
 from __future__ import print_function
 import paddle.fluid as fluid
-from utility import add_arguments, print_arguments, to_lodtensor, get_ctc_feeder_data, get_attention_feeder_for_infer
+from utility import add_arguments, print_arguments, to_lodtensor, get_ctc_feeder_data, get_attention_feeder_for_infer, get_ctc_feeder_for_infer
 import paddle.fluid.profiler as profiler
 from crnn_ctc_model import ctc_infer
 from attention_model import attention_infer


Test patch: