Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
578d60bf
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
578d60bf
编写于
1月 18, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code refine
上级
2edc136c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
18 addition
and
25 deletion
+18
-25
paddle/operators/math/matmul.h
paddle/operators/math/matmul.h
+5
-9
paddle/operators/matmul_op.cc
paddle/operators/matmul_op.cc
+5
-10
paddle/operators/matmul_op.h
paddle/operators/matmul_op.h
+8
-6
未找到文件。
paddle/operators/math/matmul.h
浏览文件 @
578d60bf
...
...
@@ -41,22 +41,18 @@ class MatMulFunctor {
"Input tensor a must be at least 1-dimensional."
);
PADDLE_ENFORCE_GE
(
dim_b
.
size
(),
1
,
"Input tensor b must be at least 1-dimensional."
);
PADDLE_ENFORCE_LE
(
dim_a
.
size
(),
4
,
"Input tensor a must be at most 4-dimensional."
);
PADDLE_ENFORCE_LE
(
dim_b
.
size
(),
4
,
"Input tensor b must be at most 4-dimensional."
);
std
::
vector
<
int64_t
>
out_dim
;
int64_t
batch_count
=
1
;
if
(
dim_a
.
size
()
>
3
)
{
PADDLE_ENFORCE
(
dim_b
.
size
()
>
3
,
"The dimensions of X and Y must be the same, and both of "
"them should be 4-dimensional."
);
"them should be %d-dimensional."
,
dim_b
.
size
());
for
(
int
j
=
0
;
j
<
dim_a
.
size
()
-
2
;
++
j
)
{
PADDLE_ENFORCE
(
dim_b
[
j
]
==
dim_a
[
j
],
"The dimensions of X and Y must be the same, and both of "
"them should be 4-dimensional."
);
PADDLE_ENFORCE
(
dim_b
[
j
]
==
dim_a
[
j
],
"The dimensions of X[%d] and Y[%d] must be the same."
,
j
,
j
);
out_dim
.
push_back
(
dim_a
[
j
]);
batch_count
*=
dim_a
[
j
];
}
...
...
paddle/operators/matmul_op.cc
浏览文件 @
578d60bf
...
...
@@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/operators/matmul_op.h"
#include <vector>
namespace
paddle
{
namespace
operators
{
...
...
@@ -42,22 +41,18 @@ class MatMulOp : public framework::OperatorWithKernel {
"Input tensor X must be at least 1-dimensional."
);
PADDLE_ENFORCE_GE
(
dim_y
.
size
(),
1
,
"Input tensor Y must be at least 1-dimensional."
);
PADDLE_ENFORCE_LE
(
dim_x
.
size
(),
4
,
"Input tensor X must be at most 4-dimensional."
);
PADDLE_ENFORCE_LE
(
dim_y
.
size
(),
4
,
"Input tensor Y must be at most 4-dimensional."
);
std
::
vector
<
int64_t
>
out_dim
;
int64_t
batch_count
=
1
;
if
(
dim_x
.
size
()
>
3
)
{
PADDLE_ENFORCE
(
dim_y
.
size
()
==
dim_x
.
size
(),
"The dimensions of X and Y must be the same, and both of "
"them should be 4-dimensional."
);
"them should be %d-dimensional."
,
dim_x
.
size
());
for
(
int
j
=
0
;
j
<
dim_x
.
size
()
-
2
;
++
j
)
{
PADDLE_ENFORCE
(
dim_y
[
j
]
==
dim_x
[
j
],
"The dimensions of X and Y must be the same, and both of "
"them should be 4-dimensional."
);
PADDLE_ENFORCE
(
dim_y
[
j
]
==
dim_x
[
j
],
"The dimensions of X[%d] and Y[%d] must be the same."
,
j
,
j
);
out_dim
.
push_back
(
dim_x
[
j
]);
batch_count
*=
dim_x
[
j
];
}
...
...
paddle/operators/matmul_op.h
浏览文件 @
578d60bf
...
...
@@ -137,6 +137,12 @@ class MatMulGradKernel : public framework::OpKernel<T> {
y_dims
.
push_back
(
1
);
}
int
batch_count
=
0
;
//
if
(
x_dims
.
size
()
>
3
)
{
batch_count
=
accumulate
(
x_dims
.
begin
(),
x_dims
.
end
()
-
2
,
1
,
std
::
multiplies
<
int
>
());
}
// Fix the dOut dimensions.
int
M
=
0
,
N
=
0
,
batchCountX
=
0
,
batchCountY
=
0
;
...
...
@@ -149,8 +155,7 @@ class MatMulGradKernel : public framework::OpKernel<T> {
M
=
transpose_x
?
x_dims
[
2
]
:
x_dims
[
1
];
break
;
default:
batchCountX
=
accumulate
(
x_dims
.
begin
(),
x_dims
.
end
()
-
2
,
1
,
std
::
multiplies
<
int
>
());
batchCountX
=
batch_count
;
size_t
mat_s
=
x_dims
.
size
()
-
2
;
M
=
transpose_x
?
x_dims
[
mat_s
+
1
]
:
x_dims
[
mat_s
];
}
...
...
@@ -164,8 +169,7 @@ class MatMulGradKernel : public framework::OpKernel<T> {
N
=
transpose_y
?
y_dims
[
1
]
:
y_dims
[
2
];
break
;
default:
batchCountY
=
accumulate
(
y_dims
.
begin
(),
y_dims
.
end
()
-
2
,
1
,
std
::
multiplies
<
int
>
());
batchCountY
=
batch_count
;
size_t
mat_s
=
y_dims
.
size
()
-
2
;
N
=
transpose_y
?
y_dims
[
mat_s
]
:
y_dims
[
mat_s
+
1
];
}
...
...
@@ -180,8 +184,6 @@ class MatMulGradKernel : public framework::OpKernel<T> {
if
(
batchCount
)
{
if
(
x_dims
.
size
()
>
3
)
{
dout_dims
.
insert
(
dout_dims
.
begin
(),
x_dims
.
begin
(),
x_dims
.
end
()
-
2
);
}
else
if
(
y_dims
.
size
()
>
3
)
{
dout_dims
.
insert
(
dout_dims
.
begin
(),
y_dims
.
begin
(),
y_dims
.
end
()
-
2
);
}
else
{
dout_dims
.
insert
(
dout_dims
.
begin
(),
batchCount
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录