提交 ea03d59e 编写于 作者: Q qingqing01

test in jupyter notebook

上级 92d9d2d2
......@@ -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]
```
......
......@@ -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]
```
......
......@@ -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]
```
......
......@@ -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]
```
......
......@@ -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__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册