Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
9dde5640
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9dde5640
编写于
8月 30, 2019
作者:
L
Liufang Sang
提交者:
whs
8月 30, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change var name padding_num to padding_value (#19498)
上级
5b5379b3
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
16 addition
and
15 deletion
+16
-15
paddle/fluid/operators/ctc_align_op.cc
paddle/fluid/operators/ctc_align_op.cc
+2
-2
paddle/fluid/operators/ctc_align_op.cu
paddle/fluid/operators/ctc_align_op.cu
+4
-4
paddle/fluid/operators/ctc_align_op.h
paddle/fluid/operators/ctc_align_op.h
+3
-2
python/paddle/fluid/tests/unittests/test_ctc_align.py
python/paddle/fluid/tests/unittests/test_ctc_align.py
+7
-7
未找到文件。
paddle/fluid/operators/ctc_align_op.cc
浏览文件 @
9dde5640
...
...
@@ -57,7 +57,7 @@ class CTCAlignOpMaker : public framework::OpProtoAndCheckerMaker {
"merge repeated elements between two blanks. "
)
.
SetDefault
(
true
);
// add attr padding number for tensor input
AddAttr
<
int
>
(
"padding_
num
"
,
AddAttr
<
int
>
(
"padding_
value
"
,
"(int, default: 0), padding number "
"use to padding tensor. "
)
.
SetDefault
(
0
);
...
...
@@ -89,7 +89,7 @@ or Given:
And:
blank = 0
merge_repeated = True
padding_
num
= 0
padding_
value
= 0
Then:
Output.data = [[1, 2, 4, 0, 0, 0],
...
...
paddle/fluid/operators/ctc_align_op.cu
浏览文件 @
9dde5640
...
...
@@ -46,7 +46,7 @@ template <typename T>
__global__
void
PaddingMergeAndDelCudaKernel
(
const
int64_t
num_token
,
const
T
*
tokens
,
const
int
blank
,
const
int
merge_repeated
,
const
int
padding_
num
,
const
int
padding_
value
,
const
int64_t
batch_size
,
T
*
output
)
{
int
ind
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
...
...
@@ -62,7 +62,7 @@ __global__ void PaddingMergeAndDelCudaKernel(const int64_t num_token,
prev_token
=
tokens
[
i
];
}
for
(
int
i
=
output_idx
;
i
<
ind
*
num_token
+
num_token
;
i
++
)
{
output
[
i
]
=
padding_
num
;
output
[
i
]
=
padding_
value
;
}
}
...
...
@@ -82,13 +82,13 @@ class CTCAlignOpCUDAKernel : public framework::OpKernel<T> {
// tensor input which has no lod
if
(
input
->
lod
().
empty
())
{
const
int
padding_
num
=
ctx
.
Attr
<
int
>
(
"padding_num
"
);
const
int
padding_
value
=
ctx
.
Attr
<
int
>
(
"padding_value
"
);
auto
input_dims
=
input
->
dims
();
T
*
output_data
=
output
->
mutable_data
<
T
>
({
input_dims
[
0
],
input_dims
[
1
]},
ctx
.
GetPlace
());
PaddingMergeAndDelCudaKernel
<
T
><<<
32
,
(
input_dims
[
0
]
+
32
-
1
)
/
32
,
0
,
stream
>>>
(
input_dims
[
1
],
tokens
,
blank
,
merge_repeated
,
padding_
num
,
input_dims
[
1
],
tokens
,
blank
,
merge_repeated
,
padding_
value
,
input_dims
[
0
],
output_data
);
}
else
{
const
size_t
level
=
0
;
...
...
paddle/fluid/operators/ctc_align_op.h
浏览文件 @
9dde5640
...
...
@@ -39,7 +39,8 @@ class CTCAlignKernel : public framework::OpKernel<T> {
// support tensor input, no lod information
if
(
input
->
lod
().
empty
())
{
size_t
padding_num
=
static_cast
<
size_t
>
(
ctx
.
Attr
<
int
>
(
"padding_num"
));
size_t
padding_value
=
static_cast
<
size_t
>
(
ctx
.
Attr
<
int
>
(
"padding_value"
));
for
(
size_t
batch_id
=
0
;
batch_id
<
(
unsigned
)
input_dims
[
0
];
batch_id
++
)
{
T
prev_token
=
-
1
;
...
...
@@ -55,7 +56,7 @@ class CTCAlignKernel : public framework::OpKernel<T> {
prev_token
=
input_data
[
input_ind
];
}
for
(
size_t
j
=
output_idx
;
j
<
(
unsigned
)
input_dims
[
1
];
j
++
)
output_data
[
batch_id
*
input_dims
[
1
]
+
j
]
=
padding_
num
;
output_data
[
batch_id
*
input_dims
[
1
]
+
j
]
=
padding_
value
;
}
}
else
{
const
size_t
level
=
0
;
...
...
python/paddle/fluid/tests/unittests/test_ctc_align.py
浏览文件 @
9dde5640
...
...
@@ -109,7 +109,7 @@ class TestCTCAlignPaddingOp(OpTest):
self
.
op_type
=
"ctc_align"
self
.
input_lod
=
[]
self
.
blank
=
0
self
.
padding_
num
=
0
self
.
padding_
value
=
0
self
.
merge_repeated
=
True
self
.
input
=
np
.
array
([[
0
,
2
,
4
,
4
,
0
,
6
,
3
,
6
,
6
,
0
,
0
],
[
1
,
1
,
3
,
0
,
0
,
4
,
5
,
6
,
0
,
0
,
0
]]).
reshape
(
...
...
@@ -118,13 +118,13 @@ class TestCTCAlignPaddingOp(OpTest):
def
setUp
(
self
):
self
.
config
()
output
=
CTCAlign
(
self
.
input
,
self
.
input_lod
,
self
.
blank
,
self
.
merge_repeated
,
self
.
padding_
num
)
self
.
merge_repeated
,
self
.
padding_
value
)
self
.
inputs
=
{
"Input"
:
(
self
.
input
,
self
.
input_lod
),
}
self
.
outputs
=
{
"Output"
:
output
}
self
.
attrs
=
{
"blank"
:
self
.
blank
,
"merge_repeated"
:
self
.
merge_repeated
,
"padding_
num"
:
self
.
padding_num
"padding_
value"
:
self
.
padding_value
}
def
test_check_output
(
self
):
...
...
@@ -138,7 +138,7 @@ class TestCTCAlignOpCase3(TestCTCAlignPaddingOp):
self
.
blank
=
0
self
.
input_lod
=
[]
self
.
merge_repeated
=
True
self
.
padding_
num
=
0
self
.
padding_
value
=
0
self
.
input
=
np
.
array
([[
0
,
1
,
2
,
2
,
0
,
4
],
[
0
,
4
,
5
,
0
,
6
,
0
],
[
0
,
7
,
7
,
7
,
0
,
0
]]).
reshape
(
[
3
,
6
]).
astype
(
"int32"
)
...
...
@@ -146,7 +146,7 @@ class TestCTCAlignOpCase3(TestCTCAlignPaddingOp):
class
TestCTCAlignOpCase4
(
TestCTCAlignPaddingOp
):
'''
# test tensor input which has attr input padding_
num
# test tensor input which has attr input padding_
value
'''
def
config
(
self
):
...
...
@@ -154,7 +154,7 @@ class TestCTCAlignOpCase4(TestCTCAlignPaddingOp):
self
.
blank
=
0
self
.
input_lod
=
[]
self
.
merge_repeated
=
False
self
.
padding_
num
=
0
self
.
padding_
value
=
0
self
.
input
=
np
.
array
([[
0
,
1
,
2
,
2
,
0
,
4
],
[
0
,
4
,
5
,
0
,
6
,
0
],
[
0
,
7
,
7
,
7
,
0
,
0
]]).
reshape
(
[
3
,
6
]).
astype
(
"int32"
)
...
...
@@ -166,7 +166,7 @@ class TestCTCAlignOpCase5(TestCTCAlignPaddingOp):
self
.
blank
=
0
self
.
input_lod
=
[]
self
.
merge_repeated
=
False
self
.
padding_
num
=
1
self
.
padding_
value
=
1
self
.
input
=
np
.
array
([[
0
,
1
,
2
,
2
,
0
,
4
],
[
0
,
4
,
5
,
0
,
6
,
0
],
[
0
,
7
,
1
,
7
,
0
,
0
]]).
reshape
(
[
3
,
6
]).
astype
(
"int32"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录