Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9e1799cb
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9e1799cb
编写于
11月 09, 2017
作者:
D
Dong Zhihong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"fix based on comments"
上级
cfbc92e6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
5 addition
and
11 deletion
+5
-11
doc/design/evaluator.md
doc/design/evaluator.md
+2
-2
python/paddle/v2/framework/evaluator.py
python/paddle/v2/framework/evaluator.py
+2
-2
python/paddle/v2/framework/tests/test_fit_a_line.py
python/paddle/v2/framework/tests/test_fit_a_line.py
+1
-7
未找到文件。
doc/design/evaluator.md
浏览文件 @
9e1799cb
...
...
@@ -42,14 +42,14 @@ class Evaluator(object):
"""
def
reset
(
self
,
executor
,
program
=
None
):
def
reset
(
self
,
executor
,
reset_
program
=
None
):
"""
Reset metric states at the begin of each pass/user specified batch number.
Execute the reset_program to reset the states.
"""
def
eval
(
self
,
executor
,
program
=
None
):
def
eval
(
self
,
executor
,
eval_
program
=
None
):
"""
Merge the mini-batch statistics to form the evaluation result for multiple mini-batches.
Execute the eval_program and return the result.
...
...
python/paddle/v2/framework/evaluator.py
浏览文件 @
9e1799cb
...
...
@@ -39,7 +39,7 @@ class Evaluator(object):
"""
raise
NotImplementedError
()
def
reset
(
self
,
executor
,
program
=
None
):
def
reset
(
self
,
executor
,
reset_
program
=
None
):
"""
Clear metric states at the begin of each pass/user specified batch
"""
...
...
@@ -63,7 +63,7 @@ class Evaluator(object):
type
=
"scale"
,
inputs
=
{
"X"
:
zeros
},
outputs
=
{
"Out"
:
g_var
})
executor
.
run
(
reset_program
,
fetch_list
=
self
.
_states
.
values
())
def
eval
(
self
,
executor
,
program
=
None
):
def
eval
(
self
,
executor
,
eval_
program
=
None
):
"""
Merge the mini-batch statistics to form the evaluation result for multiple mini-batches.
"""
...
...
python/paddle/v2/framework/tests/test_fit_a_line.py
浏览文件 @
9e1799cb
...
...
@@ -6,7 +6,6 @@ import paddle.v2.framework.optimizer as optimizer
from
paddle.v2.framework.framework
import
Program
,
g_main_program
from
paddle.v2.framework.io
import
save_persistables
,
load_persistables
from
paddle.v2.framework.executor
import
Executor
from
paddle.v2.framework.evaluator
import
Accuracy
import
numpy
as
np
...
...
@@ -32,8 +31,6 @@ y = layers.data(
main_program
=
main_program
,
startup_program
=
startup_program
)
accuracy
=
evaluator
.
Accuracy
(
input
=
y_predict
,
label
=
y
)
cost
=
layers
.
square_error_cost
(
input
=
y_predict
,
label
=
y
,
...
...
@@ -61,7 +58,6 @@ PASS_NUM = 100
for
pass_id
in
range
(
PASS_NUM
):
save_persistables
(
exe
,
"./fit_a_line.model/"
,
main_program
=
main_program
)
load_persistables
(
exe
,
"./fit_a_line.model/"
,
main_program
=
main_program
)
accuracy
.
reset
(
exe
)
for
data
in
train_reader
():
x_data
=
np
.
array
(
map
(
lambda
x
:
x
[
0
],
data
)).
astype
(
"float32"
)
y_data
=
np
.
array
(
map
(
lambda
x
:
x
[
1
],
data
)).
astype
(
"float32"
)
...
...
@@ -76,10 +72,8 @@ for pass_id in range(PASS_NUM):
outs
=
exe
.
run
(
main_program
,
feed
=
{
'x'
:
tensor_x
,
'y'
:
tensor_y
},
fetch_list
=
[
avg_cost
,
accuracy
])
fetch_list
=
[
avg_cost
])
out
=
np
.
array
(
outs
[
0
])
pass_acc
=
accuracy
.
eval
(
exe
)
print
pass_acc
if
out
[
0
]
<
10.0
:
exit
(
0
)
# if avg cost less than 10.0, we think our code is good.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录