Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzpei9
Paddle
提交
a8f118ca
P
Paddle
项目概览
wzpei9
/
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,发现更多精彩内容 >>
提交
a8f118ca
编写于
1月 20, 2018
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add EditDistance to evaluator.py
上级
680aec21
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
8 addition
and
6 deletion
+8
-6
python/paddle/v2/fluid/evaluator.py
python/paddle/v2/fluid/evaluator.py
+8
-6
未找到文件。
python/paddle/v2/fluid/evaluator.py
浏览文件 @
a8f118ca
...
...
@@ -218,21 +218,23 @@ class EditDistance(Evaluator):
raise
ValueError
(
"You can only invoke Evaluator in root block"
)
self
.
total_error
=
self
.
create_state
(
dtype
=
'int64'
,
shape
=
[
1
],
suffix
=
'total'
)
self
.
batch_num
=
0
dtype
=
'float32'
,
shape
=
[
1
],
suffix
=
'total'
)
self
.
batch_num
=
self
.
create_state
(
dtype
=
'float32'
,
shape
=
[
1
],
suffix
=
'total'
)
error
=
layers
.
edit_distance
(
input
=
input
,
label
=
label
)
mean_error
=
layers
.
mean
(
input
=
error
)
error
=
layers
.
cast
(
x
=
error
,
dtype
=
'float32'
)
mean_error
=
layers
.
mean
(
x
=
error
)
layers
.
sums
(
input
=
[
self
.
total_error
,
mean_error
],
out
=
self
.
total_error
)
const1
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
1.0
,
dtype
=
"float32"
)
layers
.
sums
(
input
=
[
self
.
batch_num
,
const1
],
out
=
self
.
batch_num
)
self
.
metrics
.
append
(
mean_error
)
def
eval
(
self
,
executor
,
eval_program
=
None
):
self
.
batch_num
+=
1
if
eval_program
is
None
:
eval_program
=
Program
()
block
=
eval_program
.
current_block
()
with
program_guard
(
main_program
=
eval_program
):
total_error
=
_clone_var_
(
block
,
self
.
total_error
)
batch_num
=
layers
.
fill_constant
(
shape
=
[
1
],
value
=
self
.
batch_num
,
dtype
=
"float32"
)
batch_num
=
_clone_var_
(
block
,
self
.
batch_num
)
out
=
layers
.
elementwise_div
(
x
=
total_error
,
y
=
batch_num
)
return
np
.
array
(
executor
.
run
(
eval_program
,
fetch_list
=
[
out
])[
0
])
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录