提交 6dcfad45 编写于 作者: G gangliao 提交者: GitHub

Merge pull request #297 from PaddlePaddle/readme

add event handler to print training logs
......@@ -67,6 +67,7 @@ RUN ${update_mirror_cmd}
apt-get -y install gcc && \
apt-get -y clean && \
localedef -f UTF-8 -i en_US en_US.UTF-8 && \
pip install --upgrade pip && \
pip install -U pillow matplotlib jupyter numpy requests scipy
#convert md to ipynb
......
......@@ -162,6 +162,22 @@ feeding={'x': 0, 'y': 1}
Moreover, an event handler is provided to print the training progress:
```python
# event_handler to print training and testing info
def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
print "Pass %d, Batch %d, Cost %f" % (
event.pass_id, event.batch_id, event.cost)
if isinstance(event, paddle.event.EndPass):
result = trainer.test(
reader=paddle.batch(
uci_housing.test(), batch_size=2),
feeding=feeding)
print "Test %d, Cost %f" % (event.pass_id, result.cost)
```
```python
# event_handler to print training and testing info
from paddle.v2.plot import Ploter
......@@ -172,7 +188,7 @@ plot_cost = Ploter(train_title, test_title)
step = 0
def event_handler(event):
def event_handler_plot(event):
global step
if isinstance(event, paddle.event.EndIteration):
if step % 10 == 0: # every 10 batches, record a train cost
......@@ -200,7 +216,7 @@ trainer.train(
uci_housing.train(), buf_size=500),
batch_size=2),
feeding=feeding,
event_handler=event_handler,
event_handler=event_handler_plot,
num_passes=30)
```
......
......@@ -157,6 +157,22 @@ feeding={'x': 0, 'y': 1}
此外,我们还可以提供一个 event handler,来打印训练的进度:
```python
# event_handler to print training and testing info
def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
print "Pass %d, Batch %d, Cost %f" % (
event.pass_id, event.batch_id, event.cost)
if isinstance(event, paddle.event.EndPass):
result = trainer.test(
reader=paddle.batch(
uci_housing.test(), batch_size=2),
feeding=feeding)
print "Test %d, Cost %f" % (event.pass_id, result.cost)
```
```python
# event_handler to print training and testing info
from paddle.v2.plot import Ploter
......@@ -167,7 +183,7 @@ cost_ploter = Ploter(train_title, test_title)
step = 0
def event_handler(event):
def event_handler_plot(event):
global step
if isinstance(event, paddle.event.EndIteration):
if step % 10 == 0: # every 10 batches, record a train cost
......@@ -195,7 +211,7 @@ trainer.train(
uci_housing.train(), buf_size=500),
batch_size=2),
feeding=feeding,
event_handler=event_handler,
event_handler=event_handler_plot,
num_passes=30)
```
......
......@@ -204,6 +204,22 @@ feeding={'x': 0, 'y': 1}
Moreover, an event handler is provided to print the training progress:
```python
# event_handler to print training and testing info
def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
print "Pass %d, Batch %d, Cost %f" % (
event.pass_id, event.batch_id, event.cost)
if isinstance(event, paddle.event.EndPass):
result = trainer.test(
reader=paddle.batch(
uci_housing.test(), batch_size=2),
feeding=feeding)
print "Test %d, Cost %f" % (event.pass_id, result.cost)
```
```python
# event_handler to print training and testing info
from paddle.v2.plot import Ploter
......@@ -214,7 +230,7 @@ plot_cost = Ploter(train_title, test_title)
step = 0
def event_handler(event):
def event_handler_plot(event):
global step
if isinstance(event, paddle.event.EndIteration):
if step % 10 == 0: # every 10 batches, record a train cost
......@@ -242,7 +258,7 @@ trainer.train(
uci_housing.train(), buf_size=500),
batch_size=2),
feeding=feeding,
event_handler=event_handler,
event_handler=event_handler_plot,
num_passes=30)
```
......
......@@ -199,6 +199,22 @@ feeding={'x': 0, 'y': 1}
此外,我们还可以提供一个 event handler,来打印训练的进度:
```python
# event_handler to print training and testing info
def event_handler(event):
if isinstance(event, paddle.event.EndIteration):
if event.batch_id % 100 == 0:
print "Pass %d, Batch %d, Cost %f" % (
event.pass_id, event.batch_id, event.cost)
if isinstance(event, paddle.event.EndPass):
result = trainer.test(
reader=paddle.batch(
uci_housing.test(), batch_size=2),
feeding=feeding)
print "Test %d, Cost %f" % (event.pass_id, result.cost)
```
```python
# event_handler to print training and testing info
from paddle.v2.plot import Ploter
......@@ -209,7 +225,7 @@ cost_ploter = Ploter(train_title, test_title)
step = 0
def event_handler(event):
def event_handler_plot(event):
global step
if isinstance(event, paddle.event.EndIteration):
if step % 10 == 0: # every 10 batches, record a train cost
......@@ -237,7 +253,7 @@ trainer.train(
uci_housing.train(), buf_size=500),
batch_size=2),
feeding=feeding,
event_handler=event_handler,
event_handler=event_handler_plot,
num_passes=30)
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册