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 420e6e6e42adc..3ad7befbe3261 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 @@ -68,24 +68,18 @@ def event_handler(event): 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( 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 9427a772f54fb..32653157994f8 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 event_handler(event): 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(