Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
5aacd64b
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
12 个月 前同步成功
通知
692
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5aacd64b
编写于
9月 06, 2017
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Follow comments
上级
0c13660a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
21 addition
and
22 deletion
+21
-22
paddle/framework/eigen.h
paddle/framework/eigen.h
+2
-2
paddle/framework/eigen_test.cc
paddle/framework/eigen_test.cc
+1
-2
paddle/framework/tensor_test.cc
paddle/framework/tensor_test.cc
+1
-1
paddle/operators/mul_op.cc
paddle/operators/mul_op.cc
+13
-13
paddle/operators/mul_op.h
paddle/operators/mul_op.h
+4
-4
未找到文件。
paddle/framework/eigen.h
浏览文件 @
5aacd64b
...
...
@@ -87,11 +87,11 @@ template <typename T, int MajorType = Eigen::RowMajor,
struct
EigenVector
:
public
EigenTensor
<
T
,
1
,
MajorType
,
IndexType
>
{
// Flatten reshapes a Tensor into an EigenVector.
static
typename
EigenVector
::
Type
Flatten
(
Tensor
&
tensor
)
{
return
EigenVector
::
From
(
tensor
,
{
static_cast
<
int
>
(
product
(
tensor
.
dims_
)
)});
return
EigenVector
::
From
(
tensor
,
{
product
(
tensor
.
dims_
)});
}
static
typename
EigenVector
::
ConstType
Flatten
(
const
Tensor
&
tensor
)
{
return
EigenVector
::
From
(
tensor
,
{
static_cast
<
int
>
(
product
(
tensor
.
dims_
)
)});
return
EigenVector
::
From
(
tensor
,
{
product
(
tensor
.
dims_
)});
}
};
...
...
paddle/framework/eigen_test.cc
浏览文件 @
5aacd64b
...
...
@@ -110,8 +110,7 @@ TEST(Eigen, Matrix) {
TEST
(
Eigen
,
MatrixReshape
)
{
Tensor
t
;
float
*
p
=
t
.
mutable_data
<
float
>
(
make_ddim
({
2
,
3
,
6
,
4
}),
platform
::
CPUPlace
());
float
*
p
=
t
.
mutable_data
<
float
>
({
2
,
3
,
6
,
4
},
platform
::
CPUPlace
());
for
(
int
i
=
0
;
i
<
2
*
3
*
6
*
4
;
++
i
)
{
p
[
i
]
=
static_cast
<
float
>
(
i
);
}
...
...
paddle/framework/tensor_test.cc
浏览文件 @
5aacd64b
...
...
@@ -267,7 +267,7 @@ TEST(Tensor, ReshapeToMatrix) {
using
namespace
paddle
::
framework
;
using
namespace
paddle
::
platform
;
Tensor
src
;
int
*
src_ptr
=
src
.
mutable_data
<
int
>
(
make_ddim
({
2
,
3
,
4
,
9
})
,
CPUPlace
());
int
*
src_ptr
=
src
.
mutable_data
<
int
>
(
{
2
,
3
,
4
,
9
}
,
CPUPlace
());
for
(
int
i
=
0
;
i
<
2
*
3
*
4
*
9
;
++
i
)
{
src_ptr
[
i
]
=
i
;
}
...
...
paddle/operators/mul_op.cc
浏览文件 @
5aacd64b
...
...
@@ -27,8 +27,8 @@ class MulOp : public framework::OperatorWithKernel {
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
auto
x_dims
=
ctx
.
Input
<
Tensor
>
(
"X"
)
->
dims
();
auto
y_dims
=
ctx
.
Input
<
Tensor
>
(
"Y"
)
->
dims
();
int
x_num_col_dims
=
Get
Attr
<
int
>
(
"x_num_col_dims"
);
int
y_num_col_dims
=
Get
Attr
<
int
>
(
"y_num_col_dims"
);
int
x_num_col_dims
=
Attr
<
int
>
(
"x_num_col_dims"
);
int
y_num_col_dims
=
Attr
<
int
>
(
"y_num_col_dims"
);
PADDLE_ENFORCE
(
x_dims
.
size
()
>
x_num_col_dims
,
"The rank of input tensor X(%s) should be larger than "
...
...
@@ -58,19 +58,19 @@ class MulOpMaker : public framework::OpProtoAndCheckerMaker {
AddOutput
(
"Out"
,
"The output of mul op"
);
AddAttr
<
int
>
(
"x_num_col_dims"
,
"mul_op can take tensors with more than two dimensions as input `X`, "
"in that case, tensors will be reshaped to a matrix. The matrix's "
"first dimension(column length) will be the product of tensor's last "
"`num_col_dims` dimensions, and the matrix's second dimension(row "
"length) will be the product of tensor's first `rank - num_col_dims` "
"dimensions.
"
)
R"DOC(mul_op can take tensors with more than two dimensions as input `X`,
in that case, tensors will be reshaped to a matrix. The matrix's first
dimension(column length) will be the product of tensor's last
`num_col_dims` dimensions, and the matrix's second dimension(row length)
will be the product of tensor's first `rank - num_col_dims` dimensions.
)DOC
"
)
.
SetDefault
(
1
)
.
EqualLargerThan
(
1
);
AddAttr
<
int
>
(
"y_num_col_dims"
,
"mul_op can take tensors with more than two dimensions as input `Y`, "
"in that case, tensors will be reshaped to a matrix. Just like input "
"`X`.
"
)
R"DOC(mul_op can take tensors with more than two dimensions as input `Y`,
in that case, tensors will be reshaped to a matrix. Just like input `X`.
)DOC
"
)
.
SetDefault
(
1
)
.
EqualLargerThan
(
1
);
AddComment
(
R"DOC(
...
...
@@ -98,9 +98,9 @@ class MulOpGrad : public framework::OperatorWithKernel {
auto
*
y_grad
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Y"
));
auto
x_mat_dims
=
framework
::
flatten_to_2d
(
x_dims
,
Get
Attr
<
int
>
(
"x_num_col_dims"
));
framework
::
flatten_to_2d
(
x_dims
,
Attr
<
int
>
(
"x_num_col_dims"
));
auto
y_mat_dims
=
framework
::
flatten_to_2d
(
y_dims
,
Get
Attr
<
int
>
(
"y_num_col_dims"
));
framework
::
flatten_to_2d
(
y_dims
,
Attr
<
int
>
(
"y_num_col_dims"
));
PADDLE_ENFORCE_EQ
(
x_mat_dims
[
0
],
out_dims
[
0
],
...
...
paddle/operators/mul_op.h
浏览文件 @
5aacd64b
...
...
@@ -37,12 +37,12 @@ class MulKernel : public framework::OpKernel {
const
Tensor
x_matrix
=
x
->
dims
().
size
()
>
2
?
framework
::
ReshapeToMatrix
<
T
>
(
*
x
,
context
.
template
Get
Attr
<
int
>(
"x_num_col_dims"
))
*
x
,
context
.
template
Attr
<
int
>(
"x_num_col_dims"
))
:
*
x
;
const
Tensor
y_matrix
=
y
->
dims
().
size
()
>
2
?
framework
::
ReshapeToMatrix
<
T
>
(
*
y
,
context
.
template
Get
Attr
<
int
>(
"y_num_col_dims"
))
*
y
,
context
.
template
Attr
<
int
>(
"y_num_col_dims"
))
:
*
y
;
z
->
mutable_data
<
T
>
(
context
.
GetPlace
());
...
...
@@ -57,8 +57,8 @@ template <typename Place, typename T>
class
MulGradKernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
int
x_num_col_dims
=
ctx
.
template
Get
Attr
<
int
>(
"x_num_col_dims"
);
int
y_num_col_dims
=
ctx
.
template
Get
Attr
<
int
>(
"y_num_col_dims"
);
int
x_num_col_dims
=
ctx
.
template
Attr
<
int
>(
"x_num_col_dims"
);
int
y_num_col_dims
=
ctx
.
template
Attr
<
int
>(
"y_num_col_dims"
);
const
Tensor
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
const
Tensor
*
y
=
ctx
.
Input
<
Tensor
>
(
"Y"
);
const
Tensor
x_matrix
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录