From 91f0573bc19a841f95fa7bc16bd7befde6ca7559 Mon Sep 17 00:00:00 2001 From: minqiyang Date: Thu, 26 Jul 2018 21:15:49 +0800 Subject: [PATCH] Fix the overfix of 2to3 for print function --- CMakeLists.txt | 1 + python/paddle/fluid/optimizer.py | 2 +- .../fit_a_line/test_fit_a_line.py | 2 +- .../test_image_classification_resnet.py | 4 +-- .../test_image_classification_vgg.py | 4 +-- .../test_label_semantic_roles_newapi.py | 20 +++++++------- .../test_machine_translation.py | 4 +-- .../test_recognize_digits_conv.py | 10 +++---- .../test_recognize_digits_mlp.py | 10 +++---- .../test_recommender_system_newapi.py | 4 +-- .../test_understand_sentiment_conv.py | 26 +++++++++---------- .../test_understand_sentiment_dynamic_rnn.py | 26 +++++++++---------- .../test_understand_sentiment_stacked_lstm.py | 26 +++++++++---------- .../word2vec/test_word2vec_new_api.py | 4 +-- .../tests/book/notest_understand_sentiment.py | 20 +++++++------- .../fluid/tests/book/test_fit_a_line.py | 6 ++--- .../tests/book/test_image_classification.py | 8 +++--- .../tests/book/test_label_semantic_roles.py | 22 ++++++++-------- .../tests/book/test_machine_translation.py | 6 ++--- .../fluid/tests/book/test_recognize_digits.py | 6 ++--- .../tests/book/test_recommender_system.py | 14 +++++----- .../tests/book/test_rnn_encoder_decoder.py | 22 ++++++++-------- .../paddle/fluid/tests/book/test_word2vec.py | 14 +++++----- .../test_memopt_fit_a_line.py | 2 +- .../test_memopt_image_classification_train.py | 4 +-- .../test_memopt_machine_translation.py | 4 +-- python/paddle/fluid/tests/demo/fc_gan.py | 4 +-- python/paddle/fluid/tests/test_detection.py | 8 +++--- python/paddle/fluid/tests/test_if_else_op.py | 4 +-- .../paddle/fluid/tests/unittests/benchmark.py | 8 +++--- .../unittests/parallel_executor_test_base.py | 6 ++--- .../memory_optimization_transpiler.py | 10 +++---- 32 files changed, 156 insertions(+), 155 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 231224f924..f180b5cfa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ option(PY_VERSION "Compile PaddlePaddle with python3 support" ${PY_VER if(NOT PY_VERSION) set(PY_VERSION 2.7) endif() +set(PYBIND11_PYTHON_VERSION ${PY_VERSION}) # CMAKE_BUILD_TYPE if(NOT CMAKE_BUILD_TYPE) diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index a3c32cfea6..a07325f46a 100644 --- a/python/paddle/fluid/optimizer.py +++ b/python/paddle/fluid/optimizer.py @@ -106,7 +106,7 @@ class Optimizer(object): param_lr = param.optimize_attr['learning_rate'] if type(param_lr) == Variable: # param learning rate has been updated (LARS) - print(("returns updated param lr ", param_lr)) + print("returns updated param lr ", param_lr) return param_lr else: if param_lr == 1.0: diff --git a/python/paddle/fluid/tests/book/high-level-api/fit_a_line/test_fit_a_line.py b/python/paddle/fluid/tests/book/high-level-api/fit_a_line/test_fit_a_line.py index a27e6c45f6..36a1a223cf 100644 --- a/python/paddle/fluid/tests/book/high-level-api/fit_a_line/test_fit_a_line.py +++ b/python/paddle/fluid/tests/book/high-level-api/fit_a_line/test_fit_a_line.py @@ -94,7 +94,7 @@ def infer(use_cuda, inference_program, params_dirname=None): tensor_x = numpy.random.uniform(0, 10, [batch_size, 13]).astype("float32") results = inferencer.infer({'x': tensor_x}) - print(("infer results: ", results[0])) + print("infer results: ", results[0]) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_resnet.py b/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_resnet.py index 8f38d53ea1..a1f62db093 100644 --- a/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_resnet.py +++ b/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_resnet.py @@ -105,7 +105,7 @@ def train(use_cuda, train_program, params_dirname): avg_cost, accuracy = trainer.test( reader=test_reader, feed_order=['pixel', 'label']) - print(('Loss {0:2.2}, Acc {1:2.2}'.format(avg_cost, accuracy))) + print('Loss {0:2.2}, Acc {1:2.2}'.format(avg_cost, accuracy)) if accuracy > 0.01: # Low threshold for speeding up CI if params_dirname is not None: @@ -134,7 +134,7 @@ def infer(use_cuda, inference_program, params_dirname=None): tensor_img = numpy.random.rand(1, 3, 32, 32).astype("float32") results = inferencer.infer({'pixel': tensor_img}) - print(("infer results: ", results)) + print("infer results: ", results) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py b/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py index f37d3e6d6d..8429551765 100644 --- a/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py +++ b/python/paddle/fluid/tests/book/high-level-api/image_classification/test_image_classification_vgg.py @@ -82,7 +82,7 @@ def train(use_cuda, train_program, params_dirname): avg_cost, accuracy = trainer.test( reader=test_reader, feed_order=['pixel', 'label']) - print(('Loss {0:2.2}, Acc {1:2.2}'.format(avg_cost, accuracy))) + print('Loss {0:2.2}, Acc {1:2.2}'.format(avg_cost, accuracy)) if accuracy > 0.01: # Low threshold for speeding up CI if params_dirname is not None: @@ -111,7 +111,7 @@ def infer(use_cuda, inference_program, params_dirname=None): tensor_img = numpy.random.rand(1, 3, 32, 32).astype("float32") results = inferencer.infer({'pixel': tensor_img}) - print(("infer results: ", results)) + print("infer results: ", results) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/label_semantic_roles/test_label_semantic_roles_newapi.py b/python/paddle/fluid/tests/book/high-level-api/label_semantic_roles/test_label_semantic_roles_newapi.py index 6e177478e8..e3602e2d56 100755 --- a/python/paddle/fluid/tests/book/high-level-api/label_semantic_roles/test_label_semantic_roles_newapi.py +++ b/python/paddle/fluid/tests/book/high-level-api/label_semantic_roles/test_label_semantic_roles_newapi.py @@ -171,7 +171,7 @@ def train(use_cuda, train_program, params_dirname): # get avg cost avg_cost = np.array(avg_cost_set).mean() - print(("avg_cost: %s" % avg_cost)) + print("avg_cost: %s" % avg_cost) if float(avg_cost) < 100.0: # Large value to increase CI speed trainer.save_params(params_dirname) @@ -183,8 +183,8 @@ def train(use_cuda, train_program, params_dirname): sys.exit("got NaN loss, training failed.") elif isinstance(event, fluid.EndStepEvent): - print(("Step {0}, Epoch {1} Metrics {2}".format( - event.step, event.epoch, list(map(np.array, event.metrics))))) + print("Step {0}, Epoch {1} Metrics {2}".format( + event.step, event.epoch, list(map(np.array, event.metrics)))) if event.step == 1: # Run 2 iterations to speed CI trainer.save_params(params_dirname) trainer.stop() @@ -206,14 +206,14 @@ def infer(use_cuda, inference_program, params_dirname): inference_program, param_path=params_dirname, place=place) # Setup input by creating LoDTensor to represent sequence of words. - # Here each word is the basic element of the LoDTensor and the shape of - # each word (base_shape) should be [1] since it is simply an index to + # Here each word is the basic element of the LoDTensor and the shape of + # each word (base_shape) should be [1] since it is simply an index to # look up for the corresponding word vector. # Suppose the recursive_sequence_lengths info is set to [[3, 4, 2]], - # which has only one level of detail. Then the created LoDTensor will have only - # one higher level structure (sequence of words, or sentence) than the basic - # element (word). Hence the LoDTensor will hold data for three sentences of - # length 3, 4 and 2, respectively. + # which has only one level of detail. Then the created LoDTensor will have only + # one higher level structure (sequence of words, or sentence) than the basic + # element (word). Hence the LoDTensor will hold data for three sentences of + # length 3, 4 and 2, respectively. # Note that recursive_sequence_lengths should be a list of lists. recursive_seq_lens = [[3, 4, 2]] base_shape = [1] @@ -248,7 +248,7 @@ def infer(use_cuda, inference_program, params_dirname): }, return_numpy=False) - print(("infer results: ", np.array(results[0]).shape)) + print("infer results: ", np.array(results[0]).shape) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/machine_translation/test_machine_translation.py b/python/paddle/fluid/tests/book/high-level-api/machine_translation/test_machine_translation.py index c8dbea4807..6fb0c85a8b 100644 --- a/python/paddle/fluid/tests/book/high-level-api/machine_translation/test_machine_translation.py +++ b/python/paddle/fluid/tests/book/high-level-api/machine_translation/test_machine_translation.py @@ -197,7 +197,7 @@ def train(use_cuda, is_sparse, is_local=True): def event_handler(event): if isinstance(event, fluid.EndStepEvent): - print(('pass_id=' + str(event.epoch) + ' batch=' + str(event.step))) + print('pass_id=' + str(event.epoch) + ' batch=' + str(event.step)) if event.step == 10: trainer.stop() @@ -259,7 +259,7 @@ def decode_main(use_cuda, is_sparse): feed=feed_dict, fetch_list=[translation_ids, translation_scores], return_numpy=False) - print((result_ids.recursive_sequence_lengths())) + print(result_ids.recursive_sequence_lengths()) break diff --git a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py index 2ade9a4bc6..898807db6f 100644 --- a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py +++ b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py @@ -78,14 +78,14 @@ def train(use_cuda, train_program, params_dirname): avg_cost, acc = trainer.test( reader=test_reader, feed_order=['img', 'label']) - print(("avg_cost: %s" % avg_cost)) - print(("acc : %s" % acc)) + print("avg_cost: %s" % avg_cost) + print("acc : %s" % acc) if acc > 0.2: # Smaller value to increase CI speed trainer.save_params(params_dirname) else: - print(('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.epoch + 1, avg_cost, acc))) + print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( + event.epoch + 1, avg_cost, acc)) if math.isnan(avg_cost): sys.exit("got NaN loss, training failed.") elif isinstance(event, fluid.EndStepEvent): @@ -118,7 +118,7 @@ def infer(use_cuda, inference_program, params_dirname=None): results = inferencer.infer({'img': tensor_img}) - print(("infer results: ", results[0])) + print("infer results: ", results[0]) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py index ddf7d05d43..6dd64be315 100644 --- a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py +++ b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py @@ -61,14 +61,14 @@ def train(use_cuda, train_program, params_dirname): avg_cost, acc = trainer.test( reader=test_reader, feed_order=['img', 'label']) - print(("avg_cost: %s" % avg_cost)) - print(("acc : %s" % acc)) + print("avg_cost: %s" % avg_cost) + print("acc : %s" % acc) if acc > 0.2: # Smaller value to increase CI speed trainer.save_params(params_dirname) else: - print(('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.epoch + 1, avg_cost, acc))) + print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( + event.epoch + 1, avg_cost, acc)) if math.isnan(avg_cost): sys.exit("got NaN loss, training failed.") @@ -96,7 +96,7 @@ def infer(use_cuda, inference_program, params_dirname=None): results = inferencer.infer({'img': tensor_img}) - print(("infer results: ", results[0])) + print("infer results: ", results[0]) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/recommender_system/test_recommender_system_newapi.py b/python/paddle/fluid/tests/book/high-level-api/recommender_system/test_recommender_system_newapi.py index 2605c1f56f..60f3d8e105 100644 --- a/python/paddle/fluid/tests/book/high-level-api/recommender_system/test_recommender_system_newapi.py +++ b/python/paddle/fluid/tests/book/high-level-api/recommender_system/test_recommender_system_newapi.py @@ -180,7 +180,7 @@ def train(use_cuda, train_program, params_dirname): # get avg cost avg_cost = np.array(avg_cost_set).mean() - print(("avg_cost: %s" % avg_cost)) + print("avg_cost: %s" % avg_cost) if float(avg_cost) < 4: # Smaller value to increase CI speed trainer.save_params(params_dirname) @@ -240,7 +240,7 @@ def infer(use_cuda, inference_program, params_dirname): }, return_numpy=False) - print(("infer results: ", np.array(results[0]))) + print("infer results: ", np.array(results[0])) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_conv.py b/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_conv.py index 4a739252e1..24e65d1bd5 100644 --- a/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_conv.py +++ b/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_conv.py @@ -82,21 +82,21 @@ def train(use_cuda, train_program, params_dirname): avg_cost, acc = trainer.test( reader=test_reader, feed_order=['words', 'label']) - print(("avg_cost: %s" % avg_cost)) - print(("acc : %s" % acc)) + print("avg_cost: %s" % avg_cost) + print("acc : %s" % acc) if acc > 0.2: # Smaller value to increase CI speed trainer.save_params(params_dirname) trainer.stop() else: - print(('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.epoch + 1, avg_cost, acc))) + print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( + event.epoch + 1, avg_cost, acc)) if math.isnan(avg_cost): sys.exit("got NaN loss, training failed.") elif isinstance(event, fluid.EndStepEvent): - print(("Step {0}, Epoch {1} Metrics {2}".format( - event.step, event.epoch, list(map(np.array, event.metrics))))) + print("Step {0}, Epoch {1} Metrics {2}".format( + event.step, event.epoch, list(map(np.array, event.metrics)))) if event.step == 1: # Run 2 iterations to speed CI trainer.save_params(params_dirname) trainer.stop() @@ -123,14 +123,14 @@ def infer(use_cuda, inference_program, params_dirname=None): place=place) # Setup input by creating LoDTensor to represent sequence of words. - # Here each word is the basic element of the LoDTensor and the shape of - # each word (base_shape) should be [1] since it is simply an index to + # Here each word is the basic element of the LoDTensor and the shape of + # each word (base_shape) should be [1] since it is simply an index to # look up for the corresponding word vector. # Suppose the recursive_sequence_lengths info is set to [[3, 4, 2]], - # which has only one level of detail. Then the created LoDTensor will have only - # one higher level structure (sequence of words, or sentence) than the basic - # element (word). Hence the LoDTensor will hold data for three sentences of - # length 3, 4 and 2, respectively. + # which has only one level of detail. Then the created LoDTensor will have only + # one higher level structure (sequence of words, or sentence) than the basic + # element (word). Hence the LoDTensor will hold data for three sentences of + # length 3, 4 and 2, respectively. # Note that recursive_sequence_lengths should be a list of lists. recursive_seq_lens = [[3, 4, 2]] base_shape = [1] @@ -138,7 +138,7 @@ def infer(use_cuda, inference_program, params_dirname=None): tensor_words = fluid.create_random_int_lodtensor( recursive_seq_lens, base_shape, place, low=0, high=len(word_dict) - 1) results = inferencer.infer({'words': tensor_words}) - print(("infer results: ", results)) + print("infer results: ", results) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_dynamic_rnn.py b/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_dynamic_rnn.py index 690d6e47c1..b3b1505a0f 100644 --- a/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_dynamic_rnn.py +++ b/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_dynamic_rnn.py @@ -97,21 +97,21 @@ def train(use_cuda, train_program, params_dirname): avg_cost, acc = trainer.test( reader=test_reader, feed_order=['words', 'label']) - print(("avg_cost: %s" % avg_cost)) - print(("acc : %s" % acc)) + print("avg_cost: %s" % avg_cost) + print("acc : %s" % acc) if acc > 0.2: # Smaller value to increase CI speed trainer.save_params(params_dirname) trainer.stop() else: - print(('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.epoch + 1, avg_cost, acc))) + print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( + event.epoch + 1, avg_cost, acc)) if math.isnan(avg_cost): sys.exit("got NaN loss, training failed.") elif isinstance(event, fluid.EndStepEvent): - print(("Step {0}, Epoch {1} Metrics {2}".format( - event.step, event.epoch, list(map(np.array, event.metrics))))) + print("Step {0}, Epoch {1} Metrics {2}".format( + event.step, event.epoch, list(map(np.array, event.metrics)))) if event.step == 1: # Run 2 iterations to speed CI trainer.save_params(params_dirname) trainer.stop() @@ -138,14 +138,14 @@ def infer(use_cuda, inference_program, params_dirname=None): place=place) # Setup input by creating LoDTensor to represent sequence of words. - # Here each word is the basic element of the LoDTensor and the shape of - # each word (base_shape) should be [1] since it is simply an index to + # Here each word is the basic element of the LoDTensor and the shape of + # each word (base_shape) should be [1] since it is simply an index to # look up for the corresponding word vector. # Suppose the recursive_sequence_lengths info is set to [[3, 4, 2]], - # which has only one level of detail. Then the created LoDTensor will have only - # one higher level structure (sequence of words, or sentence) than the basic - # element (word). Hence the LoDTensor will hold data for three sentences of - # length 3, 4 and 2, respectively. + # which has only one level of detail. Then the created LoDTensor will have only + # one higher level structure (sequence of words, or sentence) than the basic + # element (word). Hence the LoDTensor will hold data for three sentences of + # length 3, 4 and 2, respectively. # Note that recursive_sequence_lengths should be a list of lists. recursive_seq_lens = [[3, 4, 2]] base_shape = [1] @@ -153,7 +153,7 @@ def infer(use_cuda, inference_program, params_dirname=None): tensor_words = fluid.create_random_int_lodtensor( recursive_seq_lens, base_shape, place, low=0, high=len(word_dict) - 1) results = inferencer.infer({'words': tensor_words}) - print(("infer results: ", results)) + print("infer results: ", results) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_stacked_lstm.py b/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_stacked_lstm.py index af41abaf23..25f99ff0fd 100644 --- a/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_stacked_lstm.py +++ b/python/paddle/fluid/tests/book/high-level-api/understand_sentiment/test_understand_sentiment_stacked_lstm.py @@ -91,21 +91,21 @@ def train(use_cuda, train_program, params_dirname): avg_cost, acc = trainer.test( reader=test_reader, feed_order=['words', 'label']) - print(("avg_cost: %s" % avg_cost)) - print(("acc : %s" % acc)) + print("avg_cost: %s" % avg_cost) + print("acc : %s" % acc) if acc > 0.2: # Smaller value to increase CI speed trainer.save_params(params_dirname) trainer.stop() else: - print(('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.epoch + 1, avg_cost, acc))) + print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( + event.epoch + 1, avg_cost, acc)) if math.isnan(avg_cost): sys.exit("got NaN loss, training failed.") elif isinstance(event, fluid.EndStepEvent): - print(("Step {0}, Epoch {1} Metrics {2}".format( - event.step, event.epoch, list(map(np.array, event.metrics))))) + print("Step {0}, Epoch {1} Metrics {2}".format( + event.step, event.epoch, list(map(np.array, event.metrics)))) if event.step == 1: # Run 2 iterations to speed CI trainer.save_params(params_dirname) trainer.stop() @@ -133,14 +133,14 @@ def infer(use_cuda, inference_program, params_dirname=None): place=place) # Setup input by creating LoDTensor to represent sequence of words. - # Here each word is the basic element of the LoDTensor and the shape of - # each word (base_shape) should be [1] since it is simply an index to + # Here each word is the basic element of the LoDTensor and the shape of + # each word (base_shape) should be [1] since it is simply an index to # look up for the corresponding word vector. # Suppose the recursive_sequence_lengths info is set to [[3, 4, 2]], - # which has only one level of detail. Then the created LoDTensor will have only - # one higher level structure (sequence of words, or sentence) than the basic - # element (word). Hence the LoDTensor will hold data for three sentences of - # length 3, 4 and 2, respectively. + # which has only one level of detail. Then the created LoDTensor will have only + # one higher level structure (sequence of words, or sentence) than the basic + # element (word). Hence the LoDTensor will hold data for three sentences of + # length 3, 4 and 2, respectively. # Note that recursive_sequence_lengths should be a list of lists. recursive_seq_lens = [[3, 4, 2]] base_shape = [1] @@ -148,7 +148,7 @@ def infer(use_cuda, inference_program, params_dirname=None): tensor_words = fluid.create_random_int_lodtensor( recursive_seq_lens, base_shape, place, low=0, high=len(word_dict) - 1) results = inferencer.infer({'words': tensor_words}) - print(("infer results: ", results)) + print("infer results: ", results) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/high-level-api/word2vec/test_word2vec_new_api.py b/python/paddle/fluid/tests/book/high-level-api/word2vec/test_word2vec_new_api.py index 8e32f90d65..02e65cf56c 100644 --- a/python/paddle/fluid/tests/book/high-level-api/word2vec/test_word2vec_new_api.py +++ b/python/paddle/fluid/tests/book/high-level-api/word2vec/test_word2vec_new_api.py @@ -98,7 +98,7 @@ def train(use_cuda, train_program, params_dirname): reader=test_reader, feed_order=['firstw', 'secondw', 'thirdw', 'forthw', 'nextw']) avg_cost = outs[0] - print(("loss= ", avg_cost)) + print("loss= ", avg_cost) if avg_cost < 10.0: trainer.save_params(params_dirname) @@ -149,7 +149,7 @@ def infer(use_cuda, inference_program, params_dirname=None): 'forthw': fourth_word }, return_numpy=False) - print((np.array(result[0]))) + print(np.array(result[0])) def main(use_cuda, is_sparse): diff --git a/python/paddle/fluid/tests/book/notest_understand_sentiment.py b/python/paddle/fluid/tests/book/notest_understand_sentiment.py index 2b5585149d..ce6342c2da 100644 --- a/python/paddle/fluid/tests/book/notest_understand_sentiment.py +++ b/python/paddle/fluid/tests/book/notest_understand_sentiment.py @@ -180,7 +180,7 @@ def train(word_dict, cost_val, acc_val = exe.run(main_program, feed=feeder.feed(data), fetch_list=[cost, acc_out]) - print(("cost=" + str(cost_val) + " acc=" + str(acc_val))) + print("cost=" + str(cost_val) + " acc=" + str(acc_val)) if cost_val < 0.4 and acc_val > 0.8: if save_dirname is not None: fluid.io.save_inference_model(save_dirname, ["words"], @@ -235,14 +235,14 @@ def infer(word_dict, use_cuda, save_dirname=None): word_dict_len = len(word_dict) # Setup input by creating LoDTensor to represent sequence of words. - # Here each word is the basic element of the LoDTensor and the shape of - # each word (base_shape) should be [1] since it is simply an index to + # Here each word is the basic element of the LoDTensor and the shape of + # each word (base_shape) should be [1] since it is simply an index to # look up for the corresponding word vector. # Suppose the recursive_sequence_lengths info is set to [[3, 4, 2]], - # which has only one level of detail. Then the created LoDTensor will have only - # one higher level structure (sequence of words, or sentence) than the basic - # element (word). Hence the LoDTensor will hold data for three sentences of - # length 3, 4 and 2, respectively. + # which has only one level of detail. Then the created LoDTensor will have only + # one higher level structure (sequence of words, or sentence) than the basic + # element (word). Hence the LoDTensor will hold data for three sentences of + # length 3, 4 and 2, respectively. # Note that recursive_sequence_lengths should be a list of lists. recursive_seq_lens = [[3, 4, 2]] base_shape = [1] @@ -261,10 +261,10 @@ def infer(word_dict, use_cuda, save_dirname=None): feed={feed_target_names[0]: tensor_words}, fetch_list=fetch_targets, return_numpy=False) - print((results[0].recursive_sequence_lengths())) + print(results[0].recursive_sequence_lengths()) np_data = np.array(results[0]) - print(("Inference Shape: ", np_data.shape)) - print(("Inference results: ", np_data)) + print("Inference Shape: ", np_data.shape) + print("Inference results: ", np_data) def main(word_dict, net_method, use_cuda, parallel=False, save_dirname=None): diff --git a/python/paddle/fluid/tests/book/test_fit_a_line.py b/python/paddle/fluid/tests/book/test_fit_a_line.py index 58bcbdfb03..37b64fa94a 100644 --- a/python/paddle/fluid/tests/book/test_fit_a_line.py +++ b/python/paddle/fluid/tests/book/test_fit_a_line.py @@ -124,9 +124,9 @@ def infer(use_cuda, save_dirname=None): results = exe.run(inference_program, feed={feed_target_names[0]: numpy.array(test_feat)}, fetch_list=fetch_targets) - print(("infer shape: ", results[0].shape)) - print(("infer results: ", results[0])) - print(("ground truth: ", test_label)) + print("infer shape: ", results[0].shape) + print("infer results: ", results[0]) + print("ground truth: ", test_label) def main(use_cuda, is_local=True): diff --git a/python/paddle/fluid/tests/book/test_image_classification.py b/python/paddle/fluid/tests/book/test_image_classification.py index 1c74481fa7..de6fe5f140 100644 --- a/python/paddle/fluid/tests/book/test_image_classification.py +++ b/python/paddle/fluid/tests/book/test_image_classification.py @@ -119,7 +119,7 @@ def train(net_type, use_cuda, save_dirname, is_local): avg_cost = fluid.layers.mean(cost) acc = fluid.layers.accuracy(input=predict, label=label) - # Test program + # Test program test_program = fluid.default_main_program().clone(for_test=True) optimizer = fluid.optimizer.Adam(learning_rate=0.001) @@ -163,10 +163,10 @@ def train(net_type, use_cuda, save_dirname, is_local): acc_value = numpy.array(acc_list).mean() avg_loss_value = numpy.array(avg_loss_list).mean() - print(( + print( 'PassID {0:1}, BatchID {1:04}, Test Loss {2:2.2}, Acc {3:2.2}'. format(pass_id, batch_id + 1, - float(avg_loss_value), float(acc_value)))) + float(avg_loss_value), float(acc_value))) if acc_value > 0.01: # Low threshold for speeding up CI fluid.io.save_inference_model(save_dirname, ["pixel"], @@ -239,7 +239,7 @@ def infer(use_cuda, save_dirname=None): np.testing.assert_almost_equal( results[0][i], transpiler_results[0][i], decimal=5) - print(("infer results: ", results[0])) + print("infer results: ", results[0]) fluid.io.save_inference_model(save_dirname, feed_target_names, fetch_targets, exe, diff --git a/python/paddle/fluid/tests/book/test_label_semantic_roles.py b/python/paddle/fluid/tests/book/test_label_semantic_roles.py index 9dbd462fb4..b7ac911caf 100644 --- a/python/paddle/fluid/tests/book/test_label_semantic_roles.py +++ b/python/paddle/fluid/tests/book/test_label_semantic_roles.py @@ -189,10 +189,10 @@ def train(use_cuda, save_dirname=None, is_local=True): cost = cost[0] if batch_id % 10 == 0: - print(("avg_cost:" + str(cost))) + print("avg_cost:" + str(cost)) if batch_id != 0: - print(("second per batch: " + str( - (time.time() - start_time) / batch_id))) + print("second per batch: " + str((time.time( + ) - start_time) / batch_id)) # Set the threshold low to speed up the CI test if float(cost) < 60.0: if save_dirname is not None: @@ -248,14 +248,14 @@ def infer(use_cuda, save_dirname=None): fetch_targets] = fluid.io.load_inference_model(save_dirname, exe) # Setup input by creating LoDTensor to represent sequence of words. - # Here each word is the basic element of the LoDTensor and the shape of - # each word (base_shape) should be [1] since it is simply an index to + # Here each word is the basic element of the LoDTensor and the shape of + # each word (base_shape) should be [1] since it is simply an index to # look up for the corresponding word vector. # Suppose the recursive_sequence_lengths info is set to [[3, 4, 2]], - # which has only one level of detail. Then the created LoDTensor will have only - # one higher level structure (sequence of words, or sentence) than the basic - # element (word). Hence the LoDTensor will hold data for three sentences of - # length 3, 4 and 2, respectively. + # which has only one level of detail. Then the created LoDTensor will have only + # one higher level structure (sequence of words, or sentence) than the basic + # element (word). Hence the LoDTensor will hold data for three sentences of + # length 3, 4 and 2, respectively. # Note that recursive_sequence_lengths should be a list of lists. recursive_seq_lens = [[3, 4, 2]] base_shape = [1] @@ -333,9 +333,9 @@ def infer(use_cuda, save_dirname=None): }, fetch_list=fetch_targets, return_numpy=False) - print((results[0].recursive_sequence_lengths())) + print(results[0].recursive_sequence_lengths()) np_data = np.array(results[0]) - print(("Inference Shape: ", np_data.shape)) + print("Inference Shape: ", np_data.shape) def main(use_cuda, is_local=True): diff --git a/python/paddle/fluid/tests/book/test_machine_translation.py b/python/paddle/fluid/tests/book/test_machine_translation.py index 6578328643..462faad3e1 100644 --- a/python/paddle/fluid/tests/book/test_machine_translation.py +++ b/python/paddle/fluid/tests/book/test_machine_translation.py @@ -205,8 +205,8 @@ def train_main(use_cuda, is_sparse, is_local=True): feed=feeder.feed(data), fetch_list=[avg_cost]) avg_cost_val = np.array(outs[0]) - print(('pass_id=' + str(pass_id) + ' batch=' + str(batch_id) + - " avg_cost=" + str(avg_cost_val))) + print('pass_id=' + str(pass_id) + ' batch=' + str(batch_id) + + " avg_cost=" + str(avg_cost_val)) if batch_id > 3: break batch_id += 1 @@ -282,7 +282,7 @@ def decode_main(use_cuda, is_sparse): feed=feed_dict, fetch_list=[translation_ids, translation_scores], return_numpy=False) - print((result_ids.recursive_sequence_lengths())) + print(result_ids.recursive_sequence_lengths()) break diff --git a/python/paddle/fluid/tests/book/test_recognize_digits.py b/python/paddle/fluid/tests/book/test_recognize_digits.py index 49e58a148a..3e5f76d12d 100644 --- a/python/paddle/fluid/tests/book/test_recognize_digits.py +++ b/python/paddle/fluid/tests/book/test_recognize_digits.py @@ -142,10 +142,10 @@ def train(nn_type, params_filename=params_filename) return else: - print(( + print( 'PassID {0:1}, BatchID {1:04}, Test Loss {2:2.2}, Acc {3:2.2}'. format(pass_id, batch_id + 1, - float(avg_loss_val), float(acc_val)))) + float(avg_loss_val), float(acc_val))) if math.isnan(float(avg_loss_val)): sys.exit("got NaN loss, training failed.") raise AssertionError("Loss of recognize digits is too large") @@ -206,7 +206,7 @@ def infer(use_cuda, results = exe.run(inference_program, feed={feed_target_names[0]: tensor_img}, fetch_list=fetch_targets) - print(("infer results: ", results[0])) + print("infer results: ", results[0]) def main(use_cuda, parallel, nn_type, combine): diff --git a/python/paddle/fluid/tests/book/test_recommender_system.py b/python/paddle/fluid/tests/book/test_recommender_system.py index ca396e5cdf..b30c8771fc 100644 --- a/python/paddle/fluid/tests/book/test_recommender_system.py +++ b/python/paddle/fluid/tests/book/test_recommender_system.py @@ -260,15 +260,15 @@ def infer(use_cuda, save_dirname=None): # Use the first data from paddle.dataset.movielens.test() as input assert feed_target_names[0] == "user_id" - # Use create_lod_tensor(data, recursive_sequence_lengths, place) API - # to generate LoD Tensor where `data` is a list of sequences of index - # numbers, `recursive_sequence_lengths` is the length-based level of detail + # Use create_lod_tensor(data, recursive_sequence_lengths, place) API + # to generate LoD Tensor where `data` is a list of sequences of index + # numbers, `recursive_sequence_lengths` is the length-based level of detail # (lod) info associated with `data`. # For example, data = [[10, 2, 3], [2, 3]] means that it contains # two sequences of indexes, of length 3 and 2, respectively. - # Correspondingly, recursive_sequence_lengths = [[3, 2]] contains one - # level of detail info, indicating that `data` consists of two sequences - # of length 3 and 2, respectively. + # Correspondingly, recursive_sequence_lengths = [[3, 2]] contains one + # level of detail info, indicating that `data` consists of two sequences + # of length 3 and 2, respectively. user_id = fluid.create_lod_tensor([[1]], [[1]], place) assert feed_target_names[1] == "gender_id" @@ -304,7 +304,7 @@ def infer(use_cuda, save_dirname=None): }, fetch_list=fetch_targets, return_numpy=False) - print(("inferred score: ", np.array(results[0]))) + print("inferred score: ", np.array(results[0])) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/test_rnn_encoder_decoder.py b/python/paddle/fluid/tests/book/test_rnn_encoder_decoder.py index 25181d8309..2e79be2bd0 100644 --- a/python/paddle/fluid/tests/book/test_rnn_encoder_decoder.py +++ b/python/paddle/fluid/tests/book/test_rnn_encoder_decoder.py @@ -182,8 +182,8 @@ def train(use_cuda, save_dirname=None): fetch_list=[avg_cost]) avg_cost_val = np.array(outs[0]) - print(('pass_id=' + str(pass_id) + ' batch=' + str(batch_id) + - " avg_cost=" + str(avg_cost_val))) + print('pass_id=' + str(pass_id) + ' batch=' + str(batch_id) + + " avg_cost=" + str(avg_cost_val)) if math.isnan(float(avg_cost_val[0])): sys.exit("got NaN loss, training failed.") if batch_id > 3: @@ -213,14 +213,14 @@ def infer(use_cuda, save_dirname=None): fetch_targets] = fluid.io.load_inference_model(save_dirname, exe) # Setup input by creating LoDTensor to represent sequence of words. - # Here each word is the basic element of the LoDTensor and the shape of - # each word (base_shape) should be [1] since it is simply an index to + # Here each word is the basic element of the LoDTensor and the shape of + # each word (base_shape) should be [1] since it is simply an index to # look up for the corresponding word vector. # Suppose the recursive_sequence_lengths info is set to [[4, 6]], - # which has only one level of detail. Then the created LoDTensor will have only - # one higher level structure (sequence of words, or sentence) than the basic - # element (word). Hence the LoDTensor will hold data for two sentences of - # length 4 and 6, respectively. + # which has only one level of detail. Then the created LoDTensor will have only + # one higher level structure (sequence of words, or sentence) than the basic + # element (word). Hence the LoDTensor will hold data for two sentences of + # length 4 and 6, respectively. # Note that recursive_sequence_lengths should be a list of lists. recursive_seq_lens = [[4, 6]] base_shape = [1] @@ -241,10 +241,10 @@ def infer(use_cuda, save_dirname=None): }, fetch_list=fetch_targets, return_numpy=False) - print((results[0].recursive_sequence_lengths())) + print(results[0].recursive_sequence_lengths()) np_data = np.array(results[0]) - print(("Inference shape: ", np_data.shape)) - print(("Inference results: ", np_data)) + print("Inference shape: ", np_data.shape) + print("Inference results: ", np_data) def main(use_cuda): diff --git a/python/paddle/fluid/tests/book/test_word2vec.py b/python/paddle/fluid/tests/book/test_word2vec.py index 61838440b0..e761e05795 100644 --- a/python/paddle/fluid/tests/book/test_word2vec.py +++ b/python/paddle/fluid/tests/book/test_word2vec.py @@ -169,11 +169,11 @@ def infer(use_cuda, save_dirname=None): word_dict = paddle.dataset.imikolov.build_dict() dict_size = len(word_dict) - # Setup inputs by creating 4 LoDTensors representing 4 words. Here each word - # is simply an index to look up for the corresponding word vector and hence - # the shape of word (base_shape) should be [1]. The recursive_sequence_lengths, - # which is length-based level of detail (lod) of each LoDTensor, should be [[1]] - # meaning there is only one level of detail and there is only one sequence of + # Setup inputs by creating 4 LoDTensors representing 4 words. Here each word + # is simply an index to look up for the corresponding word vector and hence + # the shape of word (base_shape) should be [1]. The recursive_sequence_lengths, + # which is length-based level of detail (lod) of each LoDTensor, should be [[1]] + # meaning there is only one level of detail and there is only one sequence of # one word on this level. # Note that recursive_sequence_lengths should be a list of lists. recursive_seq_lens = [[1]] @@ -204,9 +204,9 @@ def infer(use_cuda, save_dirname=None): }, fetch_list=fetch_targets, return_numpy=False) - print((results[0].recursive_sequence_lengths())) + print(results[0].recursive_sequence_lengths()) np_data = np.array(results[0]) - print(("Inference Shape: ", np_data.shape)) + print("Inference Shape: ", np_data.shape) def main(use_cuda, is_sparse, is_parallel): diff --git a/python/paddle/fluid/tests/book_memory_optimization/test_memopt_fit_a_line.py b/python/paddle/fluid/tests/book_memory_optimization/test_memopt_fit_a_line.py index e425da1f9d..ccc62b442f 100644 --- a/python/paddle/fluid/tests/book_memory_optimization/test_memopt_fit_a_line.py +++ b/python/paddle/fluid/tests/book_memory_optimization/test_memopt_fit_a_line.py @@ -78,7 +78,7 @@ for pass_id in range(PASS_NUM): if avg_loss_value[0] < 10.0: exit(0) # if avg cost less than 10.0, we think our code is good. - print((avg_loss_value[0])) + print(avg_loss_value[0]) if math.isnan(float(avg_loss_value)): sys.exit("got NaN loss, training failed.") exit(1) diff --git a/python/paddle/fluid/tests/book_memory_optimization/test_memopt_image_classification_train.py b/python/paddle/fluid/tests/book_memory_optimization/test_memopt_image_classification_train.py index 16e5c5f322..b2a59d27da 100644 --- a/python/paddle/fluid/tests/book_memory_optimization/test_memopt_image_classification_train.py +++ b/python/paddle/fluid/tests/book_memory_optimization/test_memopt_image_classification_train.py @@ -155,8 +155,8 @@ for pass_id in range(PASS_NUM): fetch_list=[avg_cost, batch_acc, batch_size]) accuracy.add(value=acc, weight=weight) pass_acc = accuracy.eval() - print(("loss:" + str(loss) + " acc:" + str(acc) + " pass_acc:" + - str(pass_acc))) + print("loss:" + str(loss) + " acc:" + str(acc) + " pass_acc:" + str( + pass_acc)) # this model is slow, so if we can train two mini batch, we think it works properly. if i > 0: exit(0) diff --git a/python/paddle/fluid/tests/book_memory_optimization/test_memopt_machine_translation.py b/python/paddle/fluid/tests/book_memory_optimization/test_memopt_machine_translation.py index f290dd3e6d..323ddfb691 100644 --- a/python/paddle/fluid/tests/book_memory_optimization/test_memopt_machine_translation.py +++ b/python/paddle/fluid/tests/book_memory_optimization/test_memopt_machine_translation.py @@ -124,8 +124,8 @@ def main(): feed=feeder.feed(data), fetch_list=[avg_cost]) avg_cost_val = np.array(outs[0]) - print(('pass_id=' + str(pass_id) + ' batch=' + str(batch_id) + - " avg_cost=" + str(avg_cost_val))) + print('pass_id=' + str(pass_id) + ' batch=' + str(batch_id) + + " avg_cost=" + str(avg_cost_val)) if batch_id > 2: exit(0) if math.isnan(float(avg_cost_val)): diff --git a/python/paddle/fluid/tests/demo/fc_gan.py b/python/paddle/fluid/tests/demo/fc_gan.py index 0bc5a47029..3d92f50f0a 100644 --- a/python/paddle/fluid/tests/demo/fc_gan.py +++ b/python/paddle/fluid/tests/demo/fc_gan.py @@ -158,8 +158,8 @@ def main(): dg_loss_np = exe.run(dg_program, feed={'noise': n}, fetch_list={dg_loss})[0] - print(("Pass ID={0}, Batch ID={1}, D-Loss={2}, DG-Loss={3}".format( - pass_id, batch_id, d_loss_np, dg_loss_np))) + print("Pass ID={0}, Batch ID={1}, D-Loss={2}, DG-Loss={3}".format( + pass_id, batch_id, d_loss_np, dg_loss_np)) # generate image each batch fig = plot(generated_img) plt.savefig( diff --git a/python/paddle/fluid/tests/test_detection.py b/python/paddle/fluid/tests/test_detection.py index 3e0dffc1e9..fd45abd0a7 100644 --- a/python/paddle/fluid/tests/test_detection.py +++ b/python/paddle/fluid/tests/test_detection.py @@ -46,7 +46,7 @@ class TestDetection(unittest.TestCase): scores=scores, loc=loc, prior_box=pb, prior_box_var=pbv) self.assertIsNotNone(out) self.assertEqual(out.shape[-1], 6) - print((str(program))) + print(str(program)) def test_detection_api(self): program = Program() @@ -81,7 +81,7 @@ class TestDetection(unittest.TestCase): self.assertIsNotNone(trg) self.assertIsNotNone(trg_weight) - print((str(program))) + print(str(program)) def test_ssd_loss(self): program = Program() @@ -105,7 +105,7 @@ class TestDetection(unittest.TestCase): loss = layers.ssd_loss(loc, scores, gt_box, gt_label, pb, pbv) self.assertIsNotNone(loss) self.assertEqual(loss.shape[-1], 1) - print((str(program))) + print(str(program)) class TestPriorBox(unittest.TestCase): @@ -196,7 +196,7 @@ class TestDetectionMAP(unittest.TestCase): map_out = layers.detection_map(detect_res, label, 21) self.assertIsNotNone(map_out) self.assertEqual(map_out.shape, (1, )) - print((str(program))) + print(str(program)) if __name__ == '__main__': diff --git a/python/paddle/fluid/tests/test_if_else_op.py b/python/paddle/fluid/tests/test_if_else_op.py index a3495cc6d4..082f64c146 100644 --- a/python/paddle/fluid/tests/test_if_else_op.py +++ b/python/paddle/fluid/tests/test_if_else_op.py @@ -84,7 +84,7 @@ class TestMNISTIfElseOp(unittest.TestCase): feed={'x': x_data, 'y': y_data}, fetch_list=[avg_loss]) - print((outs[0])) + print(outs[0]) if outs[0] < 1.0: return self.assertFalse(True) @@ -139,7 +139,7 @@ class TestMNISTIfElseOp(unittest.TestCase): feed={'x': x_data, 'y': y_data}, fetch_list=[avg_loss]) - print((outs[0])) + print(outs[0]) if outs[0] < 1.0: return self.assertFalse(True) diff --git a/python/paddle/fluid/tests/unittests/benchmark.py b/python/paddle/fluid/tests/unittests/benchmark.py index aeaa1751d7..9255996549 100644 --- a/python/paddle/fluid/tests/unittests/benchmark.py +++ b/python/paddle/fluid/tests/unittests/benchmark.py @@ -88,8 +88,8 @@ class BenchmarkSuite(OpTest): for place in places: elapses.append(self.timeit_output_with_place(place, iters)) for place, elapse in zip(places, elapses): - print(("One pass of ({2}_op) at {0} cost {1}".format( - str(place), elapse, self.op_type))) + print("One pass of ({2}_op) at {0} cost {1}".format( + str(place), elapse, self.op_type)) def timeit_grad_with_place(self, place, iters=100): inputs_to_check = self._get_input_names() @@ -108,5 +108,5 @@ class BenchmarkSuite(OpTest): for place in places: elapses.append(self.timeit_grad_with_place(place, iters)) for place, elapse in zip(places, elapses): - print(("One pass of ({2}_grad_op) at {0} cost {1}".format( - str(place), elapse, self.op_type))) + print("One pass of ({2}_grad_op) at {0} cost {1}".format( + str(place), elapse, self.op_type)) diff --git a/python/paddle/fluid/tests/unittests/parallel_executor_test_base.py b/python/paddle/fluid/tests/unittests/parallel_executor_test_base.py index 831331589b..67c35e9de7 100644 --- a/python/paddle/fluid/tests/unittests/parallel_executor_test_base.py +++ b/python/paddle/fluid/tests/unittests/parallel_executor_test_base.py @@ -99,8 +99,8 @@ class TestParallelExecutorBase(unittest.TestCase): end = time.time() if batch_size is not None: - print(("%.4f Instance per second" % ( - (batch_size * iter + 2) / (end - begin)))) + print("%.4f Instance per second" % ( + (batch_size * iter + 2) / (end - begin))) avg_last_loss_val = np.array(last_loss).mean() avg_first_loss_val = np.array(first_loss).mean() @@ -108,6 +108,6 @@ class TestParallelExecutorBase(unittest.TestCase): float(avg_first_loss_val)): sys.exit("got NaN loss, training failed.") - print((first_loss, last_loss)) + print(first_loss, last_loss) # self.assertGreater(first_loss[0], last_loss[0]) return first_loss, last_loss diff --git a/python/paddle/fluid/transpiler/memory_optimization_transpiler.py b/python/paddle/fluid/transpiler/memory_optimization_transpiler.py index 1c7bab8e1e..907acb1cac 100644 --- a/python/paddle/fluid/transpiler/memory_optimization_transpiler.py +++ b/python/paddle/fluid/transpiler/memory_optimization_transpiler.py @@ -246,11 +246,11 @@ class ControlFlowGraph(object): continue if PRINT_LOG: - print((("Hit Cache !!!! cache pool index " - "is %d, var name is %s, " - "cached var name is %s, " - "var shape is %s ") % (index, x, cache_var, - str(cache_shape)))) + print(("Hit Cache !!!! cache pool index " + "is %d, var name is %s, " + "cached var name is %s, " + "var shape is %s ") % (index, x, cache_var, + str(cache_shape))) self.pool.pop(index) if x == cache_var: break -- GitLab