From ea03d59e9ea496a73ff041ae887e4c38711ced36 Mon Sep 17 00:00:00 2001 From: qingqing01 Date: Wed, 5 Apr 2017 20:05:57 +0800 Subject: [PATCH] test in jupyter notebook --- 03.image_classification/README.en.md | 11 ++++++----- 03.image_classification/README.md | 10 ++++++---- 03.image_classification/index.en.html | 11 ++++++----- 03.image_classification/index.html | 10 ++++++---- 03.image_classification/train.py | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/03.image_classification/README.en.md b/03.image_classification/README.en.md index 6291f61..d5e8b65 100644 --- a/03.image_classification/README.en.md +++ b/03.image_classification/README.en.md @@ -169,6 +169,7 @@ We must import and initialize PaddlePaddle (enable/disable GPU, set the number o ```python import sys +import gzip import paddle.v2 as paddle from vgg import vgg_bn_drop from resnet import resnet_cifar10 @@ -417,10 +418,6 @@ def event_handler_plot(event): cost_ploter.plot() step += 1 if isinstance(event, paddle.event.EndPass): - # save parameters - with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f: - parameters.to_tar(f) - result = trainer.test( reader=paddle.batch( paddle.dataset.cifar.test10(), batch_size=128), @@ -441,6 +438,10 @@ def event_handler(event): sys.stdout.write('.') sys.stdout.flush() if isinstance(event, paddle.event.EndPass): + # save parameters + with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f: + parameters.to_tar(f) + result = trainer.test( reader=paddle.batch( paddle.dataset.cifar.test10(), batch_size=128), @@ -499,7 +500,7 @@ test_data.append((load_image('image/dog.png'),)) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) lab = np.argsort(-probs) # probs and lab are the results of one batch data -print("Label of image/dog.png is: %d", lab[0][0]) +print "Label of image/dog.png is: %d" % lab[0][0] ``` diff --git a/03.image_classification/README.md b/03.image_classification/README.md index a35e471..8f3a8d2 100644 --- a/03.image_classification/README.md +++ b/03.image_classification/README.md @@ -156,6 +156,7 @@ Paddle API提供了自动加载cifar数据集模块 `paddle.dataset.cifar`。 ```python import sys +import gzip import paddle.v2 as paddle from vgg import vgg_bn_drop from resnet import resnet_cifar10 @@ -409,9 +410,6 @@ def event_handler_plot(event): cost_ploter.plot() step += 1 if isinstance(event, paddle.event.EndPass): - # save parameters - with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f: - parameters.to_tar(f) result = trainer.test( reader=paddle.batch( @@ -433,6 +431,10 @@ def event_handler(event): sys.stdout.write('.') sys.stdout.flush() if isinstance(event, paddle.event.EndPass): + # save parameters + with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f: + parameters.to_tar(f) + result = trainer.test( reader=paddle.batch( paddle.dataset.cifar.test10(), batch_size=128), @@ -490,7 +492,7 @@ test_data.append((load_image('image/dog.png'),)) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) lab = np.argsort(-probs) # probs and lab are the results of one batch data -print("Label of image/dog.png is: %d", lab[0][0]) +print "Label of image/dog.png is: %d" % lab[0][0] ``` diff --git a/03.image_classification/index.en.html b/03.image_classification/index.en.html index 226f8af..37f1dc5 100644 --- a/03.image_classification/index.en.html +++ b/03.image_classification/index.en.html @@ -211,6 +211,7 @@ We must import and initialize PaddlePaddle (enable/disable GPU, set the number o ```python import sys +import gzip import paddle.v2 as paddle from vgg import vgg_bn_drop from resnet import resnet_cifar10 @@ -459,10 +460,6 @@ def event_handler_plot(event): cost_ploter.plot() step += 1 if isinstance(event, paddle.event.EndPass): - # save parameters - with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f: - parameters.to_tar(f) - result = trainer.test( reader=paddle.batch( paddle.dataset.cifar.test10(), batch_size=128), @@ -483,6 +480,10 @@ def event_handler(event): sys.stdout.write('.') sys.stdout.flush() if isinstance(event, paddle.event.EndPass): + # save parameters + with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f: + parameters.to_tar(f) + result = trainer.test( reader=paddle.batch( paddle.dataset.cifar.test10(), batch_size=128), @@ -541,7 +542,7 @@ test_data.append((load_image('image/dog.png'),)) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) lab = np.argsort(-probs) # probs and lab are the results of one batch data -print("Label of image/dog.png is: %d", lab[0][0]) +print "Label of image/dog.png is: %d" % lab[0][0] ``` diff --git a/03.image_classification/index.html b/03.image_classification/index.html index b14f88e..4001d12 100644 --- a/03.image_classification/index.html +++ b/03.image_classification/index.html @@ -198,6 +198,7 @@ Paddle API提供了自动加载cifar数据集模块 `paddle.dataset.cifar`。 ```python import sys +import gzip import paddle.v2 as paddle from vgg import vgg_bn_drop from resnet import resnet_cifar10 @@ -451,9 +452,6 @@ def event_handler_plot(event): cost_ploter.plot() step += 1 if isinstance(event, paddle.event.EndPass): - # save parameters - with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f: - parameters.to_tar(f) result = trainer.test( reader=paddle.batch( @@ -475,6 +473,10 @@ def event_handler(event): sys.stdout.write('.') sys.stdout.flush() if isinstance(event, paddle.event.EndPass): + # save parameters + with gzip.open('params_pass_%d.tar.gz' % event.pass_id, 'w') as f: + parameters.to_tar(f) + result = trainer.test( reader=paddle.batch( paddle.dataset.cifar.test10(), batch_size=128), @@ -532,7 +534,7 @@ test_data.append((load_image('image/dog.png'),)) probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) lab = np.argsort(-probs) # probs and lab are the results of one batch data -print("Label of image/dog.png is: %d", lab[0][0]) +print "Label of image/dog.png is: %d" % lab[0][0] ``` diff --git a/03.image_classification/train.py b/03.image_classification/train.py index 4b3ab18..e60b9bd 100644 --- a/03.image_classification/train.py +++ b/03.image_classification/train.py @@ -108,7 +108,7 @@ def main(): probs = paddle.infer( output_layer=out, parameters=parameters, input=test_data) lab = np.argsort(-probs) # probs and lab are the results of one batch data - print("Label of image/dog.png is: %d", lab[0][0]) + print "Label of image/dog.png is: %d" % lab[0][0] if __name__ == '__main__': -- GitLab