Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
4c6bccbe
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,发现更多精彩内容 >>
提交
4c6bccbe
编写于
10月 24, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix doc and remove useless code
上级
154dbb46
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
71 addition
and
75 deletion
+71
-75
paddle/operators/math/CMakeLists.txt
paddle/operators/math/CMakeLists.txt
+2
-2
paddle/operators/math/sequence_project.h
paddle/operators/math/sequence_project.h
+57
-34
paddle/operators/sequence_conv_op.cc
paddle/operators/sequence_conv_op.cc
+12
-33
paddle/operators/sequence_conv_op.h
paddle/operators/sequence_conv_op.h
+0
-6
未找到文件。
paddle/operators/math/CMakeLists.txt
浏览文件 @
4c6bccbe
...
@@ -7,7 +7,7 @@ if(WITH_GPU)
...
@@ -7,7 +7,7 @@ if(WITH_GPU)
nv_library
(
cross_entropy SRCS cross_entropy.cc cross_entropy.cu DEPS operator
)
nv_library
(
cross_entropy SRCS cross_entropy.cc cross_entropy.cu DEPS operator
)
nv_library
(
pooling SRCS pooling.cc pooling.cu DEPS device_context
)
nv_library
(
pooling SRCS pooling.cc pooling.cu DEPS device_context
)
nv_library
(
vol2col SRCS vol2col.cc vol2col.cu DEPS device_context
)
nv_library
(
vol2col SRCS vol2col.cc vol2col.cu DEPS device_context
)
nv_library
(
sequence_project SRCS sequence_project.cc sequence_project.cu DEPS device_context
math_function
)
nv_library
(
sequence_project SRCS sequence_project.cc sequence_project.cu DEPS device_context
)
else
()
else
()
cc_library
(
math_function SRCS math_function.cc im2col.cc DEPS cblas device_context operator
)
cc_library
(
math_function SRCS math_function.cc im2col.cc DEPS cblas device_context operator
)
cc_library
(
selected_rows_functor SRCS selected_rows_functor.cc DEPS selected_rows math_function
)
cc_library
(
selected_rows_functor SRCS selected_rows_functor.cc DEPS selected_rows math_function
)
...
@@ -15,7 +15,7 @@ else()
...
@@ -15,7 +15,7 @@ else()
cc_library
(
cross_entropy SRCS cross_entropy.cc DEPS operator
)
cc_library
(
cross_entropy SRCS cross_entropy.cc DEPS operator
)
cc_library
(
pooling SRCS pooling.cc DEPS device_context
)
cc_library
(
pooling SRCS pooling.cc DEPS device_context
)
cc_library
(
vol2col SRCS vol2col.cc DEPS device_context
)
cc_library
(
vol2col SRCS vol2col.cc DEPS device_context
)
cc_library
(
sequence_project SRCS sequence_project.cc DEPS device_context
math_function
)
cc_library
(
sequence_project SRCS sequence_project.cc DEPS device_context
)
endif
()
endif
()
cc_test
(
math_function_test SRCS math_function_test.cc DEPS math_function tensor
)
cc_test
(
math_function_test SRCS math_function_test.cc DEPS math_function tensor
)
...
...
paddle/operators/math/sequence_project.h
浏览文件 @
4c6bccbe
...
@@ -18,7 +18,6 @@ limitations under the License. */
...
@@ -18,7 +18,6 @@ limitations under the License. */
#include "paddle/framework/lod_tensor.h"
#include "paddle/framework/lod_tensor.h"
#include "paddle/framework/tensor.h"
#include "paddle/framework/tensor.h"
#include "paddle/operators/math/im2col.h"
#include "paddle/operators/math/im2col.h"
#include "paddle/operators/math/math_function.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
...
@@ -32,37 +31,59 @@ template <typename T, int MajorType = Eigen::RowMajor,
...
@@ -32,37 +31,59 @@ template <typename T, int MajorType = Eigen::RowMajor,
typename
IndexType
=
Eigen
::
DenseIndex
>
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenMatrix
=
framework
::
EigenMatrix
<
T
,
MajorType
,
IndexType
>
;
using
EigenMatrix
=
framework
::
EigenMatrix
<
T
,
MajorType
,
IndexType
>
;
/*
/*
* \brief Converts the feature data of four dimensions(CDHW) into a colData of
* \brief SequenceProject projects features of context_length time-steps of each
* seven dimensions in the Vol2ColFunctor calculation,
* instance.
* And in the Col2VolFunctor calculation, it is reversed.
*
*
* \param volData Vol data.
* \param in Input data.
* \param volShape The shape of volData,
* \param inShape The shape of Input data,
* [input_channels, input_depth, input_height, input_width].
* [minibatch, number_of_input_features].
* \param colData Column data.
* \param inShape A float LoDTensor.
* \param colShape The shape of colData.
*
*
* The shape of colData is:
* \param padding_data Padding data.
* [input_channels, filter_depth, filter_height, filter_width, output_depth,
* \param inShape The shape of Padding data,
* output_height, output_width]
* [up_pad + down_pad, number_of_input_features].
* So, it is easy to reshape into a convolution matrix for convolution
* \param inShape A float LoDTensor.
* calculation based on matrix multiplication.
* The shape of convolution matrix is [height, width], where the height is equal
* input_channels * filter_depth * filter_height * filter_width, and the width
* is equal output_depth * output_height * output_width.
*
*
* Reshape:
* \param col Col data.
* shape of colData shape of convolution matrix
* \param inShape The shape of Col data,
* [input_channels,
* [minibatch, 1].
* filter_depth,
* \param inShape A float LoDTensor.
* filter_height,
*
* filter_width, ======> [height, width]
* For a mini-batch of 2 variable lengths sentences, containing 3, and 1
* output_depth,
* time-steps:
* output_height,
*
* output_width]
* Assumed input (X) is a [4, M, N] float LoDTensor, and X->lod()[0] = [0, 3,
* 4].
* Besides, for the sake of simplicity, we assume M=1 and N=2.
*
* X = [[a1, a2;
* b1, b2;
* c1, c2]
* [d1, d2]]
*
* This is to say that input (X) has 4 words and the dimension of each word
* representation is 2.
*
* - Case1:
* If context_start is -1 and padding_trainable is false, we use zero to pad
* instead of learned weight to pad,
* and the context_lenth is 3, the output (Out) is:
*
* Out =[[0, 0, a1, a2, b1, b2;
* a1, a2, b1, b2, c1, c2;
* b1, b2, c1, c2, 0, 0 ]
* [0, 0, d1, d2, 0, 0 ]]
*
* - Case2:
* If context_start is -1 and padding_trainable is true, we use learned weight
* to pad,
* and the context_lenth is 3, the output (Out) is:
*
* Out = [[w1, w2, a1, a2, b1, b2;
* a1, a2, b1, b2, c1, c2;
* b1, b2, c1, c2, w3, w4]
* [w1, w2, d1, d2, w3, w4]]
*
*
* \note The caller needs to ensure that volShape.inputChannels is equal to
* colShape.inputChannels.
*/
*/
template
<
typename
Place
,
typename
T
>
template
<
typename
Place
,
typename
T
>
...
@@ -96,14 +117,16 @@ class SequenceProjectFunctor {
...
@@ -96,14 +117,16 @@ class SequenceProjectFunctor {
sequence_height
=
static_cast
<
int
>
(
out_t
.
dims
()[
0
]);
sequence_height
=
static_cast
<
int
>
(
out_t
.
dims
()[
0
]);
std
::
vector
<
int64_t
>
output_shape
(
{
sequence_height
,
1
,
1
,
context_length
,
sequence_width
});
// output_height, output_width,
// input_channels, filter_height, filter_width
out_t
.
Resize
(
framework
::
make_ddim
(
output_shape
));
if
(
input_row_begin
<
input_row_end
)
{
if
(
input_row_begin
<
input_row_end
)
{
framework
::
Tensor
in_t
=
in
->
Slice
(
input_row_begin
,
input_row_end
);
framework
::
Tensor
in_t
=
in
->
Slice
(
input_row_begin
,
input_row_end
);
std
::
vector
<
int64_t
>
output_shape
(
{
sequence_height
,
1
,
1
,
context_length
,
sequence_width
});
// output_height, output_width,
// input_channels, filter_height, filter_width
out_t
.
Resize
(
framework
::
make_ddim
(
output_shape
));
std
::
vector
<
int64_t
>
input_shape
(
std
::
vector
<
int64_t
>
input_shape
(
{
1
,
input_row_end
-
input_row_begin
,
{
1
,
input_row_end
-
input_row_begin
,
sequence_width
});
// input_channels, input_height, input_width
sequence_width
});
// input_channels, input_height, input_width
...
...
paddle/operators/sequence_conv_op.cc
浏览文件 @
4c6bccbe
...
@@ -135,39 +135,18 @@ class SequenceConvOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -135,39 +135,18 @@ class SequenceConvOpMaker : public framework::OpProtoAndCheckerMaker {
.
GreaterThan
(
0
);
.
GreaterThan
(
0
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
SequenceConvOp projects features of context_length time-steps of each instance.
SequenceConvOp performs convolution operation on features of
context_length time-steps of each instance.
For a mini-batch of 2 variable lengths sentences, containing 3, and 1 time-steps:
The convolution operation calculates the output based on the input, filter
and strides, paddings parameters. The size of each dimension of the
Assumed input (X) is a [4, M, N] float LoDTensor, and X->lod()[0] = [0, 3, 4].
parameters is checked in the infer-shape.
Besides, for the sake of simplicity, we assume M=1 and N=2.
Example:
X = [[a1, a2;
Input:
b1, b2;
X shape: (minibatch, number_of_input_features)
c1, c2]
Filter shape: (context_length, number_of_input_features)
[d1, d2]]
Output:
Out shape: (minibatch, 1)
This is to say that input (X) has 4 words and the dimension of each word
representation is 2.
- Case1:
If context_start is -1 and padding_trainable is false, we use zero to pad instead of learned weight to pad,
and the context_lenth is 3, the output (Out) is:
Out =[[0, 0, a1, a2, b1, b2;
a1, a2, b1, b2, c1, c2;
b1, b2, c1, c2, 0, 0 ]
[0, 0, d1, d2, 0, 0 ]]
- Case2:
If context_start is -1 and padding_trainable is true, we use learned weight to pad,
and the context_lenth is 3, the output (Out) is:
Out = [[w1, w2, a1, a2, b1, b2;
a1, a2, b1, b2, c1, c2;
b1, b2, c1, c2, w3, w4]
[w1, w2, d1, d2, w3, w4]]
)DOC"
);
)DOC"
);
}
}
};
};
...
...
paddle/operators/sequence_conv_op.h
浏览文件 @
4c6bccbe
...
@@ -182,12 +182,6 @@ class SequenceConvGradKernel : public framework::OpKernel<T> {
...
@@ -182,12 +182,6 @@ class SequenceConvGradKernel : public framework::OpKernel<T> {
functor
(
context
.
device_context
(),
padding_data_g
,
0
);
functor
(
context
.
device_context
(),
padding_data_g
,
0
);
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
lod_g_level_0
.
size
())
-
1
;
++
i
)
{
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
lod_g_level_0
.
size
())
-
1
;
++
i
)
{
input_row_begin
=
(
context_start
>
0
)
?
static_cast
<
int
>
(
lod_g_level_0
[
i
])
+
context_start
:
static_cast
<
int
>
(
lod_g_level_0
[
i
]);
input_row_end
=
static_cast
<
int
>
(
lod_g_level_0
[
i
+
1
]);
Tensor
col_t
=
col
.
Slice
(
static_cast
<
int
>
(
lod_g_level_0
[
i
]),
Tensor
col_t
=
col
.
Slice
(
static_cast
<
int
>
(
lod_g_level_0
[
i
]),
static_cast
<
int
>
(
lod_g_level_0
[
i
+
1
]));
static_cast
<
int
>
(
lod_g_level_0
[
i
+
1
]));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录