Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
urhero
Paddle
提交
d815ec23
P
Paddle
项目概览
urhero
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d815ec23
编写于
1月 24, 2018
作者:
Y
Yang Yu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use test accuracy to exit(0)
上级
ef55a8f6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
10 deletion
+21
-10
python/paddle/v2/fluid/tests/book/test_recognize_digits.py
python/paddle/v2/fluid/tests/book/test_recognize_digits.py
+21
-10
未找到文件。
python/paddle/v2/fluid/tests/book/test_recognize_digits.py
浏览文件 @
d815ec23
...
...
@@ -16,6 +16,7 @@ import argparse
import
paddle.v2.fluid
as
fluid
import
paddle.v2
as
paddle
import
sys
import
numpy
def
parse_arg
():
...
...
@@ -100,6 +101,8 @@ def main():
else
:
avg_loss
,
acc
=
net_conf
(
img
,
label
)
test_program
=
fluid
.
default_main_program
().
clone
()
optimizer
=
fluid
.
optimizer
.
Adam
(
learning_rate
=
0.001
)
optimizer
.
minimize
(
avg_loss
)
...
...
@@ -112,6 +115,8 @@ def main():
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
mnist
.
train
(),
buf_size
=
500
),
batch_size
=
BATCH_SIZE
)
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
mnist
.
test
(),
batch_size
=
BATCH_SIZE
)
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
img
,
label
],
place
=
place
)
PASS_NUM
=
100
...
...
@@ -119,21 +124,27 @@ def main():
for
batch_id
,
data
in
enumerate
(
train_reader
()):
need_check
=
(
batch_id
+
1
)
%
10
==
0
# train a mini-batch, fetch nothing
exe
.
run
(
feed
=
feeder
.
feed
(
data
))
if
need_check
:
fetch_list
=
[
avg_loss
,
acc
]
else
:
fetch_list
=
[]
outs
=
exe
.
run
(
feed
=
feeder
.
feed
(
data
),
fetch_list
=
fetch_list
)
if
need_check
:
avg_loss_np
,
acc_np
=
outs
if
float
(
acc_np
)
>
0.9
:
acc_set
=
[]
avg_loss_set
=
[]
for
test_data
in
test_reader
():
acc_np
,
avg_loss_np
=
exe
.
run
(
program
=
test_program
,
feed
=
feeder
.
feed
(
test_data
),
fetch_list
=
[
acc
,
avg_loss
])
acc_set
.
append
(
float
(
acc_np
))
avg_loss_set
.
append
(
float
(
avg_loss_np
))
# get test acc and loss
acc_val
=
numpy
.
array
(
acc_set
).
mean
()
avg_loss_val
=
numpy
.
array
(
avg_loss_set
).
mean
()
if
float
(
acc_val
)
>
0.85
:
# test acc > 85%
exit
(
0
)
else
:
print
(
'PassID {0:1}, BatchID {1:04}, Loss {2:2.2}, Acc {3:2.2}'
.
'PassID {0:1}, BatchID {1:04},
Test
Loss {2:2.2}, Acc {3:2.2}'
.
format
(
pass_id
,
batch_id
+
1
,
float
(
avg_loss_
np
),
float
(
acc_np
)))
float
(
avg_loss_
val
),
float
(
acc_val
)))
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录