Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
cf07f3e1
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
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看板
未验证
提交
cf07f3e1
编写于
11月 14, 2017
作者:
H
helinwang
提交者:
GitHub
11月 14, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5565 from dzhwinter/fix/reduce_op
Fix/reduce op
上级
2d7ac80b
60232d81
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
19 addition
and
7 deletion
+19
-7
paddle/operators/reduce_op.h
paddle/operators/reduce_op.h
+19
-7
未找到文件。
paddle/operators/reduce_op.h
浏览文件 @
cf07f3e1
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#pragma once
#pragma once
#include "glog/logging.h"
#include "paddle/framework/eigen.h"
#include "paddle/framework/eigen.h"
#include "paddle/framework/op_registry.h"
#include "paddle/framework/op_registry.h"
...
@@ -26,6 +27,10 @@ template <typename T, size_t D, int MajorType = Eigen::RowMajor,
...
@@ -26,6 +27,10 @@ template <typename T, size_t D, int MajorType = Eigen::RowMajor,
typename
IndexType
=
Eigen
::
DenseIndex
>
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenTensor
=
framework
::
EigenTensor
<
T
,
D
,
MajorType
,
IndexType
>
;
using
EigenTensor
=
framework
::
EigenTensor
<
T
,
D
,
MajorType
,
IndexType
>
;
template
<
typename
T
,
int
MajorType
=
Eigen
::
RowMajor
,
typename
IndexType
=
Eigen
::
DenseIndex
>
using
EigenScalar
=
framework
::
EigenScalar
<
T
,
MajorType
,
IndexType
>
;
struct
SumFunctor
{
struct
SumFunctor
{
template
<
typename
Place
,
typename
X
,
typename
Y
,
typename
Dim
>
template
<
typename
Place
,
typename
X
,
typename
Y
,
typename
Dim
>
void
operator
()(
const
Place
&
place
,
X
&
x
,
Y
&
y
,
const
Dim
&
dim
)
{
void
operator
()(
const
Place
&
place
,
X
&
x
,
Y
&
y
,
const
Dim
&
dim
)
{
...
@@ -133,11 +138,18 @@ class ReduceKernel : public framework::OpKernel<T> {
...
@@ -133,11 +138,18 @@ class ReduceKernel : public framework::OpKernel<T> {
dims_vector
.
erase
(
dims_vector
.
begin
()
+
dim
);
dims_vector
.
erase
(
dims_vector
.
begin
()
+
dim
);
dims
=
framework
::
make_ddim
(
dims_vector
);
dims
=
framework
::
make_ddim
(
dims_vector
);
}
}
auto
out
=
EigenTensor
<
T
,
D
==
1
?
1
:
(
D
-
1
)
>
::
From
(
*
output
,
dims
);
auto
&
place
=
context
.
GetEigenDevice
<
Place
>
();
auto
&
place
=
context
.
GetEigenDevice
<
Place
>
();
Functor
functor
;
Functor
functor
;
if
(
D
==
1
)
{
auto
out
=
EigenScalar
<
T
>::
From
(
*
output
);
functor
(
place
,
x
,
out
,
reduce_dim
);
}
else
{
auto
out
=
EigenTensor
<
T
,
(
D
-
1
)
>::
From
(
*
output
,
dims
);
functor
(
place
,
x
,
out
,
reduce_dim
);
functor
(
place
,
x
,
out
,
reduce_dim
);
}
}
}
};
};
template
<
typename
Place
,
typename
T
,
typename
Functor
>
template
<
typename
Place
,
typename
T
,
typename
Functor
>
...
@@ -186,13 +198,13 @@ class ReduceGradKernel : public framework::OpKernel<T> {
...
@@ -186,13 +198,13 @@ class ReduceGradKernel : public framework::OpKernel<T> {
auto
x_reduce
=
EigenTensor
<
T
,
D
>::
From
(
*
input1
,
dims
);
auto
x_reduce
=
EigenTensor
<
T
,
D
>::
From
(
*
input1
,
dims
);
auto
x_reduce_grad
=
EigenTensor
<
T
,
D
>::
From
(
*
input2
,
dims
);
auto
x_reduce_grad
=
EigenTensor
<
T
,
D
>::
From
(
*
input2
,
dims
);
Eigen
::
array
<
int
,
D
>
br
ao
dcast_dim
;
Eigen
::
array
<
int
,
D
>
br
oa
dcast_dim
;
for
(
size_t
i
=
0
;
i
<
D
;
++
i
)
br
ao
dcast_dim
[
i
]
=
1
;
for
(
size_t
i
=
0
;
i
<
D
;
++
i
)
br
oa
dcast_dim
[
i
]
=
1
;
br
ao
dcast_dim
[
dim
]
=
input0
->
dims
()[
dim
];
br
oa
dcast_dim
[
dim
]
=
input0
->
dims
()[
dim
];
auto
&
place
=
context
.
GetEigenDevice
<
Place
>
();
auto
&
place
=
context
.
GetEigenDevice
<
Place
>
();
Functor
functor
;
Functor
functor
;
functor
(
place
,
x
,
x_reduce
,
x_grad
,
x_reduce_grad
,
br
ao
dcast_dim
,
functor
(
place
,
x
,
x_reduce
,
x_grad
,
x_reduce_grad
,
br
oa
dcast_dim
,
br
ao
dcast_dim
[
dim
]);
br
oa
dcast_dim
[
dim
]);
}
}
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录