Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
8d9babf2
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
8d9babf2
编写于
11月 15, 2017
作者:
W
wanghaox
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
maxout code review 2nd
上级
f319fb1c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
14 addition
and
17 deletion
+14
-17
paddle/operators/math/maxouting.cc
paddle/operators/math/maxouting.cc
+5
-5
paddle/operators/math/maxouting.cu
paddle/operators/math/maxouting.cu
+6
-5
paddle/operators/maxout_op.h
paddle/operators/maxout_op.h
+3
-5
python/paddle/v2/framework/tests/test_maxout_op.py
python/paddle/v2/framework/tests/test_maxout_op.py
+0
-2
未找到文件。
paddle/operators/math/maxouting.cc
浏览文件 @
8d9babf2
...
@@ -42,11 +42,11 @@ class MaxOutFunctor<platform::CPUPlace, MaxOutProcess, T> {
...
@@ -42,11 +42,11 @@ class MaxOutFunctor<platform::CPUPlace, MaxOutProcess, T> {
const
T
*
input_data
=
input
.
data
<
T
>
();
const
T
*
input_data
=
input
.
data
<
T
>
();
T
*
output_data
=
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
output_data
=
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
for
(
int
i
=
0
;
i
<
batch_size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
int
new_bindex
=
c_size
*
i
;
int
new_bindex
=
c_size
*
i
;
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
int
new_cindex
=
fea_size
*
c
;
int
new_cindex
=
fea_size
*
c
;
for
(
int
f
=
0
;
f
<
fea_size
;
f
++
)
{
for
(
int
f
=
0
;
f
<
fea_size
;
++
f
)
{
T
ele
=
maxout_process
.
initial
();
T
ele
=
maxout_process
.
initial
();
for
(
int
ph
=
0
;
ph
<
groups
;
++
ph
)
{
for
(
int
ph
=
0
;
ph
<
groups
;
++
ph
)
{
maxout_process
.
compute
(
ele
,
maxout_process
.
compute
(
ele
,
...
@@ -82,15 +82,15 @@ public:
...
@@ -82,15 +82,15 @@ public:
const
T
*
output_grad_data
=
output_grad
.
data
<
T
>
();
const
T
*
output_grad_data
=
output_grad
.
data
<
T
>
();
T
*
input_grad_data
=
input_grad
.
mutable_data
<
T
>
(
context
.
GetPlace
());
T
*
input_grad_data
=
input_grad
.
mutable_data
<
T
>
(
context
.
GetPlace
());
for
(
int
i
=
0
;
i
<
batch_size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
batch_size
;
++
i
)
{
int
blen
=
fea_size
*
output_channels
*
i
;
int
blen
=
fea_size
*
output_channels
*
i
;
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
for
(
int
c
=
0
;
c
<
output_channels
;
++
c
)
{
int
clen
=
fea_size
*
c
;
int
clen
=
fea_size
*
c
;
for
(
int
f
=
0
;
f
<
fea_size
;
f
++
)
{
for
(
int
f
=
0
;
f
<
fea_size
;
++
f
)
{
int
input_idx
=
0
;
int
input_idx
=
0
;
bool
stop
=
false
;
bool
stop
=
false
;
int
output_idx
=
blen
+
clen
+
f
;
int
output_idx
=
blen
+
clen
+
f
;
for
(
int
g
=
0
;
g
<
groups
&&
!
stop
;
g
++
)
{
for
(
int
g
=
0
;
g
<
groups
&&
!
stop
;
++
g
)
{
input_idx
=
(
blen
+
clen
)
*
groups
+
fea_size
*
g
+
f
;
input_idx
=
(
blen
+
clen
)
*
groups
+
fea_size
*
g
+
f
;
input_grad_data
[
input_idx
]
=
0
;
input_grad_data
[
input_idx
]
=
0
;
if
(
input_data
[
input_idx
]
==
output_data
[
output_idx
])
{
if
(
input_data
[
input_idx
]
==
output_data
[
output_idx
])
{
...
...
paddle/operators/math/maxouting.cu
浏览文件 @
8d9babf2
...
@@ -21,9 +21,10 @@ namespace math {
...
@@ -21,9 +21,10 @@ namespace math {
template
<
typename
MaxOutProcess
,
typename
T
>
template
<
typename
MaxOutProcess
,
typename
T
>
__global__
void
KernelMaxOut
(
const
int
nthreads
,
const
T
*
input_data
,
__global__
void
KernelMaxOut
(
const
int
nthreads
,
const
T
*
input_data
,
T
*
output_data
,
const
int
channels
,
const
int
channels
,
const
int
input_height
,
const
int
input_width
,
const
int
input_height
,
const
int
input_width
,
int
groups
,
MaxOutProcess
maxout_process
)
{
int
groups
,
T
*
output_data
,
MaxOutProcess
maxout_process
)
{
const
int
size
=
input_height
*
input_width
*
channels
/
groups
;
const
int
size
=
input_height
*
input_width
*
channels
/
groups
;
const
int
feat_len
=
input_height
*
input_width
;
const
int
feat_len
=
input_height
*
input_width
;
for
(
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
index
<
nthreads
;
for
(
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
index
<
nthreads
;
...
@@ -58,7 +59,7 @@ __global__ void KernelMaxoutGrad(
...
@@ -58,7 +59,7 @@ __global__ void KernelMaxoutGrad(
(
batch_idx
*
size
+
channel_idx
*
feat_len
)
*
groups
+
feat_idx
;
(
batch_idx
*
size
+
channel_idx
*
feat_len
)
*
groups
+
feat_idx
;
int
maxIndex
=
-
1
;
int
maxIndex
=
-
1
;
bool
stop
=
false
;
bool
stop
=
false
;
for
(
int
g
=
0
;
g
<
groups
&&
!
stop
;
g
++
)
{
for
(
int
g
=
0
;
g
<
groups
&&
!
stop
;
++
g
)
{
if
(
input_data
[
data_idx
+
g
*
feat_len
]
==
output_data
[
index
])
{
if
(
input_data
[
data_idx
+
g
*
feat_len
]
==
output_data
[
index
])
{
maxIndex
=
data_idx
+
g
*
feat_len
;
maxIndex
=
data_idx
+
g
*
feat_len
;
stop
=
true
;
stop
=
true
;
...
@@ -99,9 +100,9 @@ class MaxOutFunctor<platform::GPUPlace, MaxOutProcess, T> {
...
@@ -99,9 +100,9 @@ class MaxOutFunctor<platform::GPUPlace, MaxOutProcess, T> {
MaxOutProcess
,
MaxOutProcess
,
T
><<<
grid
,
threads
,
0
,
T
><<<
grid
,
threads
,
0
,
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
reinterpret_cast
<
const
platform
::
CUDADeviceContext
&>
(
context
)
.
stream
()
>>>
(
nthreads
,
input_data
,
output_data
,
input_channels
,
.
stream
()
>>>
(
nthreads
,
input_data
,
input_channels
,
input_height
,
input_width
,
groups
,
input_height
,
input_width
,
groups
,
maxout_process
);
output_data
,
maxout_process
);
}
}
};
};
/*
/*
...
...
paddle/operators/maxout_op.h
浏览文件 @
8d9babf2
...
@@ -54,13 +54,11 @@ class MaxOutGradKernel : public framework::OpKernel<T> {
...
@@ -54,13 +54,11 @@ class MaxOutGradKernel : public framework::OpKernel<T> {
int
groups
=
context
.
template
Attr
<
int
>(
"groups"
);
int
groups
=
context
.
template
Attr
<
int
>(
"groups"
);
auto
&
device_ctx
=
context
.
device_context
();
math
::
SetConstant
<
Place
,
T
>
zero
;
if
(
in_x_grad
)
{
if
(
in_x_grad
)
{
in_x_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
in_x_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
temp
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
in_x_grad
);
zero
(
device_ctx
,
in_x_grad
,
static_cast
<
T
>
(
0.0
));
temp
.
device
(
context
.
GetEigenDevice
<
Place
>
())
=
temp
.
constant
(
static_cast
<
T
>
(
0
));
paddle
::
operators
::
math
::
MaxOutGradFunctor
<
Place
,
T
>
paddle
::
operators
::
math
::
MaxOutGradFunctor
<
Place
,
T
>
maxout_backward
;
maxout_backward
;
...
...
python/paddle/v2/framework/tests/test_maxout_op.py
浏览文件 @
8d9babf2
...
@@ -26,8 +26,6 @@ class TestMaxOutOp(OpTest):
...
@@ -26,8 +26,6 @@ class TestMaxOutOp(OpTest):
self
.
check_output
()
self
.
check_output
()
def
test_check_grad
(
self
):
def
test_check_grad
(
self
):
print
self
.
inputs
print
self
.
outputs
self
.
check_grad
([
'X'
],
'Out'
)
self
.
check_grad
([
'X'
],
'Out'
)
def
init_test_case
(
self
):
def
init_test_case
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录