Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
29b3de6f
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看板
提交
29b3de6f
编写于
11月 06, 2017
作者:
Y
yangyaming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Bugs fix and expose sub_seq_layer.
上级
cb0118f3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
85 addition
and
4 deletion
+85
-4
paddle/gserver/layers/SubSequenceLayer.cpp
paddle/gserver/layers/SubSequenceLayer.cpp
+28
-4
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+57
-0
未找到文件。
paddle/gserver/layers/SubSequenceLayer.cpp
浏览文件 @
29b3de6f
...
...
@@ -98,8 +98,19 @@ void SubSequenceLayer::forward(PassType passType) {
CHECK_EQ
(
numSequences2
,
numSequences3
);
MatrixPtr
inputValue
=
input
.
value
;
IVectorPtr
offsetValue
=
offsetSeq
.
ids
;
IVectorPtr
sizeValue
=
sizeSeq
.
ids
;
IVectorPtr
offsetValue
;
IVectorPtr
sizeValue
;
if
(
useGpu_
)
{
// copy to cpu
IVector
::
resizeOrCreate
(
offsetValue
,
offsetSeq
.
ids
->
getSize
(),
false
);
IVector
::
resizeOrCreate
(
sizeValue
,
sizeSeq
.
ids
->
getSize
(),
false
);
offsetValue
->
copyFrom
(
*
offsetSeq
.
ids
);
sizeValue
->
copyFrom
(
*
sizeSeq
.
ids
);
}
else
{
offsetValue
=
offsetSeq
.
ids
;
sizeValue
=
sizeSeq
.
ids
;
}
CHECK_EQ
(
offsetValue
->
getSize
(),
numSequences1
);
CHECK_EQ
(
sizeValue
->
getSize
(),
numSequences1
);
...
...
@@ -176,8 +187,21 @@ void SubSequenceLayer::backward(const UpdateCallback& callback) {
size_t
numSequences1
=
startPositions1
->
getSize
()
-
1
;
const
int
*
starts1
=
startPositions1
->
getData
();
IVectorPtr
offsetValue
=
getInput
(
1
).
ids
;
IVectorPtr
sizeValue
=
getInput
(
2
).
ids
;
const
Argument
&
offsetSeq
=
getInput
(
1
);
const
Argument
&
sizeSeq
=
getInput
(
2
);
IVectorPtr
offsetValue
;
IVectorPtr
sizeValue
;
if
(
useGpu_
)
{
// copy to cpu
IVector
::
resizeOrCreate
(
offsetValue
,
offsetSeq
.
ids
->
getSize
(),
false
);
IVector
::
resizeOrCreate
(
sizeValue
,
sizeSeq
.
ids
->
getSize
(),
false
);
offsetValue
->
copyFrom
(
*
offsetSeq
.
ids
);
sizeValue
->
copyFrom
(
*
sizeSeq
.
ids
);
}
else
{
offsetValue
=
offsetSeq
.
ids
;
sizeValue
=
sizeSeq
.
ids
;
}
int
*
offsets
=
offsetValue
->
getData
();
int
*
sizes
=
sizeValue
->
getData
();
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
29b3de6f
...
...
@@ -143,6 +143,7 @@ __all__ = [
'scale_shift_layer'
,
'img_conv3d_layer'
,
'resize_layer'
,
'sub_seq_layer'
,
]
...
...
@@ -252,6 +253,7 @@ class LayerType(object):
SCALE_SHIFT_LAYER
=
'scale_shift'
RESIZE
=
'resize'
SUB_SEQ_LAYER
=
'subseq'
@
staticmethod
def
is_layer_type
(
type_name
):
...
...
@@ -6980,3 +6982,58 @@ def resize_layer(input, size, name=None):
"""
Layer
(
name
=
name
,
type
=
LayerType
.
RESIZE
,
inputs
=
Input
(
input
.
name
),
size
=
size
)
return
LayerOutput
(
name
,
LayerType
.
RESIZE
,
parents
=
[
input
],
size
=
input
.
size
)
@
wrap_act_default
(
act
=
LinearActivation
())
@
wrap_name_default
(
'sub_seq'
)
def
sub_seq_layer
(
input
,
offsets
,
sizes
,
act
=
None
,
bias_attr
=
None
,
name
=
None
):
"""
sub_seq_layer will return sub-sequences from the input sequences. For each
sequence in the input sequence layer, sub_seq_layer will slice it by given
offset and size. Please notice that, number of offset value and size value
both are equal to the number of sequence in the input layer.
.. code-block:: python
sub_seq = sub_seq_layer(input=input_seq, offsets=offsets, sizes=sizes)
:param name: The name of this layer. It is optional.
:type name: basestring
:param input: The input of this layer, which should be sequence.
:type input: LayerOutput
:param offsets: offset indices to slice the input sequence, which should be
sequence type.
:type offsets: LayerOutput
:param sizes: sizes of the sub-sequences, which should be sequence type.
:type sizes: LayerOutput
:param act: Layer activation, default is LinearActivation
:type act: BaseActivation.
:param bias_attr: The Bias Attribute. If the parameter is set to
False or something not type of ParameterAttribute,
no bias is defined. If the parameter is set to
True, the bias is initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any
:return: LayerOutput object.
:rtype: LayerOutput
"""
assert
isinstance
(
input
,
LayerOutput
),
(
'The first input of sub_seq_layer layer must be a PaddlePaddle layer.'
)
assert
isinstance
(
offsets
,
LayerOutput
),
(
'The offset indices for sub_seq_layer, '
'must be a PaddlePaddle layer.'
)
assert
isinstance
(
sizes
,
LayerOutput
),
(
'The sizes of sub-sequences, must be a PaddlePaddle layer.'
)
Layer
(
name
=
name
,
type
=
LayerType
.
SUB_SEQ_LAYER
,
inputs
=
[
input
.
name
,
offsets
.
name
,
sizes
.
name
],
active_type
=
act
.
name
,
bias
=
ParamAttr
.
to_bias
(
bias_attr
))
return
LayerOutput
(
name
,
LayerType
.
SUB_SEQ_LAYER
,
parents
=
[
input
,
offsets
,
sizes
],
size
=
input
.
size
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录