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 f252a7e2b98b05d0c64533e9e24a902559be2f39..2aac70463c64019ec97b0c3893b4b52f77967797 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 @@ -71,24 +71,18 @@ def train(use_cuda, train_program, save_dirname): if isinstance(event, fluid.EndEpochEvent): test_reader = paddle.batch( paddle.dataset.mnist.test(), batch_size=BATCH_SIZE) - test_metrics = trainer.test( + avg_cost, acc = trainer.test( reader=test_reader, feed_order=['img', 'label']) - avg_cost_set = test_metrics[0] - acc_set = test_metrics[1] - - # get test acc and loss - acc = numpy.array(acc_set).mean() - avg_cost = numpy.array(avg_cost_set).mean() print("avg_cost: %s" % avg_cost) print("acc : %s" % acc) - if float(acc) > 0.2: # Smaller value to increase CI speed + if acc > 0.2: # Smaller value to increase CI speed trainer.save_params(save_dirname) else: print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.epoch + 1, float(avg_cost), float(acc))) - if math.isnan(float(avg_cost)): + 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( 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 9427a772f54fb58ca1f50ed792cccf5d8f9b3d84..32653157994f81c46f420c1b55ceddbbbf06f2fe 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 @@ -55,24 +55,18 @@ def train(use_cuda, train_program, save_dirname): if isinstance(event, fluid.EndEpochEvent): test_reader = paddle.batch( paddle.dataset.mnist.test(), batch_size=BATCH_SIZE) - test_metrics = trainer.test( + avg_cost, acc = trainer.test( reader=test_reader, feed_order=['img', 'label']) - avg_cost_set = test_metrics[0] - acc_set = test_metrics[1] - - # get test acc and loss - acc = numpy.array(acc_set).mean() - avg_cost = numpy.array(avg_cost_set).mean() print("avg_cost: %s" % avg_cost) print("acc : %s" % acc) - if float(acc) > 0.2: # Smaller value to increase CI speed + if acc > 0.2: # Smaller value to increase CI speed trainer.save_params(save_dirname) else: print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.epoch + 1, float(avg_cost), float(acc))) - if math.isnan(float(avg_cost)): + event.epoch + 1, avg_cost, acc)) + if math.isnan(avg_cost): sys.exit("got NaN loss, training failed.") train_reader = paddle.batch(