Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夏有凉风,冬有雪
Paddle
提交
d369577f
P
Paddle
项目概览
夏有凉风,冬有雪
/
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,发现更多精彩内容 >>
提交
d369577f
编写于
3月 31, 2017
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add reversed poolSequenceWithStride
上级
08d6622d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
40 addition
and
30 deletion
+40
-30
paddle/gserver/layers/SequenceLastInstanceLayer.cpp
paddle/gserver/layers/SequenceLastInstanceLayer.cpp
+2
-3
paddle/gserver/layers/SequencePoolLayer.cpp
paddle/gserver/layers/SequencePoolLayer.cpp
+3
-2
paddle/gserver/layers/SequencePoolLayer.h
paddle/gserver/layers/SequencePoolLayer.h
+2
-0
paddle/parameter/Argument.cpp
paddle/parameter/Argument.cpp
+11
-10
paddle/parameter/Argument.h
paddle/parameter/Argument.h
+2
-1
paddle/parameter/tests/test_argument.cpp
paddle/parameter/tests/test_argument.cpp
+19
-13
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+1
-1
未找到文件。
paddle/gserver/layers/SequenceLastInstanceLayer.cpp
浏览文件 @
d369577f
...
...
@@ -40,7 +40,6 @@ class SequenceLastInstanceLayer : public SequencePoolLayer {
protected:
MatrixPtr
tmpSrc_
;
MatrixPtr
tmpDest_
;
bool
select_first_
;
std
::
vector
<
int
>
insId_
;
public:
...
...
@@ -59,7 +58,7 @@ REGISTER_LAYER(seqlastins, SequenceLastInstanceLayer);
bool
SequenceLastInstanceLayer
::
init
(
const
LayerMap
&
layerMap
,
const
ParameterMap
&
parameterMap
)
{
SequencePoolLayer
::
init
(
layerMap
,
parameterMap
);
select_first
_
=
config_
.
select_first
();
reversed
_
=
config_
.
select_first
();
tmpSrc_
=
Matrix
::
create
(
nullptr
,
/* height= */
1
,
1
,
/* trans= */
false
,
useGpu_
);
...
...
@@ -83,7 +82,7 @@ void SequenceLastInstanceLayer::forward(PassType passType) {
insId_
.
clear
();
for
(
size_t
seqId
=
0
;
seqId
<
newBatchSize_
;
++
seqId
)
{
int
insId
=
select_first
_
?
starts
[
seqId
]
:
starts
[
seqId
+
1
]
-
1
;
int
insId
=
reversed
_
?
starts
[
seqId
]
:
starts
[
seqId
+
1
]
-
1
;
insId_
.
push_back
(
insId
);
outputValue
->
subMatrix
(
seqId
,
1
,
tmpDest_
)
...
...
paddle/gserver/layers/SequencePoolLayer.cpp
浏览文件 @
d369577f
...
...
@@ -68,8 +68,9 @@ void SequencePoolLayer::forward(PassType passType) {
}
if
(
stride_
>
0
)
{
CHECK_EQ
(
input
.
hasSubseq
(),
0UL
)
<<
"sequence stride pooling is not suitable for hasSubseq now"
;
output_
.
poolSequenceWithStride
(
input
,
stride_
,
&
stridePositions_
);
<<
"sequence stride pooling is invalid for hasSubseq now"
;
output_
.
poolSequenceWithStride
(
input
,
stride_
,
&
stridePositions_
,
reversed_
);
newBatchSize_
=
stridePositions_
->
getSize
()
-
1
;
}
...
...
paddle/gserver/layers/SequencePoolLayer.h
浏览文件 @
d369577f
...
...
@@ -49,6 +49,8 @@ protected:
int
stride_
;
// store the start position of each stride window
IVectorPtr
stridePositions_
;
// Whether it is reversed sequence
bool
reversed_
=
false
;
public:
explicit
SequencePoolLayer
(
const
LayerConfig
&
config
)
:
Layer
(
config
)
{}
...
...
paddle/parameter/Argument.cpp
浏览文件 @
d369577f
...
...
@@ -561,11 +561,13 @@ void Argument::degradeSequence(const Argument& input) {
void
Argument
::
poolSequenceWithStride
(
const
Argument
&
input
,
size_t
stride
,
IVectorPtr
*
stridePostions
)
{
IVectorPtr
*
stridePostions
,
bool
reversed
)
{
/*
* If input.sequenceStartPositions = [0, 9, 14, 17, 30] and stride = 5,
* then sequenceStartPositions = [0, 2, 3, 4, 7],
* and stridePostions = [0, 5, 9, 14, 17, 22, 27, 30]
* then sequenceStartPositions = [0, 2, 3, 4, 7].
* If reversed = false, stridePostions = [0, 5, 9, 14, 17, 22, 27, 30];
* else reversed = true, stridePostions = [0, 4, 9, 14, 17, 20, 25, 30]
*/
CHECK
(
input
.
sequenceStartPositions
);
CHECK_EQ
(
input
.
hasSubseq
(),
0UL
);
...
...
@@ -584,14 +586,13 @@ void Argument::poolSequenceWithStride(const Argument& input,
if
(
seqLength
==
0
)
{
// empty sequence
tgtBuf
[
seqId
+
1
]
=
tgtBuf
[
seqId
];
}
else
if
(
seqLength
<
stride
)
{
tgtBuf
[
seqId
+
1
]
=
tgtBuf
[
seqId
]
+
1
;
}
else
{
tgtBuf
[
seqId
+
1
]
=
tgtBuf
[
seqId
]
+
ceil
((
float
)
seqLength
/
stride
);
int
size
=
(
seqLength
%
stride
)
?
seqLength
/
stride
:
seqLength
/
stride
-
1
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
stridePos
.
emplace_back
(
stridePos
.
back
()
+
stride
);
int
size
=
ceil
((
float
)
seqLength
/
stride
);
tgtBuf
[
seqId
+
1
]
=
tgtBuf
[
seqId
]
+
size
;
for
(
int
i
=
0
;
i
<
size
-
1
;
i
++
)
{
int
cur
=
reversed
?
starts
[
seqId
+
1
]
-
(
size
-
1
-
i
)
*
stride
:
stridePos
.
back
()
+
stride
;
stridePos
.
emplace_back
(
cur
);
}
}
}
...
...
paddle/parameter/Argument.h
浏览文件 @
d369577f
...
...
@@ -298,7 +298,8 @@ struct Argument {
*/
void
poolSequenceWithStride
(
const
Argument
&
input
,
size_t
stride
,
IVectorPtr
*
stridePositions
);
IVectorPtr
*
stridePositions
,
bool
reversed
=
false
);
/**
* @brief getValueString will return the argument's output in string. There
* are several kinds of output. The keys of output dictionary are 'value',
...
...
paddle/parameter/tests/test_argument.cpp
浏览文件 @
d369577f
...
...
@@ -27,20 +27,26 @@ TEST(Argument, poolSequenceWithStride) {
inStart
[
3
]
=
17
;
inStart
[
4
]
=
30
;
IVectorPtr
stridePositions
;
output
.
poolSequenceWithStride
(
input
,
5
/* stride */
,
&
stridePositions
);
const
int
*
outStart
=
output
.
sequenceStartPositions
->
getData
(
false
);
CHECK_EQ
(
outStart
[
0
],
0
);
CHECK_EQ
(
outStart
[
1
],
2
);
CHECK_EQ
(
outStart
[
2
],
3
);
CHECK_EQ
(
outStart
[
3
],
4
);
CHECK_EQ
(
outStart
[
4
],
7
);
CHECK_EQ
(
stridePositions
->
getSize
(),
8
);
int
strideResult
[]
=
{
0
,
5
,
9
,
14
,
17
,
22
,
27
,
30
};
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
CHECK_EQ
(
stridePositions
->
getData
()[
i
],
strideResult
[
i
]);
int
strideResultReversed
[]
=
{
0
,
4
,
9
,
14
,
17
,
20
,
25
,
30
};
for
(
auto
reversed
:
{
false
,
true
})
{
IVectorPtr
stridePositions
;
output
.
poolSequenceWithStride
(
input
,
5
/* stride */
,
&
stridePositions
,
reversed
);
const
int
*
outStart
=
output
.
sequenceStartPositions
->
getData
(
false
);
CHECK_EQ
(
outStart
[
0
],
0
);
CHECK_EQ
(
outStart
[
1
],
2
);
CHECK_EQ
(
outStart
[
2
],
3
);
CHECK_EQ
(
outStart
[
3
],
4
);
CHECK_EQ
(
outStart
[
4
],
7
);
CHECK_EQ
(
stridePositions
->
getSize
(),
8
);
auto
result
=
reversed
?
strideResultReversed
:
strideResult
;
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
CHECK_EQ
(
stridePositions
->
getData
()[
i
],
result
[
i
]);
}
}
}
...
...
python/paddle/trainer/config_parser.py
浏览文件 @
d369577f
...
...
@@ -2497,7 +2497,7 @@ class SequenceLastInstanceLayer(LayerBase):
config_assert
(
len
(
inputs
)
==
1
,
'SequenceLastInstanceLayer must have 1 input'
)
if
trans_type
==
'seq'
:
config_assert
(
stride
==
-
1
,
'subseq do not support stride window'
)
config_assert
(
stride
==
-
1
,
'subseq do
es
not support stride window'
)
self
.
config
.
trans_type
=
trans_type
self
.
config
.
seq_pool_stride
=
stride
self
.
set_layer_size
(
self
.
get_input_layer
(
0
).
size
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录