提交 11609762 编写于 作者: Q qiaolongfei

add event_handler_plot for 03.image_classification

上级 d6497f9d
...@@ -259,6 +259,7 @@ def event_handler_plot(event): ...@@ -259,6 +259,7 @@ def event_handler_plot(event):
``` ```
`event_handler` is used to plot some text data when training. `event_handler` is used to plot some text data when training.
```python ```python
lists = [] lists = []
......
...@@ -301,6 +301,7 @@ def event_handler_plot(event): ...@@ -301,6 +301,7 @@ def event_handler_plot(event):
``` ```
`event_handler` is used to plot some text data when training. `event_handler` is used to plot some text data when training.
```python ```python
lists = [] lists = []
......
...@@ -397,6 +397,34 @@ feeding={'image': 0, ...@@ -397,6 +397,34 @@ feeding={'image': 0,
Callback function `event_handler` will be called during training when a pre-defined event happens. Callback function `event_handler` will be called during training when a pre-defined event happens.
`event_handler_plot`is used to plot a figure like below:
![png](./image/train_and_test.png)
```python
from paddle.v2.plot import Ploter
train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
def event_handler_plot(event):
global step
if isinstance(event, paddle.event.EndIteration):
if step % 1 == 0:
cost_ploter.append(train_title, step, event.cost)
cost_ploter.plot()
step += 1
if isinstance(event, paddle.event.EndPass):
result = trainer.test(
reader=paddle.batch(
paddle.dataset.cifar.test10(), batch_size=128),
feeding=feeding)
cost_ploter.append(test_title, step, result.cost)
```
`event_handler` is used to plot some text data when training.
```python ```python
# event handler to track training and testing process # event handler to track training and testing process
...@@ -422,7 +450,7 @@ Finally, we can invoke `trainer.train` to start training: ...@@ -422,7 +450,7 @@ Finally, we can invoke `trainer.train` to start training:
trainer.train( trainer.train(
reader=reader, reader=reader,
num_passes=200, num_passes=200,
event_handler=event_handler, event_handler=event_handler_plot,
feeding=feeding) feeding=feeding)
``` ```
......
...@@ -389,6 +389,35 @@ feeding={'image': 0, ...@@ -389,6 +389,35 @@ feeding={'image': 0,
可以使用`event_handler`回调函数来观察训练过程,或进行测试等, 该回调函数是`trainer.train`函数里设定。 可以使用`event_handler`回调函数来观察训练过程,或进行测试等, 该回调函数是`trainer.train`函数里设定。
`event_handler_plot`可以用来利用回调数据来打点画图:
![png](./image/train_and_test.png)
```python
from paddle.v2.plot import Ploter
train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
def event_handler_plot(event):
global step
if isinstance(event, paddle.event.EndIteration):
if step % 1 == 0:
cost_ploter.append(train_title, step, event.cost)
cost_ploter.plot()
step += 1
if isinstance(event, paddle.event.EndPass):
result = trainer.test(
reader=paddle.batch(
paddle.dataset.cifar.test10(), batch_size=128),
feeding=feeding)
cost_ploter.append(test_title, step, result.cost)
```
`event_handler` 用来在训练过程中输出文本日志
```python ```python
# End batch and end pass event handler # End batch and end pass event handler
def event_handler(event): def event_handler(event):
...@@ -413,7 +442,7 @@ def event_handler(event): ...@@ -413,7 +442,7 @@ def event_handler(event):
trainer.train( trainer.train(
reader=reader, reader=reader,
num_passes=200, num_passes=200,
event_handler=event_handler, event_handler=event_handler_plot,
feeding=feeding) feeding=feeding)
``` ```
......
...@@ -439,6 +439,34 @@ feeding={'image': 0, ...@@ -439,6 +439,34 @@ feeding={'image': 0,
Callback function `event_handler` will be called during training when a pre-defined event happens. Callback function `event_handler` will be called during training when a pre-defined event happens.
`event_handler_plot`is used to plot a figure like below:
![png](./image/train_and_test.png)
```python
from paddle.v2.plot import Ploter
train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
def event_handler_plot(event):
global step
if isinstance(event, paddle.event.EndIteration):
if step % 1 == 0:
cost_ploter.append(train_title, step, event.cost)
cost_ploter.plot()
step += 1
if isinstance(event, paddle.event.EndPass):
result = trainer.test(
reader=paddle.batch(
paddle.dataset.cifar.test10(), batch_size=128),
feeding=feeding)
cost_ploter.append(test_title, step, result.cost)
```
`event_handler` is used to plot some text data when training.
```python ```python
# event handler to track training and testing process # event handler to track training and testing process
...@@ -464,7 +492,7 @@ Finally, we can invoke `trainer.train` to start training: ...@@ -464,7 +492,7 @@ Finally, we can invoke `trainer.train` to start training:
trainer.train( trainer.train(
reader=reader, reader=reader,
num_passes=200, num_passes=200,
event_handler=event_handler, event_handler=event_handler_plot,
feeding=feeding) feeding=feeding)
``` ```
......
...@@ -431,6 +431,35 @@ feeding={'image': 0, ...@@ -431,6 +431,35 @@ feeding={'image': 0,
可以使用`event_handler`回调函数来观察训练过程,或进行测试等, 该回调函数是`trainer.train`函数里设定。 可以使用`event_handler`回调函数来观察训练过程,或进行测试等, 该回调函数是`trainer.train`函数里设定。
`event_handler_plot`可以用来利用回调数据来打点画图:
![png](./image/train_and_test.png)
```python
from paddle.v2.plot import Ploter
train_title = "Train cost"
test_title = "Test cost"
cost_ploter = Ploter(train_title, test_title)
step = 0
def event_handler_plot(event):
global step
if isinstance(event, paddle.event.EndIteration):
if step % 1 == 0:
cost_ploter.append(train_title, step, event.cost)
cost_ploter.plot()
step += 1
if isinstance(event, paddle.event.EndPass):
result = trainer.test(
reader=paddle.batch(
paddle.dataset.cifar.test10(), batch_size=128),
feeding=feeding)
cost_ploter.append(test_title, step, result.cost)
```
`event_handler` 用来在训练过程中输出文本日志
```python ```python
# End batch and end pass event handler # End batch and end pass event handler
def event_handler(event): def event_handler(event):
...@@ -455,7 +484,7 @@ def event_handler(event): ...@@ -455,7 +484,7 @@ def event_handler(event):
trainer.train( trainer.train(
reader=reader, reader=reader,
num_passes=200, num_passes=200,
event_handler=event_handler, event_handler=event_handler_plot,
feeding=feeding) feeding=feeding)
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册