diff --git a/PaddleCV/gan/cycle_gan/README.md b/PaddleCV/gan/cycle_gan/README.md index 0a9be53c783a557b7c2306f65377e4cafa8cfd90..5b7088fe7d0a0d44b5e5e08a453870b57bd5bafc 100644 --- a/PaddleCV/gan/cycle_gan/README.md +++ b/PaddleCV/gan/cycle_gan/README.md @@ -1,4 +1,3 @@ - 运行本目录下的程序示例需要使用PaddlePaddle develop最新版本。如果您的PaddlePaddle安装版本低于此要求,请按照[安装文档](http://www.paddlepaddle.org/docs/develop/documentation/zh/build_and_install/pip_install_cn.html)中的说明更新PaddlePaddle安装版本。 @@ -73,8 +72,8 @@ env CUDA_VISIBLE_DEVICES=0 python train.py 执行以下命令读取多张图片进行预测: ``` -env CUDA_VISIBLE_DEVICE=0 python infer.py \ - --init_model="checkpoints/1" --input="./data/inputA/*" \ +env CUDA_VISIBLE_DEVICES=0 python infer.py \ + --init_model="output/checkpoints/1" --input="./data/horse2zebra/trainA/*" \ --input_style A --output="./output" ``` @@ -89,3 +88,5 @@ env CUDA_VISIBLE_DEVICE=0 python infer.py \
图 3

+ +>在本文示例中,均可通过修改`CUDA_VISIBLE_DEVICES`改变使用的显卡号。 diff --git a/PaddleCV/gan/cycle_gan/infer.py b/PaddleCV/gan/cycle_gan/infer.py index 2282cf6c6aa6d41b1caba41a3cf42c08aea7ecef..666e6859b64482de12bcd0b13d15a76c63963e2f 100644 --- a/PaddleCV/gan/cycle_gan/infer.py +++ b/PaddleCV/gan/cycle_gan/infer.py @@ -44,7 +44,6 @@ def infer(args): if not os.path.exists(args.output): os.makedirs(args.output) for file in glob.glob(args.input): - print "read %s" % file image_name = os.path.basename(file) image = Image.open(file) image = image.resize((256, 256)) diff --git a/PaddleCV/gan/cycle_gan/train.py b/PaddleCV/gan/cycle_gan/train.py index 3f7bb03929958e56b22c5ae3288bd7e20c5b6058..561b1effc48477efb0454f63859e1664128e2a3a 100644 --- a/PaddleCV/gan/cycle_gan/train.py +++ b/PaddleCV/gan/cycle_gan/train.py @@ -22,7 +22,7 @@ add_arg = functools.partial(add_arguments, argparser=parser) # yapf: disable add_arg('batch_size', int, 1, "Minibatch size.") add_arg('epoch', int, 2, "The number of epoched to be trained.") -add_arg('output', str, "./output_0", "The directory the model and the test result to be saved to.") +add_arg('output', str, "./output", "The directory the model and the test result to be saved to.") add_arg('init_model', str, None, "The init model file of directory.") add_arg('save_checkpoints', bool, True, "Whether to save checkpoints.") add_arg('run_test', bool, True, "Whether to run test.") diff --git a/PaddleCV/ocr_recognition/README.md b/PaddleCV/ocr_recognition/README.md index 1c9553993e84d10376441407704088ec4dd66c0c..84c2fbba41a7f478d4e8d477402f6542fc0b185b 100644 --- a/PaddleCV/ocr_recognition/README.md +++ b/PaddleCV/ocr_recognition/README.md @@ -1,4 +1,3 @@ - 运行本目录下的程序示例需要使用PaddlePaddle develop最新版本。如果您的PaddlePaddle安装版本低于此要求,请按照[安装文档](http://www.paddlepaddle.org/docs/develop/documentation/zh/build_and_install/pip_install_cn.html)中的说明更新PaddlePaddle安装版本。 @@ -156,12 +155,13 @@ env CUDA_VISIBLE_DEVICES=0,1,2,3 python train.py --parallel=True 通过以下命令调用评估脚本用指定数据集对模型进行评估: ``` -env CUDA_VISIBLE_DEVICE=0 python eval.py \ +env CUDA_VISIBLE_DEVICES=0 python eval.py \ --model_path="./models/model_0" \ --input_images_dir="./eval_data/images/" \ - --input_images_list="./eval_data/eval_list\" \ + --input_images_list="./eval_data/eval_list" ``` + 执行`python train.py --help`可查看参数详细说明。 @@ -170,7 +170,7 @@ env CUDA_VISIBLE_DEVICE=0 python eval.py \ 从标准输入读取一张图片的路径,并对齐进行预测: ``` -env CUDA_VISIBLE_DEVICE=0 python infer.py \ +env CUDA_VISIBLE_DEVICES=0 python infer.py \ --model_path="models/model_00044_15000" ``` @@ -193,7 +193,7 @@ result: [2067 2067 8187 8477 5027 7191 2431 1462] 从文件中批量读取图片路径,并对其进行预测: ``` -env CUDA_VISIBLE_DEVICE=0 python infer.py \ +env CUDA_VISIBLE_DEVICES=0 python infer.py \ --model_path="models/model_00044_15000" \ --input_images_list="data/test.list" ``` @@ -204,3 +204,5 @@ env CUDA_VISIBLE_DEVICE=0 python infer.py \ |- |:-: | |[ocr_ctc_params](https://paddle-ocr-models.bj.bcebos.com/ocr_ctc.zip) | 22.3% | |[ocr_attention_params](https://paddle-ocr-models.bj.bcebos.com/ocr_attention.zip) | 15.8%| + +>在本文示例中,均可通过修改`CUDA_VISIBLE_DEVICES`改变当前任务使用的显卡号。 diff --git a/PaddleCV/ocr_recognition/attention_model.py b/PaddleCV/ocr_recognition/attention_model.py index d3d2185bb3685e4dd048e9bbf2990f90bf1c2254..79869e9df91c638c89da080a26badf8bdb100c1f 100755 --- a/PaddleCV/ocr_recognition/attention_model.py +++ b/PaddleCV/ocr_recognition/attention_model.py @@ -339,7 +339,7 @@ def attention_infer(images, num_classes, use_cudnn=True): return ids -def attention_eval(data_shape, num_classes): +def attention_eval(data_shape, num_classes, use_cudnn=True): images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') label_in = fluid.layers.data( name='label_in', shape=[1], dtype='int32', lod_level=1) @@ -349,7 +349,7 @@ def attention_eval(data_shape, num_classes): label_in = fluid.layers.cast(x=label_in, dtype='int64') gru_backward, encoded_vector, encoded_proj = encoder_net( - images, is_test=True) + images, is_test=True, use_cudnn=use_cudnn) backward_first = fluid.layers.sequence_pool( input=gru_backward, pool_type='first') diff --git a/PaddleCV/ocr_recognition/crnn_ctc_model.py b/PaddleCV/ocr_recognition/crnn_ctc_model.py index aa46d4ff086cee1697bafba76becf787ce619de8..51b016ac8321dca0c901d048e609502d4e974129 100755 --- a/PaddleCV/ocr_recognition/crnn_ctc_model.py +++ b/PaddleCV/ocr_recognition/crnn_ctc_model.py @@ -213,12 +213,12 @@ def ctc_train_net(args, data_shape, num_classes): return sum_cost, error_evaluator, inference_program, model_average -def ctc_infer(images, num_classes, use_cudnn): +def ctc_infer(images, num_classes, use_cudnn=True): fc_out = encoder_net(images, num_classes, is_test=True, use_cudnn=use_cudnn) return fluid.layers.ctc_greedy_decoder(input=fc_out, blank=num_classes) -def ctc_eval(data_shape, num_classes, use_cudnn): +def ctc_eval(data_shape, num_classes, use_cudnn=True): images = fluid.layers.data(name='pixel', shape=data_shape, dtype='float32') label = fluid.layers.data( name='label', shape=[1], dtype='int32', lod_level=1) diff --git a/PaddleCV/ocr_recognition/data_reader.py b/PaddleCV/ocr_recognition/data_reader.py index 1a1c5c87162efd998e73bc19ec2cb511fdabcb79..16486f990903ba91c7bc073c44605653fd33c431 100644 --- a/PaddleCV/ocr_recognition/data_reader.py +++ b/PaddleCV/ocr_recognition/data_reader.py @@ -10,6 +10,11 @@ from os import path from paddle.dataset.image import load_image import paddle +try: + input = raw_input +except NameError: + pass + SOS = 0 EOS = 1 NUM_CLASSES = 95 @@ -175,7 +180,7 @@ class DataGenerator(object): yield img, label else: while True: - img_path = raw_input("Please input the path of image: ") + img_path = input("Please input the path of image: ") img = Image.open(img_path).convert('L') img = np.array(img) - 127.5 img = img[np.newaxis, ...] diff --git a/PaddleCV/ocr_recognition/eval.py b/PaddleCV/ocr_recognition/eval.py index a19ca4a34f9b89809dce3d87cf10d5348850f4e2..bc8be4fcf4767183629c2a9c3dc7ea49af5b20b1 100644 --- a/PaddleCV/ocr_recognition/eval.py +++ b/PaddleCV/ocr_recognition/eval.py @@ -31,7 +31,8 @@ def evaluate(args): num_classes = data_reader.num_classes() data_shape = data_reader.data_shape() # define network - evaluator, cost = eval(data_shape, num_classes) + evaluator, cost = eval( + data_shape, num_classes, use_cudnn=True if args.use_gpu else False) # data reader test_reader = data_reader.test( @@ -62,8 +63,8 @@ def evaluate(args): count += 1 exe.run(fluid.default_main_program(), feed=get_feeder_data(data, place)) avg_distance, avg_seq_error = evaluator.eval(exe) - print("Read %d samples; avg_distance: %s; avg_seq_error: %s" % ( - count, avg_distance, avg_seq_error)) + print("Read %d samples; avg_distance: %s; avg_seq_error: %s" % + (count, avg_distance, avg_seq_error)) def main(): diff --git a/PaddleSlim/configs/filter_pruning_sen.yaml b/PaddleSlim/configs/filter_pruning_sen.yaml index 4537405fe200fad631095d0bd81d3de2fcb267bc..f83079f5ff704f0e8605bb41e010e935a4180a44 100644 --- a/PaddleSlim/configs/filter_pruning_sen.yaml +++ b/PaddleSlim/configs/filter_pruning_sen.yaml @@ -20,6 +20,7 @@ strategies: metric_name: 'acc_top1' compressor: epoch: 200 + #init_model: './checkpoints/0' # Please enable this option for loading checkpoint. checkpoint_path: './checkpoints/' strategies: - sensitive_pruning_strategy diff --git a/PaddleSlim/configs/filter_pruning_uniform.yaml b/PaddleSlim/configs/filter_pruning_uniform.yaml index 1dea1070f4456e7150ed1a2706cde072180bf9ff..798e7f1bea875d626e84fd802df885ed95194de6 100644 --- a/PaddleSlim/configs/filter_pruning_uniform.yaml +++ b/PaddleSlim/configs/filter_pruning_uniform.yaml @@ -16,6 +16,7 @@ strategies: metric_name: 'acc_top1' compressor: epoch: 200 + #init_model: './checkpoints/0' # Please enable this option for loading checkpoint. checkpoint_path: './checkpoints/' strategies: - uniform_pruning_strategy diff --git a/PaddleSlim/configs/quantization_pruning.yaml b/PaddleSlim/configs/quantization_pruning.yaml index b4dcd4794dc244c00c144d2fd02bbd7c859c461e..0499051037215c8341ef18fdffb8605b912ee8c4 100644 --- a/PaddleSlim/configs/quantization_pruning.yaml +++ b/PaddleSlim/configs/quantization_pruning.yaml @@ -30,6 +30,7 @@ strategies: activation_quantize_type: 'abs_max' compressor: epoch: 142 + #init_model: './checkpoints/0' # Please enable this option for loading checkpoint. checkpoint_path: './checkpoints/' strategies: - uniform_pruning_strategy diff --git a/PaddleSlim/run.sh b/PaddleSlim/run.sh index eaed30b84cc70805db1738f949bae674f207f17d..0d370e98de4a538f21d1c5d8be43d43cb000252f 100644 --- a/PaddleSlim/run.sh +++ b/PaddleSlim/run.sh @@ -24,6 +24,10 @@ fi cd - +# enable GC strategy +export FLAGS_fast_eager_deletion_mode=1 +export FLAGS_eager_delete_tensor_gb=0.0 + # for distillation #----------------- export CUDA_VISIBLE_DEVICES=0,1,2,3