Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
bbd7580e
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bbd7580e
编写于
5月 16, 2018
作者:
K
Kexin Zhao
提交者:
daminglu
5月 16, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplify recognize digits example code (#10722)
上级
2a636529
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
20 deletion
+8
-20
python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py
...-level-api/recognize_digits/test_recognize_digits_conv.py
+4
-10
python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py
...h-level-api/recognize_digits/test_recognize_digits_mlp.py
+4
-10
未找到文件。
python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py
浏览文件 @
bbd7580e
...
@@ -71,24 +71,18 @@ def train(use_cuda, train_program, save_dirname):
...
@@ -71,24 +71,18 @@ def train(use_cuda, train_program, save_dirname):
if
isinstance
(
event
,
fluid
.
EndEpochEvent
):
if
isinstance
(
event
,
fluid
.
EndEpochEvent
):
test_reader
=
paddle
.
batch
(
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
mnist
.
test
(),
batch_size
=
BATCH_SIZE
)
paddle
.
dataset
.
mnist
.
test
(),
batch_size
=
BATCH_SIZE
)
test_metrics
=
trainer
.
test
(
avg_cost
,
acc
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
[
'img'
,
'label'
])
reader
=
test_reader
,
feed_order
=
[
'img'
,
'label'
])
avg_cost_set
=
test_metrics
[
0
]
acc_set
=
test_metrics
[
1
]
# get test acc and loss
acc
=
numpy
.
array
(
acc_set
).
mean
()
avg_cost
=
numpy
.
array
(
avg_cost_set
).
mean
()
print
(
"avg_cost: %s"
%
avg_cost
)
print
(
"avg_cost: %s"
%
avg_cost
)
print
(
"acc : %s"
%
acc
)
print
(
"acc : %s"
%
acc
)
if
float
(
acc
)
>
0.2
:
# Smaller value to increase CI speed
if
acc
>
0.2
:
# Smaller value to increase CI speed
trainer
.
save_params
(
save_dirname
)
trainer
.
save_params
(
save_dirname
)
else
:
else
:
print
(
'BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'
.
format
(
print
(
'BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'
.
format
(
event
.
epoch
+
1
,
float
(
avg_cost
),
float
(
acc
)
))
event
.
epoch
+
1
,
avg_cost
,
acc
))
if
math
.
isnan
(
float
(
avg_cost
)
):
if
math
.
isnan
(
avg_cost
):
sys
.
exit
(
"got NaN loss, training failed."
)
sys
.
exit
(
"got NaN loss, training failed."
)
elif
isinstance
(
event
,
fluid
.
EndStepEvent
):
elif
isinstance
(
event
,
fluid
.
EndStepEvent
):
print
(
"Step {0}, Epoch {1} Metrics {2}"
.
format
(
print
(
"Step {0}, Epoch {1} Metrics {2}"
.
format
(
...
...
python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py
浏览文件 @
bbd7580e
...
@@ -55,24 +55,18 @@ def train(use_cuda, train_program, save_dirname):
...
@@ -55,24 +55,18 @@ def train(use_cuda, train_program, save_dirname):
if
isinstance
(
event
,
fluid
.
EndEpochEvent
):
if
isinstance
(
event
,
fluid
.
EndEpochEvent
):
test_reader
=
paddle
.
batch
(
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
mnist
.
test
(),
batch_size
=
BATCH_SIZE
)
paddle
.
dataset
.
mnist
.
test
(),
batch_size
=
BATCH_SIZE
)
test_metrics
=
trainer
.
test
(
avg_cost
,
acc
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
[
'img'
,
'label'
])
reader
=
test_reader
,
feed_order
=
[
'img'
,
'label'
])
avg_cost_set
=
test_metrics
[
0
]
acc_set
=
test_metrics
[
1
]
# get test acc and loss
acc
=
numpy
.
array
(
acc_set
).
mean
()
avg_cost
=
numpy
.
array
(
avg_cost_set
).
mean
()
print
(
"avg_cost: %s"
%
avg_cost
)
print
(
"avg_cost: %s"
%
avg_cost
)
print
(
"acc : %s"
%
acc
)
print
(
"acc : %s"
%
acc
)
if
float
(
acc
)
>
0.2
:
# Smaller value to increase CI speed
if
acc
>
0.2
:
# Smaller value to increase CI speed
trainer
.
save_params
(
save_dirname
)
trainer
.
save_params
(
save_dirname
)
else
:
else
:
print
(
'BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'
.
format
(
print
(
'BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'
.
format
(
event
.
epoch
+
1
,
float
(
avg_cost
),
float
(
acc
)
))
event
.
epoch
+
1
,
avg_cost
,
acc
))
if
math
.
isnan
(
float
(
avg_cost
)
):
if
math
.
isnan
(
avg_cost
):
sys
.
exit
(
"got NaN loss, training failed."
)
sys
.
exit
(
"got NaN loss, training failed."
)
train_reader
=
paddle
.
batch
(
train_reader
=
paddle
.
batch
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录