Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
96212132
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
96212132
编写于
10月 18, 2017
作者:
X
xzl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add max-pool-with-mask c++ impl
上级
720274da
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
78 addition
and
5 deletion
+78
-5
paddle/gserver/layers/PoolLayer.cpp
paddle/gserver/layers/PoolLayer.cpp
+7
-2
paddle/gserver/layers/PoolLayer.h
paddle/gserver/layers/PoolLayer.h
+2
-0
paddle/gserver/layers/PoolProjection.cpp
paddle/gserver/layers/PoolProjection.cpp
+35
-1
paddle/gserver/layers/PoolProjection.h
paddle/gserver/layers/PoolProjection.h
+12
-1
paddle/gserver/layers/PoolProjectionLayer.cpp
paddle/gserver/layers/PoolProjectionLayer.cpp
+9
-1
paddle/gserver/layers/Projection.h
paddle/gserver/layers/Projection.h
+13
-0
未找到文件。
paddle/gserver/layers/PoolLayer.cpp
浏览文件 @
96212132
...
...
@@ -44,14 +44,19 @@ bool PoolLayer::init(const LayerMap& layerMap,
strideY_
=
conf
.
has_stride_y
()
?
conf
.
stride_y
()
:
conf
.
stride
();
confPaddingY_
=
conf
.
has_padding_y
()
?
conf
.
padding_y
()
:
conf
.
padding
();
outputY_
=
conf
.
has_output_y
()
?
conf
.
output_y
()
:
conf
.
output_x
();
with_mask_
=
false
;
if
(
poolType_
==
"max-pool-with-mask"
)
{
setOutput
(
"mask"
,
&
mask_
);
with_mask_
=
true
;
}
return
true
;
}
Layer
*
PoolLayer
::
create
(
const
LayerConfig
&
config
)
{
CHECK_EQ
(
config
.
inputs_size
(),
1
);
const
std
::
string
&
pool
=
config
.
inputs
(
0
).
pool_conf
().
pool_type
();
if
(
pool
==
"max-projection"
||
pool
==
"avg-projection"
)
{
if
(
pool
==
"max-projection"
||
pool
==
"avg-projection"
||
pool
==
"max-pool-with-mask"
)
{
return
new
PoolProjectionLayer
(
config
);
#ifdef PADDLE_WITH_CUDA
}
else
if
(
CudnnPoolLayer
::
typeCheck
(
pool
))
{
...
...
paddle/gserver/layers/PoolLayer.h
浏览文件 @
96212132
...
...
@@ -37,6 +37,8 @@ protected:
int
confPaddingY_
;
std
::
string
poolType_
;
bool
with_mask_
;
Argument
mask_
;
public:
explicit
PoolLayer
(
const
LayerConfig
&
config
)
:
Layer
(
config
)
{}
...
...
paddle/gserver/layers/PoolProjection.cpp
浏览文件 @
96212132
...
...
@@ -36,6 +36,10 @@ PoolProjection::PoolProjection(const ProjectionConfig& config,
strideY_
=
conf
.
has_stride_y
()
?
conf
.
stride_y
()
:
conf
.
stride
();
confPaddingY_
=
conf
.
has_padding_y
()
?
conf
.
padding_y
()
:
conf
.
padding
();
outputY_
=
conf
.
has_output_y
()
?
conf
.
output_y
()
:
conf
.
output_x
();
with_mask_
=
false
;
if
(
poolType_
==
"max-pool-with-mask"
)
{
with_mask_
=
true
;
}
}
size_t
PoolProjection
::
getSize
()
{
...
...
@@ -73,6 +77,8 @@ PoolProjection* PoolProjection::create(const ProjectionConfig& config,
return
new
MaxPoolProjection
(
config
,
parameter
,
useGpu
);
}
else
if
(
pool
==
"avg-projection"
)
{
return
new
AvgPoolProjection
(
config
,
parameter
,
useGpu
);
}
else
if
(
pool
==
"max-pool-with-mask"
)
{
return
new
MaxPoolProjection
(
config
,
parameter
,
useGpu
);
}
else
{
LOG
(
FATAL
)
<<
"Unknown pool type: "
<<
pool
;
return
nullptr
;
...
...
@@ -84,6 +90,10 @@ void MaxPoolProjection::forward() {
CHECK_EQ
(
width
,
out_
->
value
->
getWidth
());
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
MatrixPtr
maskV
=
out_
->
value
;
if
(
with_mask_
)
{
maskV
=
mask_
->
value
;
}
outV
->
maxPoolForward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
...
...
@@ -95,7 +105,9 @@ void MaxPoolProjection::forward() {
outputY_
,
outputX_
,
confPaddingY_
,
confPadding_
);
confPadding_
,
maskV
,
with_mask_
);
}
void
MaxPoolProjection
::
backward
(
const
UpdateCallback
&
callback
)
{
...
...
@@ -168,4 +180,26 @@ void AvgPoolProjection::backward(const UpdateCallback& callback) {
confPaddingY_
,
confPadding_
);
}
void
MaxWithMaskPoolProjection
::
forward
()
{
size_t
width
=
getSize
();
CHECK_EQ
(
width
,
out_
->
value
->
getWidth
());
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
MatrixPtr
maskV
=
mask_
->
value
;
outV
->
maxPoolForward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
channels_
,
sizeX_
,
sizeY_
,
strideY_
,
stride_
,
outputY_
,
outputX_
,
confPaddingY_
,
confPadding_
,
maskV
,
with_mask_
);
}
}
// namespace paddle
paddle/gserver/layers/PoolProjection.h
浏览文件 @
96212132
...
...
@@ -28,6 +28,7 @@ protected:
int
confPaddingY_
,
confPadding_
;
size_t
channels_
;
std
::
string
poolType_
;
bool
with_mask_
;
public:
PoolProjection
(
const
ProjectionConfig
&
config
,
...
...
@@ -37,7 +38,6 @@ public:
static
PoolProjection
*
create
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
);
const
std
::
string
&
getPoolType
()
const
{
return
poolType_
;
}
size_t
getSize
();
...
...
@@ -64,4 +64,15 @@ public:
virtual
void
forward
();
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
};
class
MaxWithMaskPoolProjection
:
public
MaxPoolProjection
{
public:
MaxWithMaskPoolProjection
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
)
:
MaxPoolProjection
(
config
,
parameter
,
useGpu
)
{}
virtual
void
forward
();
};
}
// namespace paddle
paddle/gserver/layers/PoolProjectionLayer.cpp
浏览文件 @
96212132
...
...
@@ -51,8 +51,16 @@ void PoolProjectionLayer::forward(PassType passType) {
const
Argument
&
in
=
getInput
(
0
);
int
batchSize
=
in
.
value
->
getHeight
();
int
size
=
getSize
();
if
(
with_mask_
)
{
resetSpecifyOutput
(
mask_
,
batchSize
,
size
,
/* isValueClean */
false
,
/* isGradClean */
true
);
}
resetOutput
(
batchSize
,
size
);
poolProjection_
->
forward
(
&
in
,
&
output_
,
passType
);
poolProjection_
->
forward
(
&
in
,
&
output_
,
&
mask_
,
passType
);
}
void
PoolProjectionLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
...
...
paddle/gserver/layers/Projection.h
浏览文件 @
96212132
...
...
@@ -69,6 +69,17 @@ public:
forward
();
}
void
forward
(
const
Argument
*
in
,
const
Argument
*
out
,
const
Argument
*
mask
,
PassType
passType
)
{
in_
=
in
;
out_
=
out
;
mask_
=
mask
;
passType_
=
passType
;
forward
();
}
virtual
void
prefetch
(
const
Argument
*
in
)
{}
virtual
void
forward
()
=
0
;
virtual
void
backward
(
const
UpdateCallback
&
callback
)
=
0
;
...
...
@@ -130,6 +141,8 @@ protected:
const
Argument
*
in_
;
/// Store `out` passed to forward()
const
Argument
*
out_
;
/// Store `mask` passed to forward()
const
Argument
*
mask_
;
/// Store `passType` passed to forward()
PassType
passType_
;
/// Layer forward function
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录