Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
733ea0d2
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看板
提交
733ea0d2
编写于
8月 24, 2018
作者:
C
chenweihang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adjust infershape details
上级
2969aba1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
11 addition
and
23 deletion
+11
-23
paddle/fluid/operators/sequence_enumerate_op.cc
paddle/fluid/operators/sequence_enumerate_op.cc
+4
-11
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+2
-2
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+1
-3
python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py
...addle/fluid/tests/unittests/test_sequence_enumerate_op.py
+4
-7
未找到文件。
paddle/fluid/operators/sequence_enumerate_op.cc
浏览文件 @
733ea0d2
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
// limitations under the License.
// limitations under the License.
#include "paddle/fluid/operators/sequence_enumerate_op.h"
#include "paddle/fluid/operators/sequence_enumerate_op.h"
#include <vector>
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
...
@@ -34,18 +33,12 @@ class SequenceEnumerateOp : public framework::OperatorWithKernel {
...
@@ -34,18 +33,12 @@ class SequenceEnumerateOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ
(
PADDLE_ENFORCE_EQ
(
x_dims
.
size
(),
2UL
,
x_dims
.
size
(),
2UL
,
"Input(X) of SequenceEnumerate operator's rank should be 2."
);
"Input(X) of SequenceEnumerate operator's rank should be 2."
);
PADDLE_ENFORCE_EQ
(
x_dims
[
1
],
1UL
,
"Input(X) of SequenceEnumerate operator's 2nd dimension should be 1."
);
const
auto
win_size
=
ctx
->
Attrs
().
Get
<
int
>
(
"win_size"
);
const
auto
win_size
=
ctx
->
Attrs
().
Get
<
int
>
(
"win_size"
);
// TODO(chenweihang): unittest doesn't has batch size, but test_layers has
ctx
->
SetOutputDim
(
"Out"
,
{
x_dims
[
0
],
win_size
});
auto
first_dim
=
x_dims
[
0
]
==
-
1
?
x_dims
[
1
]
:
x_dims
[
0
];
PADDLE_ENFORCE
(
win_size
<=
first_dim
,
"The enumerate window size should be less than or equal to "
"input sequence length."
);
std
::
vector
<
int64_t
>
out_shape
(
x_dims
.
size
()
+
1
,
0
);
for
(
int
i
=
0
;
i
<
x_dims
.
size
();
++
i
)
out_shape
.
emplace_back
(
x_dims
[
i
]);
out_shape
.
emplace_back
(
win_size
);
ctx
->
SetOutputDim
(
"Out"
,
framework
::
make_ddim
(
out_shape
));
ctx
->
ShareLoD
(
"X"
,
"Out"
);
ctx
->
ShareLoD
(
"X"
,
"Out"
);
}
}
};
};
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
733ea0d2
...
@@ -5563,7 +5563,7 @@ def sequence_enumerate(input, win_size, pad_value, name=None):
...
@@ -5563,7 +5563,7 @@ def sequence_enumerate(input, win_size, pad_value, name=None):
out = fluid.layers.sequence_enumerate(input=x, win_size=3, pad_value=0)
out = fluid.layers.sequence_enumerate(input=x, win_size=3, pad_value=0)
"""
"""
helper
=
LayerHelper
(
'sequence_enumerate'
,
**
locals
())
helper
=
LayerHelper
(
'sequence_enumerate'
,
**
locals
())
out
=
helper
.
create_tmp_variable
(
helper
.
input_dtype
())
out
=
helper
.
create_tmp_variable
(
helper
.
input_dtype
()
,
stop_gradient
=
True
)
helper
.
append_op
(
helper
.
append_op
(
type
=
'sequence_enumerate'
,
type
=
'sequence_enumerate'
,
inputs
=
{
'X'
:
input
},
inputs
=
{
'X'
:
input
},
...
@@ -5571,7 +5571,7 @@ def sequence_enumerate(input, win_size, pad_value, name=None):
...
@@ -5571,7 +5571,7 @@ def sequence_enumerate(input, win_size, pad_value, name=None):
attrs
=
{
'win_size'
:
win_size
,
attrs
=
{
'win_size'
:
win_size
,
'pad_value'
:
pad_value
})
'pad_value'
:
pad_value
})
def
stack
(
x
,
axis
=
0
):
def
stack
(
x
,
axis
=
0
):
helper
=
LayerHelper
(
'stack'
,
**
locals
())
helper
=
LayerHelper
(
'stack'
,
**
locals
())
axis
=
0
if
axis
is
None
else
axis
axis
=
0
if
axis
is
None
else
axis
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
733ea0d2
...
@@ -522,10 +522,8 @@ class TestBook(unittest.TestCase):
...
@@ -522,10 +522,8 @@ class TestBook(unittest.TestCase):
def
test_sequence_enumerate
(
self
):
def
test_sequence_enumerate
(
self
):
program
=
Program
()
program
=
Program
()
with
program_guard
(
program
):
with
program_guard
(
program
):
x
=
layers
.
data
(
x
=
layers
.
data
(
name
=
"input"
,
shape
=
[
1
],
dtype
=
'int32'
,
lod_level
=
1
)
name
=
"input"
,
shape
=
[
30
],
dtype
=
'int32'
,
lod_level
=
1
)
out
=
layers
.
sequence_enumerate
(
input
=
x
,
win_size
=
2
,
pad_value
=
0
)
out
=
layers
.
sequence_enumerate
(
input
=
x
,
win_size
=
2
,
pad_value
=
0
)
self
.
assertIsNotNone
(
out
)
print
(
str
(
program
))
print
(
str
(
program
))
...
...
python/paddle/fluid/tests/unittests/test_sequence_enumerate_op.py
浏览文件 @
733ea0d2
...
@@ -19,7 +19,7 @@ import numpy as np
...
@@ -19,7 +19,7 @@ import numpy as np
from
op_test
import
OpTest
from
op_test
import
OpTest
def
sequence_enumerate
(
input_seq
,
lod0
,
win_size
,
pad_value
):
def
sequence_enumerate
(
input_seq
,
win_size
,
pad_value
):
out_seq
=
[]
out_seq
=
[]
for
idx
in
range
(
0
,
len
(
input_seq
)):
for
idx
in
range
(
0
,
len
(
input_seq
)):
single_seq
=
[]
single_seq
=
[]
...
@@ -48,8 +48,7 @@ class TestSequenceEnumerateOp(OpTest):
...
@@ -48,8 +48,7 @@ class TestSequenceEnumerateOp(OpTest):
self
.
lod
=
[[
9
,
4
,
11
,
6
]]
self
.
lod
=
[[
9
,
4
,
11
,
6
]]
self
.
win_size
=
2
self
.
win_size
=
2
self
.
pad_value
=
0
self
.
pad_value
=
0
out_seq
=
sequence_enumerate
(
self
.
in_seq
,
self
.
lod
[
0
],
self
.
win_size
,
out_seq
=
sequence_enumerate
(
self
.
in_seq
,
self
.
win_size
,
self
.
pad_value
)
self
.
pad_value
)
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int32"
)
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int32"
)
...
@@ -59,8 +58,7 @@ class TesSequenceEnumerateOpInt64(TestSequenceEnumerateOp):
...
@@ -59,8 +58,7 @@ class TesSequenceEnumerateOpInt64(TestSequenceEnumerateOp):
self
.
lod
=
[[
9
,
4
,
11
,
6
]]
self
.
lod
=
[[
9
,
4
,
11
,
6
]]
self
.
win_size
=
2
self
.
win_size
=
2
self
.
pad_value
=
0
self
.
pad_value
=
0
out_seq
=
sequence_enumerate
(
self
.
in_seq
,
self
.
lod
[
0
],
self
.
win_size
,
out_seq
=
sequence_enumerate
(
self
.
in_seq
,
self
.
win_size
,
self
.
pad_value
)
self
.
pad_value
)
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int64"
)
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int64"
)
...
@@ -70,8 +68,7 @@ class TestSequenceEnumerateOpMaxWinSize(TestSequenceEnumerateOp):
...
@@ -70,8 +68,7 @@ class TestSequenceEnumerateOpMaxWinSize(TestSequenceEnumerateOp):
self
.
lod
=
[[
9
,
4
,
11
,
6
]]
self
.
lod
=
[[
9
,
4
,
11
,
6
]]
self
.
win_size
=
30
self
.
win_size
=
30
self
.
pad_value
=
0
self
.
pad_value
=
0
out_seq
=
sequence_enumerate
(
self
.
in_seq
,
self
.
lod
[
0
],
self
.
win_size
,
out_seq
=
sequence_enumerate
(
self
.
in_seq
,
self
.
win_size
,
self
.
pad_value
)
self
.
pad_value
)
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int32"
)
self
.
out_seq
=
np
.
array
(
out_seq
).
astype
(
"int32"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录