Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
6ba1445a
B
book
项目概览
PaddlePaddle
/
book
通知
16
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6ba1445a
编写于
10月 09, 2018
作者:
M
minqiyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove plot in 1.0 book
上级
3d5b8e61
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
23 addition
and
47 deletion
+23
-47
01.fit_a_line/README.cn.md
01.fit_a_line/README.cn.md
+4
-9
01.fit_a_line/README.md
01.fit_a_line/README.md
+5
-10
01.fit_a_line/index.cn.html
01.fit_a_line/index.cn.html
+4
-9
01.fit_a_line/index.html
01.fit_a_line/index.html
+5
-10
01.fit_a_line/train.py
01.fit_a_line/train.py
+5
-9
未找到文件。
01.fit_a_line/README.cn.md
浏览文件 @
6ba1445a
...
...
@@ -183,27 +183,22 @@ feed_order=['x', 'y']
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
# Plot data
from
paddle.utils
import
Ploter
train_title
=
"Train cost"
test_title
=
"Test cost"
plot_cost
=
Ploter
(
train_title
,
test_title
)
step
=
0
# event_handler prints training and testing info
def
event_handler
_plot
(
event
):
def
event_handler
(
event
):
global
step
if
isinstance
(
event
,
fluid
.
contrib
.
trainer
.
EndStepEvent
):
if
step
%
10
==
0
:
# record a train cost every 10 batches
p
lot_cost
.
append
(
train_title
,
step
,
event
.
metrics
[
0
]
)
p
rint
(
"%s, Step %d, Cost %f"
%
(
train_title
,
step
,
event
.
metrics
[
0
])
)
if
step
%
100
==
0
:
# record a test cost every 100 batches
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
plot_cost
.
append
(
test_title
,
step
,
test_metrics
[
0
])
plot_cost
.
plot
()
print
(
"%s, Step %d, Cost %f"
%
(
test_title
,
step
,
test_metrics
[
0
]))
if
test_metrics
[
0
]
<
10.0
:
# If the accuracy is good enough, we can stop the training.
...
...
@@ -228,7 +223,7 @@ def event_handler_plot(event):
trainer
.
train
(
reader
=
train_reader
,
num_epochs
=
100
,
event_handler
=
event_handler
_plot
,
event_handler
=
event_handler
,
feed_order
=
feed_order
)
```
<div
align=
"center"
>
...
...
01.fit_a_line/README.md
浏览文件 @
6ba1445a
...
...
@@ -202,27 +202,22 @@ Moreover, an event handler is provided to print the training progress:
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
# Plot data
from
paddle.utils
import
Ploter
train_title
=
"Train cost"
test_title
=
"Test cost"
plot_cost
=
Ploter
(
train_title
,
test_title
)
step
=
0
# event_handler prints training and testing info
def
event_handler
_plot
(
event
):
def
event_handler
(
event
):
global
step
if
isinstance
(
event
,
fluid
.
contrib
.
trainer
.
EndStepEvent
):
if
step
%
10
==
0
:
# record a train cost every 10 batches
p
lot_cost
.
append
(
train_title
,
step
,
event
.
metrics
[
0
]
)
p
rint
(
"%s, Step %d, Cost %f"
%
(
train_title
,
step
,
event
.
metrics
[
0
])
)
if
step
%
100
==
0
:
# record a test cost every 100 batches
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
plot_cost
.
append
(
test_title
,
step
,
test_metrics
[
0
])
plot_cost
.
plot
()
print
(
"%s, Step %d, Cost %f"
%
(
test_title
,
step
,
test_metrics
[
0
]))
if
test_metrics
[
0
]
<
10.0
:
# If the accuracy is good enough, we can stop the training.
...
...
@@ -230,7 +225,7 @@ def event_handler_plot(event):
trainer
.
stop
()
step
+=
1
if
isinstance
(
event
,
fluid
.
contrib
.
trainer
.
EndEpochEvent
):
if
isinstance
(
event
,
EndEpochEvent
):
if
event
.
epoch
%
10
==
0
:
# We can save the trained parameters for the inferences later
if
params_dirname
is
not
None
:
...
...
@@ -249,7 +244,7 @@ We now can start training by calling `trainer.train()`.
trainer
.
train
(
reader
=
train_reader
,
num_epochs
=
100
,
event_handler
=
event_handler
_plot
,
event_handler
=
event_handler
,
feed_order
=
feed_order
)
```
...
...
01.fit_a_line/index.cn.html
浏览文件 @
6ba1445a
...
...
@@ -225,27 +225,22 @@ feed_order=['x', 'y']
# Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.utils import Ploter
train_title = "Train cost"
test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0
# event_handler prints training and testing info
def event_handler
_plot
(event):
def event_handler(event):
global step
if isinstance(event, fluid.contrib.trainer.EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches
p
lot_cost.append(train_title, step, event.metrics[0]
)
p
rint("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0])
)
if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0])
plot_cost.plot()
print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
if test_metrics[0]
<
10.0
:
#
If
the
accuracy
is
good
enough
,
we
can
stop
the
training.
...
...
@@ -270,7 +265,7 @@ def event_handler_plot(event):
trainer.train
(
reader=
train_reader,
num_epochs=
100,
event_handler=
event_handler
_plot
,
event_handler=
event_handler,
feed_order=
feed_order)
```
<
div
align=
"center"
>
...
...
01.fit_a_line/index.html
浏览文件 @
6ba1445a
...
...
@@ -244,27 +244,22 @@ Moreover, an event handler is provided to print the training progress:
# Specify the directory to save the parameters
params_dirname = "fit_a_line.inference.model"
# Plot data
from paddle.utils import Ploter
train_title = "Train cost"
test_title = "Test cost"
plot_cost = Ploter(train_title, test_title)
step = 0
# event_handler prints training and testing info
def event_handler
_plot
(event):
def event_handler(event):
global step
if isinstance(event, fluid.contrib.trainer.EndStepEvent):
if step % 10 == 0: # record a train cost every 10 batches
p
lot_cost.append(train_title, step, event.metrics[0]
)
p
rint("%s, Step %d, Cost %f" % (train_title, step, event.metrics[0])
)
if step % 100 == 0: # record a test cost every 100 batches
test_metrics = trainer.test(
reader=test_reader, feed_order=feed_order)
plot_cost.append(test_title, step, test_metrics[0])
plot_cost.plot()
print("%s, Step %d, Cost %f" % (test_title, step, test_metrics[0]))
if test_metrics[0]
<
10.0
:
#
If
the
accuracy
is
good
enough
,
we
can
stop
the
training.
...
...
@@ -272,7 +267,7 @@ def event_handler_plot(event):
trainer.stop
()
step
+=
1
if
isinstance
(
event
,
fluid.contrib.trainer.
EndEpochEvent
)
:
if
isinstance
(
event
,
EndEpochEvent
)
:
if
event.epoch
%
10
==
0
:
#
We
can
save
the
trained
parameters
for
the
inferences
later
if
params_dirname
is
not
None:
...
...
@@ -291,7 +286,7 @@ We now can start training by calling `trainer.train()`.
trainer.train
(
reader=
train_reader,
num_epochs=
100,
event_handler=
event_handler
_plot
,
event_handler=
event_handler,
feed_order=
feed_order)
```
...
...
01.fit_a_line/train.py
浏览文件 @
6ba1445a
...
...
@@ -69,28 +69,24 @@ feed_order = ['x', 'y']
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
# Plot data
from
paddle.utils
import
Ploter
train_title
=
"Train cost"
test_title
=
"Test cost"
plot_cost
=
Ploter
(
train_title
,
test_title
)
step
=
0
# event_handler prints training and testing info
def
event_handler
_plot
(
event
):
def
event_handler
(
event
):
global
step
if
isinstance
(
event
,
EndStepEvent
):
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
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
plot_cost
.
append
(
test_title
,
step
,
test_metrics
[
0
])
plot_cost
.
plot
()
print
(
"%s, Step %d, Cost %f"
%
(
test_title
,
step
,
test_metrics
[
0
]))
if
test_metrics
[
0
]
<
10.0
:
# If the accuracy is good enough, we can stop the training.
...
...
@@ -109,7 +105,7 @@ def event_handler_plot(event):
trainer
.
train
(
reader
=
train_reader
,
num_epochs
=
100
,
event_handler
=
event_handler
_plot
,
event_handler
=
event_handler
,
feed_order
=
feed_order
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录