diff --git a/03.image_classification/README.en.md b/03.image_classification/README.en.md index 6291f61295c3f14b26db26668b996e744a661622..d5e8b650199cc32bec817a884baed222d17115e3 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 a35e4712b95d526d50b21a2576f2c28589e50fce..8f3a8d256173839adeec06125527a6b696b79974 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 226f8af28a308779d2b1a7849f6aaf29a91ae79a..37f1dc5f2392a931f0e5161926abe262f3fad7ee 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 b14f88ea368652d46fc3fc66ff06cbb18b92f879..4001d122d275657a201f47e70fb4923688e523e9 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 4b3ab18abba22c03e9b3deff1749a2f5972c6947..e60b9bda3c7ec1eefb2cfb9798f72aa8fd5e2b93 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__':