diff --git a/PaddleCV/image_classification/eval.py b/PaddleCV/image_classification/eval.py index b53b1f38c892d8cda5fe985646ba9a4f282e632b..ebc6dd7757a69f12d38e30b27a9725cadbccd318 100644 --- a/PaddleCV/image_classification/eval.py +++ b/PaddleCV/image_classification/eval.py @@ -26,7 +26,7 @@ import functools import paddle import paddle.fluid as fluid -import reader_cv2 as reader +import reader_cv2 as reader import models from utils.learning_rate import cosine_decay from utils.utility import add_arguments, print_arguments, check_gpu @@ -44,6 +44,7 @@ add_arg('model', str, "SE_ResNeXt50_32x4d", "Set the network to use. add_arg('resize_short_size', int, 256, "Set resize short size") # yapf: enable + def eval(args): # parameters from arguments class_dim = args.class_dim @@ -93,10 +94,9 @@ def eval(args): exe = fluid.Executor(place) exe.run(fluid.default_startup_program()) - fluid.io.load_persistables(exe, pretrained_model) - val_reader = paddle.batch(reader.val(settings=args), batch_size=args.batch_size) + val_reader = reader.val(settings=args, batch_size=args.batch_size) feeder = fluid.DataFeeder(place=place, feed_list=[image, label]) test_info = [[], [], []] @@ -127,7 +127,7 @@ def eval(args): test_acc5 = np.sum(test_info[2]) / cnt print("Test_loss {0}, test_acc1 {1}, test_acc5 {2}".format( - "%.5f"%test_loss, "%.5f"%test_acc1, "%.5f"%test_acc5)) + "%.5f" % test_loss, "%.5f" % test_acc1, "%.5f" % test_acc5)) sys.stdout.flush() diff --git a/PaddleCV/image_classification/infer.py b/PaddleCV/image_classification/infer.py index 142ed013a8a3237c34b5dcb230fa2b59340ee571..ce5174473c9190092bb246ae0ef8b8f806bb902f 100644 --- a/PaddleCV/image_classification/infer.py +++ b/PaddleCV/image_classification/infer.py @@ -29,7 +29,7 @@ import paddle.fluid as fluid import reader_cv2 as reader import models import utils -from utils.utility import add_arguments,print_arguments, check_gpu +from utils.utility import add_arguments, print_arguments, check_gpu parser = argparse.ArgumentParser(description=__doc__) # yapf: disable @@ -44,6 +44,7 @@ add_arg('save_inference', bool, False, "Whether to save infere add_arg('resize_short_size', int, 256, "Set resize short size") # yapf: enable + def infer(args): # parameters from arguments class_dim = args.class_dim @@ -80,17 +81,18 @@ def infer(args): fluid.io.load_persistables(exe, pretrained_model) if save_inference: fluid.io.save_inference_model( - dirname=model_name, - feeded_var_names=['image'], - main_program=test_program, - target_vars=out, - executor=exe, - model_filename='model', - params_filename='params') - print("model: ",model_name," is already saved") + dirname=model_name, + feeded_var_names=['image'], + main_program=test_program, + target_vars=out, + executor=exe, + model_filename='model', + params_filename='params') + print("model: ", model_name, " is already saved") exit(0) test_batch_size = 1 - test_reader = paddle.batch(reader.test(settings=args), batch_size=test_batch_size) + + test_reader = reader.test(settings=args, batch_size=test_batch_size) feeder = fluid.DataFeeder(place=place, feed_list=[image]) TOPK = 1 diff --git a/PaddleCV/image_classification/reader_cv2.py b/PaddleCV/image_classification/reader_cv2.py index 3ef022bfa6c2f67a3862c34e0613e4d11e476ea0..1cb3baff18cfbe0bfd3965e0e1e6e97779073cb5 100644 --- a/PaddleCV/image_classification/reader_cv2.py +++ b/PaddleCV/image_classification/reader_cv2.py @@ -243,10 +243,9 @@ def _reader_creator(settings, img_path = os.path.join(data_dir, img_path) batch_data.append([img_path, int(label)]) if len(batch_data) == batch_size: - if mode == 'train' or mode == 'val': + if mode == 'train' or mode == 'val' or mode == 'test': yield batch_data - elif mode == 'test': - yield [sample[0] for sample in batch_data] + batch_data = [] return read_file_list