diff --git a/PaddleCV/ocr_recognition/README.md b/PaddleCV/ocr_recognition/README.md index f6ad4c905bebcf2628ac751e2b9d7e5db902d8ed..60106e93b1d5d4b4081ffb37594cc2e56383010e 100644 --- a/PaddleCV/ocr_recognition/README.md +++ b/PaddleCV/ocr_recognition/README.md @@ -1,4 +1,4 @@ ->注意:在paddle1.5版本上训练attention model有收敛问题,建议您暂时使用paddle1.4版本,后续我们会修复该问题。 +>注意:在paddle1.5版本上训练attention model有收敛问题,建议您暂时使用paddle1.4版本和models1.5分支,后续我们会修复该问题。 ## 代码结构 ``` diff --git a/PaddleCV/ocr_recognition/attention_model.py b/PaddleCV/ocr_recognition/attention_model.py index 963d2168fd6ec4f53724573895344825c18558a3..6cbdd2b7944cb6a759e9b15d93ed62eae2214485 100755 --- a/PaddleCV/ocr_recognition/attention_model.py +++ b/PaddleCV/ocr_recognition/attention_model.py @@ -165,11 +165,11 @@ def gru_decoder_with_attention(target_embedding, encoder_vec, encoder_proj, def attention_train_net(args, data_shape, num_classes): - images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') - label_in = fluid.layers.data( - name='label_in', shape=[1], dtype='int32', lod_level=1) - label_out = fluid.layers.data( - name='label_out', shape=[1], dtype='int32', lod_level=1) + images = fluid.data(name='pixel', shape=[None] + data_shape, dtype='float32') + label_in = fluid.data( + name='label_in', shape=[None, 1], dtype='int32', lod_level=1) + label_out = fluid.data( + name='label_out', shape=[None, 1], dtype='int32', lod_level=1) gru_backward, encoded_vector, encoded_proj = encoder_net(images) @@ -264,10 +264,10 @@ def attention_infer(images, num_classes, use_cudnn=True): ids_array = fluid.layers.create_array('int64') scores_array = fluid.layers.create_array('float32') - init_ids = fluid.layers.data( - name="init_ids", shape=[1], dtype="int64", lod_level=2) - init_scores = fluid.layers.data( - name="init_scores", shape=[1], dtype="float32", lod_level=2) + init_ids = fluid.data( + name="init_ids", shape=[None, 1], dtype="int64", lod_level=2) + init_scores = fluid.data( + name="init_scores", shape=[None, 1], dtype="float32", lod_level=2) fluid.layers.array_write(init_ids, array=ids_array, i=counter) fluid.layers.array_write(init_scores, array=scores_array, i=counter) @@ -349,11 +349,11 @@ def attention_infer(images, num_classes, use_cudnn=True): def attention_eval(data_shape, num_classes, use_cudnn=True): - images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') - label_in = fluid.layers.data( - name='label_in', shape=[1], dtype='int32', lod_level=1) - label_out = fluid.layers.data( - name='label_out', shape=[1], dtype='int32', lod_level=1) + images = fluid.data(name='pixel', shape=[None] + data_shape, dtype='float32') + label_in = fluid.data( + name='label_in', shape=[None, 1], dtype='int32', lod_level=1) + label_out = fluid.data( + name='label_out', shape=[None, 1], dtype='int32', lod_level=1) label_out = fluid.layers.cast(x=label_out, dtype='int64') label_in = fluid.layers.cast(x=label_in, dtype='int64') diff --git a/PaddleCV/ocr_recognition/crnn_ctc_model.py b/PaddleCV/ocr_recognition/crnn_ctc_model.py index 178f329299104eed2c5c3d8b1c56a66f487f694a..0c3c517fa73eae7a32eb3e1bfcec2c4b6b279a85 100755 --- a/PaddleCV/ocr_recognition/crnn_ctc_model.py +++ b/PaddleCV/ocr_recognition/crnn_ctc_model.py @@ -190,9 +190,9 @@ def ctc_train_net(args, data_shape, num_classes): learning_rate_decay = None regularizer = fluid.regularizer.L2Decay(L2_RATE) - images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') - label = fluid.layers.data( - name='label', shape=[1], dtype='int32', lod_level=1) + images = fluid.data(name='pixel', shape=[None] + data_shape, dtype='float32') + label = fluid.data( + name='label', shape=[None, 1], dtype='int32', lod_level=1) fc_out = encoder_net( images, num_classes, diff --git a/PaddleCV/ocr_recognition/data_reader.py b/PaddleCV/ocr_recognition/data_reader.py index f1b529391d9fb2ba8f2c43ce2257b29ac971374b..7c074abbae1390c678edbd180b9bf5815c1d3452 100644 --- a/PaddleCV/ocr_recognition/data_reader.py +++ b/PaddleCV/ocr_recognition/data_reader.py @@ -32,7 +32,7 @@ except NameError: SOS = 0 EOS = 1 NUM_CLASSES = 95 -DATA_SHAPE = [1, 48, 512] +DATA_SHAPE = [1, 48, None] DATA_MD5 = "7256b1d5420d8c3e74815196e58cdad5" DATA_URL = "http://paddle-ocr-data.bj.bcebos.com/data.tar.gz" diff --git a/PaddleCV/ocr_recognition/eval.py b/PaddleCV/ocr_recognition/eval.py index c139331e3a313791ac3d8df70a5f8e35a4dded49..071c975cab9495be0acd9322b5531a792b1bb396 100644 --- a/PaddleCV/ocr_recognition/eval.py +++ b/PaddleCV/ocr_recognition/eval.py @@ -13,7 +13,7 @@ # limitations under the License. import paddle.fluid as fluid from utility import add_arguments, print_arguments, to_lodtensor, get_ctc_feeder_data, get_attention_feeder_data -from utility import check_gpu +from utility import check_gpu, check_version from attention_model import attention_eval from crnn_ctc_model import ctc_eval import data_reader @@ -85,6 +85,7 @@ def main(): args = parser.parse_args() print_arguments(args) check_gpu(args.use_gpu) + check_version() evaluate(args) diff --git a/PaddleCV/ocr_recognition/infer.py b/PaddleCV/ocr_recognition/infer.py index 7b790b5226d61e88648710b83b53789350ba6652..06a2a09bcb97f1d105e01d149bac87d829dba09d 100755 --- a/PaddleCV/ocr_recognition/infer.py +++ b/PaddleCV/ocr_recognition/infer.py @@ -14,7 +14,7 @@ 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, get_ctc_feeder_for_infer -from utility import check_gpu +from utility import check_gpu, check_version import paddle.fluid.profiler as profiler from crnn_ctc_model import ctc_infer from attention_model import attention_infer @@ -153,6 +153,7 @@ def main(): args = parser.parse_args() print_arguments(args) check_gpu(args.use_gpu) + check_version() if args.profile: if args.use_gpu: with profiler.cuda_profiler("cuda_profiler.txt", 'csv') as nvprof: diff --git a/PaddleCV/ocr_recognition/train.py b/PaddleCV/ocr_recognition/train.py index 3baf0535b71551a41105b45627cfd8395775e842..8e3c38ea97e3e5bfe7c12739c01e6cf28b636501 100755 --- a/PaddleCV/ocr_recognition/train.py +++ b/PaddleCV/ocr_recognition/train.py @@ -17,7 +17,7 @@ from __future__ import division 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_data -from utility import check_gpu +from utility import check_gpu, check_version import paddle.fluid.profiler as profiler from crnn_ctc_model import ctc_train_net from attention_model import attention_train_net @@ -230,6 +230,7 @@ def main(): args = parser.parse_args() print_arguments(args) check_gpu(args.use_gpu) + check_version() if args.profile: if args.use_gpu: with profiler.cuda_profiler("cuda_profiler.txt", 'csv') as nvprof: diff --git a/PaddleCV/ocr_recognition/utility.py b/PaddleCV/ocr_recognition/utility.py index 3d548e246e7d3ff8e684fd92e413e7c5205c7c0b..dbe650bb962390bd5bc82839f49e0f8184ff994e 100755 --- a/PaddleCV/ocr_recognition/utility.py +++ b/PaddleCV/ocr_recognition/utility.py @@ -159,3 +159,18 @@ def check_gpu(use_gpu): sys.exit(1) except Exception as e: pass + +def check_version(): + """ + Log error and exit when the installed version of paddlepaddle is + not satisfied. + """ + err = "PaddlePaddle version 1.6 or higher is required, " \ + "or a suitable develop version is satisfied as well. \n" \ + "Please make sure the version is good with your code." \ + + try: + fluid.require_version('1.6.0') + except Exception as e: + logger.error(err) + sys.exit(1)