提交 6ba1445a 编写于 作者: M minqiyang

Remove plot in 1.0 book

上级 3d5b8e61
...@@ -183,27 +183,22 @@ feed_order=['x', 'y'] ...@@ -183,27 +183,22 @@ feed_order=['x', 'y']
# Specify the directory to save the parameters # Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model" params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.utils import Ploter
train_title = "Train cost" train_title = "Train cost"
test_title = "Test cost" test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0 step = 0
# event_handler prints training and testing info # event_handler prints training and testing info
def event_handler_plot(event): def event_handler(event):
global step global step
if isinstance(event, fluid.contrib.trainer.EndStepEvent): if isinstance(event, fluid.contrib.trainer.EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches if step % 10 == 0: # record a train cost every 10 batches
plot_cost.append(train_title, step, event.metrics[0]) print("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0]))
if step % 100 == 0: # record a test cost every 100 batches if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test( test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order) reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0]) print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
plot_cost.plot()
if test_metrics[0] < 10.0: if test_metrics[0] < 10.0:
# If the accuracy is good enough, we can stop the training. # If the accuracy is good enough, we can stop the training.
...@@ -228,7 +223,7 @@ def event_handler_plot(event): ...@@ -228,7 +223,7 @@ def event_handler_plot(event):
trainer.train( trainer.train(
reader=train_reader, reader=train_reader,
num_epochs=100, num_epochs=100,
event_handler=event_handler_plot, event_handler=event_handler,
feed_order=feed_order) feed_order=feed_order)
``` ```
<div align="center"> <div align="center">
......
...@@ -202,27 +202,22 @@ Moreover, an event handler is provided to print the training progress: ...@@ -202,27 +202,22 @@ Moreover, an event handler is provided to print the training progress:
# Specify the directory to save the parameters # Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model" params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.utils import Ploter
train_title = "Train cost" train_title = "Train cost"
test_title = "Test cost" test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0 step = 0
# event_handler prints training and testing info # event_handler prints training and testing info
def event_handler_plot(event): def event_handler(event):
global step global step
if isinstance(event, fluid.contrib.trainer.EndStepEvent): if isinstance(event, fluid.contrib.trainer.EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches if step % 10 == 0: # record a train cost every 10 batches
plot_cost.append(train_title, step, event.metrics[0]) print("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0]))
if step % 100 == 0: # record a test cost every 100 batches if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test( test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order) reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0]) print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
plot_cost.plot()
if test_metrics[0] < 10.0: if test_metrics[0] < 10.0:
# If the accuracy is good enough, we can stop the training. # If the accuracy is good enough, we can stop the training.
...@@ -230,7 +225,7 @@ def event_handler_plot(event): ...@@ -230,7 +225,7 @@ def event_handler_plot(event):
trainer.stop() trainer.stop()
step += 1 step += 1
if isinstance(event, fluid.contrib.trainer.EndEpochEvent): if isinstance(event, EndEpochEvent):
if event.epoch % 10 == 0: if event.epoch % 10 == 0:
# We can save the trained parameters for the inferences later # We can save the trained parameters for the inferences later
if params_dirname is not None: if params_dirname is not None:
...@@ -249,7 +244,7 @@ We now can start training by calling `trainer.train()`. ...@@ -249,7 +244,7 @@ We now can start training by calling `trainer.train()`.
trainer.train( trainer.train(
reader=train_reader, reader=train_reader,
num_epochs=100, num_epochs=100,
event_handler=event_handler_plot, event_handler=event_handler,
feed_order=feed_order) feed_order=feed_order)
``` ```
......
...@@ -225,27 +225,22 @@ feed_order=['x', 'y'] ...@@ -225,27 +225,22 @@ feed_order=['x', 'y']
# Specify the directory to save the parameters # Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model" params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.utils import Ploter
train_title = "Train cost" train_title = "Train cost"
test_title = "Test cost" test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0 step = 0
# event_handler prints training and testing info # event_handler prints training and testing info
def event_handler_plot(event): def event_handler(event):
global step global step
if isinstance(event, fluid.contrib.trainer.EndStepEvent): if isinstance(event, fluid.contrib.trainer.EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches if step % 10 == 0: # record a train cost every 10 batches
plot_cost.append(train_title, step, event.metrics[0]) print("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0]))
if step % 100 == 0: # record a test cost every 100 batches if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test( test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order) reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0]) print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
plot_cost.plot()
if test_metrics[0] < 10.0: if test_metrics[0] < 10.0:
# If the accuracy is good enough, we can stop the training. # If the accuracy is good enough, we can stop the training.
...@@ -270,7 +265,7 @@ def event_handler_plot(event): ...@@ -270,7 +265,7 @@ def event_handler_plot(event):
trainer.train( trainer.train(
reader=train_reader, reader=train_reader,
num_epochs=100, num_epochs=100,
event_handler=event_handler_plot, event_handler=event_handler,
feed_order=feed_order) feed_order=feed_order)
``` ```
<div align="center"> <div align="center">
......
...@@ -244,27 +244,22 @@ Moreover, an event handler is provided to print the training progress: ...@@ -244,27 +244,22 @@ Moreover, an event handler is provided to print the training progress:
# Specify the directory to save the parameters # Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model" params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.utils import Ploter
train_title = "Train cost" train_title = "Train cost"
test_title = "Test cost" test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0 step = 0
# event_handler prints training and testing info # event_handler prints training and testing info
def event_handler_plot(event): def event_handler(event):
global step global step
if isinstance(event, fluid.contrib.trainer.EndStepEvent): if isinstance(event, fluid.contrib.trainer.EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches if step % 10 == 0: # record a train cost every 10 batches
plot_cost.append(train_title, step, event.metrics[0]) print("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0]))
if step % 100 == 0: # record a test cost every 100 batches if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test( test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order) reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0]) print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
plot_cost.plot()
if test_metrics[0] < 10.0: if test_metrics[0] < 10.0:
# If the accuracy is good enough, we can stop the training. # If the accuracy is good enough, we can stop the training.
...@@ -272,7 +267,7 @@ def event_handler_plot(event): ...@@ -272,7 +267,7 @@ def event_handler_plot(event):
trainer.stop() trainer.stop()
step += 1 step += 1
if isinstance(event, fluid.contrib.trainer.EndEpochEvent): if isinstance(event, EndEpochEvent):
if event.epoch % 10 == 0: if event.epoch % 10 == 0:
# We can save the trained parameters for the inferences later # We can save the trained parameters for the inferences later
if params_dirname is not None: if params_dirname is not None:
...@@ -291,7 +286,7 @@ We now can start training by calling `trainer.train()`. ...@@ -291,7 +286,7 @@ We now can start training by calling `trainer.train()`.
trainer.train( trainer.train(
reader=train_reader, reader=train_reader,
num_epochs=100, num_epochs=100,
event_handler=event_handler_plot, event_handler=event_handler,
feed_order=feed_order) feed_order=feed_order)
``` ```
......
...@@ -69,28 +69,24 @@ feed_order = ['x', 'y'] ...@@ -69,28 +69,24 @@ feed_order = ['x', 'y']
# Specify the directory to save the parameters # Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model" params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.utils import Ploter
train_title = "Train cost" train_title = "Train cost"
test_title = "Test cost" test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0 step = 0
# event_handler prints training and testing info # event_handler prints training and testing info
def event_handler_plot(event): def event_handler(event):
global step global step
if isinstance(event, EndStepEvent): if isinstance(event, EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches if step % 10 == 0: # record a train cost every 10 batches
plot_cost.append(train_title, step, event.metrics[0]) print("%s, Step %d, Cost %f" %
(train_title, step, event.metrics[0]))
if step % 100 == 0: # record a test cost every 100 batches if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test( test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order) reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0]) print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
plot_cost.plot()
if test_metrics[0] < 10.0: if test_metrics[0] < 10.0:
# If the accuracy is good enough, we can stop the training. # If the accuracy is good enough, we can stop the training.
...@@ -109,7 +105,7 @@ def event_handler_plot(event): ...@@ -109,7 +105,7 @@ def event_handler_plot(event):
trainer.train( trainer.train(
reader=train_reader, reader=train_reader,
num_epochs=100, num_epochs=100,
event_handler=event_handler_plot, event_handler=event_handler,
feed_order=feed_order) feed_order=feed_order)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册