diff --git a/fluid/image_classification/caffe2fluid/convert.py b/fluid/image_classification/caffe2fluid/convert.py index 44420c837b0bc4401f7e0f54e3a184af57e53d9a..379f1a26368c9ffa4a9f82dad499ad7114f942fc 100755 --- a/fluid/image_classification/caffe2fluid/convert.py +++ b/fluid/image_classification/caffe2fluid/convert.py @@ -49,6 +49,7 @@ def convert(def_path, caffemodel_path, data_output_path, code_output_path, return 0 + def main(): """ main """ @@ -65,8 +66,8 @@ def main(): help='The phase to convert: test (default) or train') args = parser.parse_args() validate_arguments(args) - convert(args.def_path, args.caffemodel, args.data_output_path, - args.code_output_path, args.phase) + return convert(args.def_path, args.caffemodel, args.data_output_path, + args.code_output_path, args.phase) if __name__ == '__main__': diff --git a/fluid/image_classification/caffe2fluid/examples/imagenet/infer.py b/fluid/image_classification/caffe2fluid/examples/imagenet/infer.py index 5465e3da8475feb46102551fe1ca40f28cd13b7e..ec594199be5a3e7a33c9673b1d5497c95f20d946 100644 --- a/fluid/image_classification/caffe2fluid/examples/imagenet/infer.py +++ b/fluid/image_classification/caffe2fluid/examples/imagenet/infer.py @@ -13,6 +13,7 @@ import numpy as np import paddle.v2 as paddle import paddle.v2.fluid as fluid + def load_data(imgfile, shape): h, w = shape[1:] from PIL import Image @@ -35,7 +36,8 @@ def load_data(imgfile, shape): def build_model(net_file, net_name): - print('build model with net_file[%s] and net_name[%s]' % (net_file, net_name)) + print('build model with net_file[%s] and net_name[%s]' % + (net_file, net_name)) net_path = os.path.dirname(net_file) module_name = os.path.basename(net_file).rstrip('.py') @@ -102,9 +104,9 @@ def infer(net_file, net_name, model_file, imgfile, debug=False): fetch_list_name.append(k) np_images = load_data(imgfile, input_shape) - results = exe.run(program=test_program, - feed={'image': np_images}, - fetch_list=fetch_list_var) + results = exe.run(program=test_program, + feed={'image': np_images}, + fetch_list=fetch_list_var) if debug is True: dump_path = 'results.layers' @@ -126,14 +128,15 @@ if __name__ == "__main__": argc = len(sys.argv) if argc == 5: net_file = sys.argv[1] - weight_file = sys.argv[2] + weight_file = sys.argv[2] imgfile = sys.argv[3] - net_name= sys.argv[4] + net_name = sys.argv[4] elif argc > 1: print('usage:') - print('\tpython %s [net_file] [weight_file] [imgfile] [net_name]' % (sys.argv[0])) - print('\teg:python %s %s %s %s %s' % (sys.argv[0], - net_file, weight_file, imgfile, net_name)) + print('\tpython %s [net_file] [weight_file] [imgfile] [net_name]' % + (sys.argv[0])) + print('\teg:python %s %s %s %s %s' % (sys.argv[0], net_file, + weight_file, imgfile, net_name)) sys.exit(1) infer(net_file, net_name, weight_file, imgfile) diff --git a/fluid/image_classification/caffe2fluid/examples/mnist/evaluate.py b/fluid/image_classification/caffe2fluid/examples/mnist/evaluate.py index 81b67342832d4b6569f769d0dd9f40ddc2ea3699..5c86635d5a014262bdec40fe063915350c5fadb3 100644 --- a/fluid/image_classification/caffe2fluid/examples/mnist/evaluate.py +++ b/fluid/image_classification/caffe2fluid/examples/mnist/evaluate.py @@ -10,6 +10,7 @@ import numpy as np import paddle.v2 as paddle import paddle.v2.fluid as fluid + def test_model(exe, test_program, fetch_list, test_reader, feeder): acc_set = [] @@ -75,12 +76,11 @@ if __name__ == "__main__": argc = len(sys.argv) if argc == 3: net_file = sys.argv[1] - weight_file = sys.argv[2] + weight_file = sys.argv[2] elif argc > 1: print('usage:') print('\tpython %s [net_file] [weight_file]' % (sys.argv[0])) - print('\teg:python %s %s %s %s' % (sys.argv[0], - net_file, weight_file)) + print('\teg:python %s %s %s %s' % (sys.argv[0], net_file, weight_file)) sys.exit(1) evaluate(net_file, weight_file)