提交 788dc32a 编写于 作者: P Peng Li

change parameters.to_tar(f) in *.md to trainer.save_parameter_to_tar(f)

上级 c7ed5286
......@@ -214,7 +214,7 @@ def event_handler_plot(event):
if isinstance(event, paddle.event.EndPass):
if event.pass_id % 10 == 0:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
```
### 开始训练
......
......@@ -220,7 +220,7 @@ def event_handler_plot(event):
if isinstance(event, paddle.event.EndPass):
if event.pass_id % 10 == 0:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
```
### Start Training
......
......@@ -256,7 +256,7 @@ def event_handler_plot(event):
if isinstance(event, paddle.event.EndPass):
if event.pass_id % 10 == 0:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
```
### 开始训练
......
......@@ -262,7 +262,7 @@ def event_handler_plot(event):
if isinstance(event, paddle.event.EndPass):
if event.pass_id % 10 == 0:
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
```
### Start Training
......
......@@ -256,7 +256,7 @@ def event_handler_plot(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=paddle.batch(
paddle.dataset.mnist.test(), batch_size=128))
......@@ -275,7 +275,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=paddle.batch(
paddle.dataset.mnist.test(), batch_size=128))
......
......@@ -249,7 +249,7 @@ def event_handler_plot(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=paddle.batch(
paddle.dataset.mnist.test(), batch_size=128))
......@@ -270,7 +270,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=paddle.batch(
paddle.dataset.mnist.test(), batch_size=128))
......
......@@ -298,7 +298,7 @@ def event_handler_plot(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=paddle.batch(
paddle.dataset.mnist.test(), batch_size=128))
......@@ -317,7 +317,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=paddle.batch(
paddle.dataset.mnist.test(), batch_size=128))
......
......@@ -291,7 +291,7 @@ def event_handler_plot(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=paddle.batch(
paddle.dataset.mnist.test(), batch_size=128))
......@@ -312,7 +312,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=paddle.batch(
paddle.dataset.mnist.test(), batch_size=128))
......
......@@ -432,7 +432,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(
reader=paddle.batch(
......
......@@ -438,7 +438,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(
reader=paddle.batch(
......
......@@ -474,7 +474,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(
reader=paddle.batch(
......
......@@ -480,7 +480,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(
reader=paddle.batch(
......
......@@ -336,7 +336,7 @@ def event_handler(event):
paddle.dataset.imikolov.test(word_dict, N), 32))
print "Pass %d, Testing metrics %s" % (event.pass_id, result.metrics)
with open("model_%d.tar"%event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
trainer.train(
paddle.batch(paddle.dataset.imikolov.train(word_dict, N), 32),
......
......@@ -348,7 +348,7 @@ def event_handler(event):
paddle.dataset.imikolov.test(word_dict, N), 32))
print "Pass %d, Testing metrics %s" % (event.pass_id, result.metrics)
with open("model_%d.tar"%event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
trainer.train(
paddle.batch(paddle.dataset.imikolov.train(word_dict, N), 32),
......
......@@ -378,7 +378,7 @@ def event_handler(event):
paddle.dataset.imikolov.test(word_dict, N), 32))
print "Pass %d, Testing metrics %s" % (event.pass_id, result.metrics)
with open("model_%d.tar"%event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
trainer.train(
paddle.batch(paddle.dataset.imikolov.train(word_dict, N), 32),
......
......@@ -390,7 +390,7 @@ def event_handler(event):
paddle.dataset.imikolov.test(word_dict, N), 32))
print "Pass %d, Testing metrics %s" % (event.pass_id, result.metrics)
with open("model_%d.tar"%event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
trainer.train(
paddle.batch(paddle.dataset.imikolov.train(word_dict, N), 32),
......
......@@ -291,7 +291,7 @@ Paddle中提供了一系列优化算法的API,这里使用Adam优化算法。
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
with open('./params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=test_reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
......
......@@ -310,7 +310,7 @@ def event_handler(event):
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
with open('./params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=test_reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
......
......@@ -333,7 +333,7 @@ Paddle中提供了一系列优化算法的API,这里使用Adam优化算法。
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
with open('./params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=test_reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
......
......@@ -352,7 +352,7 @@ def event_handler(event):
sys.stdout.flush()
if isinstance(event, paddle.event.EndPass):
with open('./params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=test_reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
......
......@@ -448,7 +448,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
......
......@@ -466,7 +466,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
......
......@@ -490,7 +490,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
......
......@@ -508,7 +508,7 @@ def event_handler(event):
if isinstance(event, paddle.event.EndPass):
# save parameters
with open('params_pass_%d.tar' % event.pass_id, 'w') as f:
parameters.to_tar(f)
trainer.save_parameter_to_tar(f)
result = trainer.test(reader=reader, feeding=feeding)
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
......
......@@ -61,12 +61,12 @@ PaddlePaddle stores the topology and parameter separately.
inference_topology.serialize_for_inference(f)
```
2. To save a parameter, we need to invoke `to_tar` method in Parameter
class.
2. To save a parameter, we need to invoke `save_parameter_to_tar` method of
`trainer`.
```python
with open('param.tar', 'w') as f:
params.to_tar(f)
trainer.save_parameter_to_tar(f)
```
After serializing the parameter and topology into two files, we could
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册