Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
f594ca43
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
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看板
提交
f594ca43
编写于
1月 10, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reuse the usable variable in edit_distance_op
上级
0250e54c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
12 addition
and
12 deletion
+12
-12
paddle/operators/edit_distance_op.cc
paddle/operators/edit_distance_op.cc
+2
-2
paddle/operators/edit_distance_op.cu
paddle/operators/edit_distance_op.cu
+4
-4
paddle/operators/edit_distance_op.h
paddle/operators/edit_distance_op.h
+6
-6
未找到文件。
paddle/operators/edit_distance_op.cc
浏览文件 @
f594ca43
...
@@ -49,10 +49,10 @@ class EditDistanceOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -49,10 +49,10 @@ class EditDistanceOpMaker : public framework::OpProtoAndCheckerMaker {
EditDistanceOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
EditDistanceOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"Hyps"
,
AddInput
(
"Hyps"
,
"(2-D LoDTensor, 2nd dim. equal to 1) "
"(2-D LoDTensor
<int>
, 2nd dim. equal to 1) "
"The indices for hypothesis strings."
);
"The indices for hypothesis strings."
);
AddInput
(
"Refs"
,
AddInput
(
"Refs"
,
"(2-D LoDTensor, 2nd dim. equal to 1) "
"(2-D LoDTensor
<int>
, 2nd dim. equal to 1) "
"The indices for reference strings."
);
"The indices for reference strings."
);
AddAttr
<
bool
>
(
"normalized"
,
AddAttr
<
bool
>
(
"normalized"
,
"(bool, default false) Indicated whether to normalize "
"(bool, default false) Indicated whether to normalize "
...
...
paddle/operators/edit_distance_op.cu
浏览文件 @
f594ca43
...
@@ -93,21 +93,21 @@ class EditDistanceGPUKernel : public framework::OpKernel<T> {
...
@@ -93,21 +93,21 @@ class EditDistanceGPUKernel : public framework::OpKernel<T> {
out_t
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
out_t
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
out
=
out_t
->
data
<
T
>
();
auto
out
=
out_t
->
data
<
T
>
();
std
::
vector
<
T
>
distance
(
num_strs
,
0.0
)
;
T
distance
=
0.0
;
for
(
size_t
num
=
0
;
num
<
num_strs
;
num
++
)
{
for
(
size_t
num
=
0
;
num
<
num_strs
;
num
++
)
{
auto
m
=
static_cast
<
int64_t
>
(
hyp_lod
[
num
+
1
]
-
hyp_lod
[
num
]);
auto
m
=
static_cast
<
int64_t
>
(
hyp_lod
[
num
+
1
]
-
hyp_lod
[
num
]);
auto
n
=
static_cast
<
int64_t
>
(
ref_lod
[
num
+
1
]
-
ref_lod
[
num
]);
auto
n
=
static_cast
<
int64_t
>
(
ref_lod
[
num
+
1
]
-
ref_lod
[
num
]);
if
(
m
==
0
||
n
==
0
)
{
if
(
m
==
0
||
n
==
0
)
{
distance
[
num
]
=
std
::
max
(
m
,
n
);
distance
=
std
::
max
(
m
,
n
);
if
(
normalized
)
{
if
(
normalized
)
{
PADDLE_ENFORCE
(
n
>
0
,
PADDLE_ENFORCE
(
n
>
0
,
"The reference string (#%d) cannot be empty "
"The reference string (#%d) cannot be empty "
"when Attr(normalized) is enabled."
,
"when Attr(normalized) is enabled."
,
n
);
n
);
distance
[
num
]
=
distance
[
num
]
/
n
;
distance
=
distance
/
n
;
}
}
memory
::
Copy
(
boost
::
get
<
Place
>
(
ctx
.
GetPlace
()),
out
+
num
,
memory
::
Copy
(
boost
::
get
<
Place
>
(
ctx
.
GetPlace
()),
out
+
num
,
platform
::
CPUPlace
(),
&
distance
[
num
]
,
sizeof
(
T
),
stream
);
platform
::
CPUPlace
(),
&
distance
,
sizeof
(
T
),
stream
);
}
else
{
}
else
{
framework
::
Tensor
dist_t
;
framework
::
Tensor
dist_t
;
dist_t
.
Resize
({
m
+
1
,
n
+
1
});
dist_t
.
Resize
({
m
+
1
,
n
+
1
});
...
...
paddle/operators/edit_distance_op.h
浏览文件 @
f594ca43
...
@@ -46,15 +46,15 @@ class EditDistanceKernel : public framework::OpKernel<T> {
...
@@ -46,15 +46,15 @@ class EditDistanceKernel : public framework::OpKernel<T> {
out_t
->
mutable_data
<
float
>
(
ctx
.
GetPlace
());
out_t
->
mutable_data
<
float
>
(
ctx
.
GetPlace
());
auto
out
=
out_t
->
data
<
T
>
();
auto
out
=
out_t
->
data
<
T
>
();
std
::
vector
<
T
>
distance
(
num_strs
,
0.0
)
;
T
distance
=
0.0
;
for
(
size_t
num
=
0
;
num
<
num_strs
;
++
num
)
{
for
(
size_t
num
=
0
;
num
<
num_strs
;
++
num
)
{
auto
m
=
static_cast
<
int64_t
>
(
hyp_lod
[
num
+
1
]
-
hyp_lod
[
num
]);
auto
m
=
static_cast
<
int64_t
>
(
hyp_lod
[
num
+
1
]
-
hyp_lod
[
num
]);
auto
n
=
static_cast
<
int64_t
>
(
ref_lod
[
num
+
1
]
-
ref_lod
[
num
]);
auto
n
=
static_cast
<
int64_t
>
(
ref_lod
[
num
+
1
]
-
ref_lod
[
num
]);
if
(
m
==
0
)
{
if
(
m
==
0
)
{
distance
[
num
]
=
n
;
distance
=
n
;
}
else
if
(
n
==
0
)
{
}
else
if
(
n
==
0
)
{
distance
[
num
]
=
m
;
distance
=
m
;
}
else
{
}
else
{
framework
::
Tensor
dist_t
;
framework
::
Tensor
dist_t
;
dist_t
.
Resize
({
m
+
1
,
n
+
1
});
dist_t
.
Resize
({
m
+
1
,
n
+
1
});
...
@@ -77,7 +77,7 @@ class EditDistanceKernel : public framework::OpKernel<T> {
...
@@ -77,7 +77,7 @@ class EditDistanceKernel : public framework::OpKernel<T> {
dist
[
i
*
(
n
+
1
)
+
j
]
=
std
::
min
(
dels
,
std
::
min
(
ins
,
subs
));
dist
[
i
*
(
n
+
1
)
+
j
]
=
std
::
min
(
dels
,
std
::
min
(
ins
,
subs
));
}
}
}
}
distance
[
num
]
=
dist
[
m
*
(
n
+
1
)
+
n
];
distance
=
dist
[
m
*
(
n
+
1
)
+
n
];
}
}
if
(
normalized
)
{
if
(
normalized
)
{
...
@@ -85,9 +85,9 @@ class EditDistanceKernel : public framework::OpKernel<T> {
...
@@ -85,9 +85,9 @@ class EditDistanceKernel : public framework::OpKernel<T> {
"The reference string (#%d) cannot be empty "
"The reference string (#%d) cannot be empty "
"when Attr(normalized) is enabled."
,
"when Attr(normalized) is enabled."
,
n
);
n
);
distance
[
num
]
=
distance
[
num
]
/
n
;
distance
=
distance
/
n
;
}
}
out
[
num
]
=
distance
[
num
]
;
out
[
num
]
=
distance
;
}
}
}
}
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录