Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
TonyTonyFun
Paddle
提交
cbbec595
P
Paddle
项目概览
TonyTonyFun
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cbbec595
编写于
3月 24, 2017
作者:
L
Luo Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adjust poolSequenceWithStride interface for average and max
上级
0291c018
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
20 addition
and
19 deletion
+20
-19
paddle/gserver/layers/SequenceLastInstanceLayer.cpp
paddle/gserver/layers/SequenceLastInstanceLayer.cpp
+3
-5
paddle/gserver/layers/SequencePoolLayer.cpp
paddle/gserver/layers/SequencePoolLayer.cpp
+1
-1
paddle/gserver/layers/SequencePoolLayer.h
paddle/gserver/layers/SequencePoolLayer.h
+1
-1
paddle/parameter/Argument.cpp
paddle/parameter/Argument.cpp
+9
-6
paddle/parameter/Argument.h
paddle/parameter/Argument.h
+1
-1
paddle/parameter/tests/test_argument.cpp
paddle/parameter/tests/test_argument.cpp
+3
-4
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+2
-1
未找到文件。
paddle/gserver/layers/SequenceLastInstanceLayer.cpp
浏览文件 @
cbbec595
...
...
@@ -72,7 +72,8 @@ bool SequenceLastInstanceLayer::init(const LayerMap& layerMap,
void
SequenceLastInstanceLayer
::
forward
(
PassType
passType
)
{
SequencePoolLayer
::
forward
(
passType
);
const
int
*
starts
=
startPositions_
->
getData
(
false
);
auto
starts
=
(
stride_
>
0
)
?
stridePositions_
->
getData
()
:
startPositions_
->
getData
(
false
);
MatrixPtr
inputValue
=
getInputValue
(
0
);
MatrixPtr
outputValue
=
getOutputValue
();
...
...
@@ -82,10 +83,7 @@ void SequenceLastInstanceLayer::forward(PassType passType) {
insId_
.
clear
();
for
(
size_t
seqId
=
0
;
seqId
<
newBatchSize_
;
++
seqId
)
{
int
insId
=
(
stride_
>
0
)
?
(
select_first_
?
stridePositions_
[
seqId
]
:
stridePositions_
[
seqId
+
1
]
-
1
)
:
(
select_first_
?
starts
[
seqId
]
:
starts
[
seqId
+
1
]
-
1
);
int
insId
=
select_first_
?
starts
[
seqId
]
:
starts
[
seqId
+
1
]
-
1
;
insId_
.
push_back
(
insId
);
outputValue
->
subMatrix
(
seqId
,
1
,
tmpDest_
)
...
...
paddle/gserver/layers/SequencePoolLayer.cpp
浏览文件 @
cbbec595
...
...
@@ -70,7 +70,7 @@ void SequencePoolLayer::forward(PassType passType) {
CHECK_EQ
(
input
.
hasSubseq
(),
0UL
)
<<
"sequence stride pooling is not suitable for hasSubseq now"
;
output_
.
poolSequenceWithStride
(
input
,
stride_
,
&
stridePositions_
);
newBatchSize_
=
stridePositions_
.
s
ize
()
-
1
;
newBatchSize_
=
stridePositions_
->
getS
ize
()
-
1
;
}
resetOutput
(
newBatchSize_
,
dim
);
...
...
paddle/gserver/layers/SequencePoolLayer.h
浏览文件 @
cbbec595
...
...
@@ -48,7 +48,7 @@ protected:
ICpuGpuVectorPtr
startPositions_
;
int
stride_
;
// store the start position of each stride window
std
::
vector
<
int
>
stridePositions_
;
IVectorPtr
stridePositions_
;
public:
explicit
SequencePoolLayer
(
const
LayerConfig
&
config
)
:
Layer
(
config
)
{}
...
...
paddle/parameter/Argument.cpp
浏览文件 @
cbbec595
...
...
@@ -561,7 +561,7 @@ void Argument::degradeSequence(const Argument& input) {
void
Argument
::
poolSequenceWithStride
(
const
Argument
&
input
,
size_t
stride
,
std
::
vector
<
int
>
*
stridePostions
)
{
IVectorPtr
*
stridePostions
)
{
/*
* If input.sequenceStartPositions = [0, 9, 14, 17, 30] and stride = 5,
* then sequenceStartPositions = [0, 2, 3, 4, 7],
...
...
@@ -577,10 +577,10 @@ void Argument::poolSequenceWithStride(const Argument& input,
int
*
tgtBuf
=
sequenceStartPositions
->
getMutableData
(
false
);
// first index of target sequence and stride positions are both 0
tgtBuf
[
0
]
=
0
;
(
*
stridePostions
).
clear
()
;
std
::
vector
<
int
>
stridePos
;
for
(
size_t
seqId
=
0
;
seqId
<
numSequences
;
++
seqId
)
{
size_t
seqLength
=
starts
[
seqId
+
1
]
-
starts
[
seqId
];
(
*
stridePostions
)
.
emplace_back
(
starts
[
seqId
]);
stridePos
.
emplace_back
(
starts
[
seqId
]);
if
(
seqLength
==
0
)
{
// empty sequence
tgtBuf
[
seqId
+
1
]
=
tgtBuf
[
seqId
];
...
...
@@ -591,12 +591,15 @@ void Argument::poolSequenceWithStride(const Argument& input,
int
size
=
(
seqLength
%
stride
)
?
seqLength
/
stride
:
seqLength
/
stride
-
1
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
(
*
stridePostions
).
emplace_back
((
*
stridePostions
)
.
back
()
+
stride
);
stridePos
.
emplace_back
(
stridePos
.
back
()
+
stride
);
}
}
}
(
*
stridePostions
).
emplace_back
(
starts
[
numSequences
]);
CHECK_EQ
((
*
stridePostions
).
size
()
-
1
,
tgtBuf
[
numSequences
]);
stridePos
.
emplace_back
(
starts
[
numSequences
]);
int
size
=
stridePos
.
size
();
CHECK_EQ
(
size
-
1
,
tgtBuf
[
numSequences
]);
IVector
::
resizeOrCreate
(
*
stridePostions
,
size
,
false
);
(
*
stridePostions
)
->
copyFrom
(
stridePos
.
data
(),
size
);
}
void
Argument
::
getValueString
(
...
...
paddle/parameter/Argument.h
浏览文件 @
cbbec595
...
...
@@ -298,7 +298,7 @@ struct Argument {
*/
void
poolSequenceWithStride
(
const
Argument
&
input
,
size_t
stride
,
std
::
vector
<
int
>
*
stridePositions
);
IVectorPtr
*
stridePositions
);
/**
* @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
浏览文件 @
cbbec595
...
...
@@ -27,8 +27,7 @@ TEST(Argument, poolSequenceWithStride) {
inStart
[
3
]
=
17
;
inStart
[
4
]
=
30
;
std
::
vector
<
int
>
stridePositions
;
stridePositions
.
clear
();
IVectorPtr
stridePositions
;
output
.
poolSequenceWithStride
(
input
,
5
/* stride */
,
&
stridePositions
);
const
int
*
outStart
=
output
.
sequenceStartPositions
->
getData
(
false
);
...
...
@@ -38,10 +37,10 @@ TEST(Argument, poolSequenceWithStride) {
CHECK_EQ
(
outStart
[
3
],
4
);
CHECK_EQ
(
outStart
[
4
],
7
);
CHECK_EQ
(
stridePositions
.
s
ize
(),
8
);
CHECK_EQ
(
stridePositions
->
getS
ize
(),
8
);
int
strideResult
[]
=
{
0
,
5
,
9
,
14
,
17
,
22
,
27
,
30
};
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
CHECK_EQ
(
stridePositions
[
i
],
strideResult
[
i
]);
CHECK_EQ
(
stridePositions
->
getData
()
[
i
],
strideResult
[
i
]);
}
}
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
cbbec595
...
...
@@ -1406,7 +1406,6 @@ def first_seq(input,
and a long sequence will be shorten. Note that for sequence with
sub-sequence, stride is default -1 now.
The simple usage is:
.. code-block:: python
...
...
@@ -1418,6 +1417,8 @@ def first_seq(input,
:type name: basestring
:param input: Input layer name.
:type input: LayerOutput
:param stride: parameter of stride window.
:type stride: Int
:param layer_attr: extra layer attributes.
:type layer_attr: ExtraLayerAttribute.
:return: LayerOutput object.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录