Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
795f572f
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
795f572f
编写于
2月 28, 2018
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename 'seq_error' to 'instance_error'
上级
87d90d2a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
18 addition
and
13 deletion
+18
-13
python/paddle/fluid/evaluator.py
python/paddle/fluid/evaluator.py
+18
-13
未找到文件。
python/paddle/fluid/evaluator.py
浏览文件 @
795f572f
...
...
@@ -22,6 +22,7 @@ from layer_helper import LayerHelper
__all__
=
[
'Accuracy'
,
'ChunkEvaluator'
,
'EditDistance'
,
]
...
...
@@ -211,7 +212,7 @@ class ChunkEvaluator(Evaluator):
class
EditDistance
(
Evaluator
):
"""
Accumulate edit distance sum and sequence number from mini-batches and
compute the average edit_distance of all batches.
compute the average edit_distance
and instance error
of all batches.
Args:
input: the sequences predicted by network.
...
...
@@ -228,11 +229,11 @@ class EditDistance(Evaluator):
distance_evaluator.reset(exe)
for data in batches:
loss = exe.run(fetch_list=[cost])
distance,
seque
nce_error = distance_evaluator.eval(exe)
distance,
insta
nce_error = distance_evaluator.eval(exe)
In the above example:
'distance' is the average of the edit distance rate in a pass.
'
sequence_error' is the seque
nce error rate in a pass.
'
instance_error' is the insta
nce error rate in a pass.
"""
...
...
@@ -246,8 +247,8 @@ class EditDistance(Evaluator):
dtype
=
'float32'
,
shape
=
[
1
],
suffix
=
'total_distance'
)
self
.
seq_num
=
self
.
create_state
(
dtype
=
'int64'
,
shape
=
[
1
],
suffix
=
'seq_num'
)
self
.
seq
_error
=
self
.
create_state
(
dtype
=
'int64'
,
shape
=
[
1
],
suffix
=
'
seq
_error'
)
self
.
instance
_error
=
self
.
create_state
(
dtype
=
'int64'
,
shape
=
[
1
],
suffix
=
'
instance
_error'
)
distances
,
seq_num
=
layers
.
edit_distance
(
input
=
input
,
label
=
label
,
ignored_tokens
=
ignored_tokens
)
...
...
@@ -255,15 +256,18 @@ class EditDistance(Evaluator):
compare_result
=
layers
.
equal
(
distances
,
zero
)
compare_result_int
=
layers
.
cast
(
x
=
compare_result
,
dtype
=
'int'
)
seq_right_count
=
layers
.
reduce_sum
(
compare_result_int
)
seq_error_count
=
layers
.
elementwise_sub
(
x
=
seq_num
,
y
=
seq_right_count
)
instance_error_count
=
layers
.
elementwise_sub
(
x
=
seq_num
,
y
=
seq_right_count
)
total_distance
=
layers
.
reduce_sum
(
distances
)
layers
.
sums
(
input
=
[
self
.
total_distance
,
total_distance
],
out
=
self
.
total_distance
)
layers
.
sums
(
input
=
[
self
.
seq_num
,
seq_num
],
out
=
self
.
seq_num
)
layers
.
sums
(
input
=
[
self
.
seq_error
,
seq_error_count
],
out
=
self
.
seq_error
)
layers
.
sums
(
input
=
[
self
.
instance_error
,
instance_error_count
],
out
=
self
.
instance_error
)
self
.
metrics
.
append
(
total_distance
)
self
.
metrics
.
append
(
seq
_error_count
)
self
.
metrics
.
append
(
instance
_error_count
)
def
eval
(
self
,
executor
,
eval_program
=
None
):
if
eval_program
is
None
:
...
...
@@ -272,11 +276,12 @@ class EditDistance(Evaluator):
with
program_guard
(
main_program
=
eval_program
):
total_distance
=
_clone_var_
(
block
,
self
.
total_distance
)
seq_num
=
_clone_var_
(
block
,
self
.
seq_num
)
seq_error
=
_clone_var_
(
block
,
self
.
seq
_error
)
instance_error
=
_clone_var_
(
block
,
self
.
instance
_error
)
seq_num
=
layers
.
cast
(
x
=
seq_num
,
dtype
=
'float32'
)
seq_error
=
layers
.
cast
(
x
=
seq
_error
,
dtype
=
'float32'
)
instance_error
=
layers
.
cast
(
x
=
instance
_error
,
dtype
=
'float32'
)
avg_distance
=
layers
.
elementwise_div
(
x
=
total_distance
,
y
=
seq_num
)
avg_seq_error
=
layers
.
elementwise_div
(
x
=
seq_error
,
y
=
seq_num
)
result
=
executor
.
run
(
eval_program
,
fetch_list
=
[
avg_distance
,
avg_seq_error
])
avg_instance_error
=
layers
.
elementwise_div
(
x
=
instance_error
,
y
=
seq_num
)
result
=
executor
.
run
(
eval_program
,
fetch_list
=
[
avg_distance
,
avg_instance_error
])
return
np
.
array
(
result
[
0
]),
np
.
array
(
result
[
1
])
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录