Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夏有凉风,冬有雪
Paddle
提交
fcf177fc
P
Paddle
项目概览
夏有凉风,冬有雪
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fcf177fc
编写于
11月 02, 2016
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reuse code of PoolProjection in PoolProjectionLayer
上级
cdac60f6
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
25 addition
and
94 deletion
+25
-94
paddle/gserver/layers/PoolLayer.cpp
paddle/gserver/layers/PoolLayer.cpp
+2
-4
paddle/gserver/layers/PoolProjection.cpp
paddle/gserver/layers/PoolProjection.cpp
+2
-2
paddle/gserver/layers/PoolProjectionLayer.cpp
paddle/gserver/layers/PoolProjectionLayer.cpp
+7
-57
paddle/gserver/layers/PoolProjectionLayer.h
paddle/gserver/layers/PoolProjectionLayer.h
+10
-25
paddle/gserver/tests/test_LayerGrad.cpp
paddle/gserver/tests/test_LayerGrad.cpp
+4
-6
未找到文件。
paddle/gserver/layers/PoolLayer.cpp
浏览文件 @
fcf177fc
...
...
@@ -52,10 +52,8 @@ bool PoolLayer::init(const LayerMap& layerMap,
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"
)
{
return
new
MaxPoolProjectionLayer
(
config
);
}
else
if
(
pool
==
"avg-projection"
)
{
return
new
AvgPoolProjectionLayer
(
config
);
if
(
pool
==
"max-projection"
||
pool
==
"avg-projection"
)
{
return
new
PoolProjectionLayer
(
config
);
#ifndef PADDLE_ONLY_CPU
}
else
if
(
CudnnPoolLayer
::
typeCheck
(
pool
))
{
return
new
CudnnPoolLayer
(
config
);
...
...
paddle/gserver/layers/PoolProjection.cpp
浏览文件 @
fcf177fc
...
...
@@ -21,9 +21,9 @@ REGISTER_PROJECTION_CREATE_FUNC(pool2, &PoolProjection::create);
PoolProjection
*
PoolProjection
::
create
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
)
{
const
std
::
string
&
pool
=
config
.
pool_conf
().
pool_type
();
if
(
pool
==
"max"
)
{
if
(
pool
==
"max
-projection
"
)
{
return
new
MaxPoolProjection
(
config
,
parameter
,
useGpu
);
}
else
if
(
pool
==
"avg"
)
{
}
else
if
(
pool
==
"avg
-projection
"
)
{
return
new
AvgPoolProjection
(
config
,
parameter
,
useGpu
);
}
else
{
LOG
(
FATAL
)
<<
"Unknown pool type: "
<<
pool
;
...
...
paddle/gserver/layers/PoolProjectionLayer.cpp
浏览文件 @
fcf177fc
...
...
@@ -19,6 +19,7 @@ limitations under the License. */
namespace
paddle
{
size_t
PoolProjectionLayer
::
getSize
()
{
CHECK_EQ
(
inputLayers_
.
size
(),
1UL
);
size_t
layerSize
=
0
;
...
...
@@ -41,71 +42,20 @@ size_t PoolProjectionLayer::getSize() {
return
layerSize
;
}
void
MaxPoolProjectionLayer
::
forward
(
PassType
passType
)
{
Layer
::
forward
(
passType
);
/* malloc memory for the output_ if necessary */
/* note: one sample correspond to one ROW */
MatrixPtr
input
=
getInputValue
(
0
);
int
batchSize
=
input
->
getHeight
();
int
size
=
getSize
();
resetOutput
(
batchSize
,
size
);
MatrixPtr
outV
=
getOutputValue
();
outV
->
maxPoolForward
(
*
input
,
imgSizeH_
,
imgSizeW_
,
channels_
,
sizeX_
,
sizeY_
,
strideY_
,
stride_
,
outputH_
,
outputW_
,
confPaddingY_
,
confPadding_
);
}
void
MaxPoolProjectionLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
(
void
)
callback
;
if
(
NULL
==
getInputGrad
(
0
))
{
return
;
}
/* Do derivation */
MatrixPtr
outGrad
=
getOutputGrad
();
MatrixPtr
inputV
=
getInputValue
(
0
);
MatrixPtr
outV
=
getOutputValue
();
MatrixPtr
inputGrad
=
getInputGrad
(
0
);
inputGrad
->
maxPoolBackward
(
*
inputV
,
imgSizeH_
,
imgSizeW_
,
*
outGrad
,
*
outV
,
sizeX_
,
sizeY_
,
strideY_
,
stride_
,
outputH_
,
outputW_
,
1
,
1
,
confPaddingY_
,
confPadding_
);
}
void
AvgPoolProjectionLayer
::
forward
(
PassType
passType
)
{
void
PoolProjectionLayer
::
forward
(
PassType
passType
)
{
Layer
::
forward
(
passType
);
/* malloc memory for the output_ if necessary */
/* note: one sample correspond to one ROW */
MatrixPtr
input
=
getInputValue
(
0
);
int
batchSize
=
input
->
getHeight
();
const
Argument
&
in
=
getInput
(
0
);
int
batchSize
=
in
.
value
->
getHeight
();
int
size
=
getSize
();
resetOutput
(
batchSize
,
size
);
MatrixPtr
outV
=
getOutputValue
();
outV
->
avgPoolForward
(
*
input
,
imgSizeH_
,
imgSizeW_
,
channels_
,
sizeX_
,
sizeY_
,
strideY_
,
stride_
,
outputH_
,
outputW_
,
confPaddingY_
,
confPadding_
);
poolProjection_
->
forward
(
&
in
,
&
output_
,
passType
);
}
void
Avg
PoolProjectionLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
void
PoolProjectionLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
(
void
)
callback
;
if
(
NULL
==
getInputGrad
(
0
))
{
return
;
}
/* Do derivation */
MatrixPtr
outputGrad
=
getOutputGrad
();
MatrixPtr
inputGrad
=
getInputGrad
(
0
);
inputGrad
->
avgPoolBackward
(
*
outputGrad
,
imgSizeH_
,
imgSizeW_
,
sizeX_
,
sizeY_
,
strideY_
,
stride_
,
outputH_
,
outputW_
,
1
,
1
,
confPaddingY_
,
confPadding_
);
poolProjection_
->
backward
(
callback
);
}
}
// namespace paddle
paddle/gserver/layers/PoolProjectionLayer.h
浏览文件 @
fcf177fc
...
...
@@ -16,6 +16,7 @@ limitations under the License. */
#pragma once
#include "PoolLayer.h"
#include "PoolProjection.h"
#include "paddle/math/Matrix.h"
#include <vector>
...
...
@@ -27,35 +28,19 @@ class PoolProjectionLayer : public PoolLayer {
protected:
size_t
imgSizeH_
,
imgSizeW_
;
size_t
outputH_
,
outputW_
;
std
::
unique_ptr
<
PoolProjection
>
poolProjection_
;
ProjectionConfig
projectionConfig_
;
public:
size_t
getSize
();
explicit
PoolProjectionLayer
(
const
LayerConfig
&
config
)
:
PoolLayer
(
config
)
{}
};
/**
* @brief A layer for max pooling
*/
class
MaxPoolProjectionLayer
:
public
PoolProjectionLayer
{
public:
explicit
MaxPoolProjectionLayer
(
const
LayerConfig
&
config
)
:
PoolProjectionLayer
(
config
)
{}
~
MaxPoolProjectionLayer
()
{}
virtual
void
forward
(
PassType
passType
);
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
};
/**
* @brief A layer for average pooling
*/
class
AvgPoolProjectionLayer
:
public
PoolProjectionLayer
{
public:
explicit
AvgPoolProjectionLayer
(
const
LayerConfig
&
config
)
:
PoolProjectionLayer
(
config
)
{}
~
AvgPoolProjectionLayer
()
{}
virtual
void
forward
(
PassType
passType
);
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
explicit
PoolProjectionLayer
(
const
LayerConfig
&
config
)
:
PoolLayer
(
config
)
{
PoolConfig
*
conf
=
projectionConfig_
.
mutable_pool_conf
();
*
conf
=
config_
.
inputs
(
0
).
pool_conf
();
poolProjection_
.
reset
(
PoolProjection
::
create
(
projectionConfig_
,
nullptr
,
useGpu_
));
}
};
}
// namespace paddle
paddle/gserver/tests/test_LayerGrad.cpp
浏览文件 @
fcf177fc
...
...
@@ -897,12 +897,10 @@ void testSppLayer(const string& poolType, const int pyramidHeight, bool trans,
TEST
(
Layer
,
SpatialPyramidPoolLayer
)
{
for
(
auto
useGpu
:
{
false
,
true
})
{
testSppLayer
(
"avg"
,
1
,
false
,
useGpu
);
testSppLayer
(
"avg"
,
3
,
false
,
useGpu
);
testSppLayer
(
"avg"
,
5
,
false
,
useGpu
);
testSppLayer
(
"max"
,
1
,
false
,
useGpu
);
testSppLayer
(
"max"
,
3
,
false
,
useGpu
);
testSppLayer
(
"avg"
,
5
,
false
,
useGpu
);
for
(
auto
pyramidHeight
:
{
1
,
2
,
3
})
{
testSppLayer
(
"avg-projection"
,
pyramidHeight
,
false
,
useGpu
);
testSppLayer
(
"max-projection"
,
pyramidHeight
,
false
,
useGpu
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录