Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
debfb008
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
debfb008
编写于
11月 02, 2017
作者:
D
Dong Zhihong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"add evaluator design doc"
上级
cf302bdd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
69 deletion
+60
-69
doc/design/evaluator.md
doc/design/evaluator.md
+29
-21
python/paddle/v2/framework/evaluator.py
python/paddle/v2/framework/evaluator.py
+30
-48
python/paddle/v2/framework/tests/test_evaluator.py
python/paddle/v2/framework/tests/test_evaluator.py
+1
-0
未找到文件。
doc/design/evaluator.md
浏览文件 @
debfb008
...
...
@@ -22,28 +22,36 @@ class Evaluator(object):
"""
Evalutor Base class.
"""
def
_initialize
(
self
):
"""
add initialize operators and create metric states to block
"""
pass
def
_add_evalutor_op
(
self
):
"""
add mini-batch caculate operators to block
"""
pass
def
_merge
(
self
);
"""
Merge the mini-batch statistics to form the evaluation result for multiple mini-batches.
"""
pass
def
__init__
(
self
):
"""
create metric states and append to block
"""
pass
def
_clear_state
(
self
):
"""
clear metric states at the begin of each pass
"""
pass
def
_append_evalutor_op
(
self
):
"""
add mini-batch caculate operators to block
add increment operator to accumulate the metric state
"""
pass
def
_merge
(
self
):
"""
Merge the mini-batch statistics to form the evaluation result for multiple mini-batches.
"""
pass
def
evaluate
(
self
):
"""
exported interface
"""
"""
only one exported interface
user calculate the result
"""
pass
```
python/paddle/v2/framework/evaluator.py
浏览文件 @
debfb008
...
...
@@ -3,57 +3,39 @@ import numpy as np
import
paddle.v2.framework.core
as
core
def
avg_accumulate
(
accumulated_var
,
per_eval
,
num_batches
,
place
):
t
=
np
.
array
(
accumulated_var
.
get_tensor
())
t
[
0
]
+=
per_eval
[
0
]
accumulated_var
.
get_tensor
().
set
([
t
[
0
]
/
float
(
num_batches
)],
place
)
class
Evaluator
(
object
):
"""
Evalutor Base class.
"""
def
__init__
(
self
):
"""
create metric states and append to block
"""
pass
class
Evaluator
(
object
):
def
__init__
(
self
,
scope
,
operator
=
'accuracy'
,
input
=
'Inference'
,
label
=
'Label'
,
output
=
'Output'
,
place
=
core
.
CPUPlace
()):
def
_clear_state
(
self
):
"""
create an evaluator for evaluating the inference.
NOTE: default run on CPUPlace(), running on GPUPlace doesn't improve performance much.
clear metric states at the begin of each pass
"""
pass
:param scope: the scope instance contains the input.
:type scope: paddle.v2.framework.core.scope
:param operator: operator name for caculating the evaluation for each mini-batch.
:type operator: string
:param input: output variable name of forward network.
:type input: string
:param label: variable name of label
:type label: string
def
_append_evalutor_op
(
self
):
"""
self
.
scope
=
scope
self
.
place
=
place
self
.
output_name
=
output
self
.
num_batches
=
0
# create variable to store accumulated evaluator output
eval_name
=
''
.
join
([
operator
,
"@Eval"
])
if
scope
.
find_var
(
eval_name
):
raise
Exception
(
"evaluator already exist in scope: %s"
%
eval_name
)
self
.
accumulated_var
=
scope
.
var
(
eval_name
)
t
=
self
.
accumulated_var
.
get_tensor
()
t
.
set_dims
((
1
,
))
t
.
set
([
0.0
],
place
)
# self.accumulated_var = block.create_var(block, name=eval_name, shape=(1,))
# self.accumulated_var.get_tensor().set([0.0])
# create operator of evaluation
var_map
=
dict
()
# var name -> variable
var_map
[
input
]
=
[
input
]
var_map
[
label
]
=
[
label
]
var_map
[
output
]
=
[
output
]
self
.
op
=
op
.
Operator
(
operator
,
**
var_map
)
add mini-batch caculate operators to block
add increment operator to accumulate the metric state
"""
pass
def
evaluate
(
self
,
ctx
,
accumulator
=
avg_accumulate
):
self
.
op
.
run
(
self
.
scope
,
ctx
)
per_eval
=
np
.
array
(
self
.
scope
.
find_var
(
self
.
output_name
).
get_tensor
())
self
.
num_batches
+=
1
accumulator
(
self
.
accumulated_var
,
per_eval
,
self
.
num_batches
,
self
.
place
)
def
_merge
(
self
):
"""
Merge the mini-batch statistics to form the evaluation result for multiple mini-batches.
"""
pass
def
evaluate
(
self
):
"""
only one exported interface
user calculate the result
"""
pass
python/paddle/v2/framework/tests/test_evaluator.py
浏览文件 @
debfb008
...
...
@@ -4,6 +4,7 @@ import paddle.v2.framework.core as core
import
unittest
import
op_test
import
numpy
as
np
exit
(
0
)
class
TestEvaluator
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录