Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
eaf3dec9
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看板
提交
eaf3dec9
编写于
11月 09, 2016
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
70e04683
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
97 addition
and
46 deletion
+97
-46
paddle/gserver/layers/PoolProjection.cpp
paddle/gserver/layers/PoolProjection.cpp
+40
-0
paddle/gserver/layers/PoolProjection.h
paddle/gserver/layers/PoolProjection.h
+5
-35
paddle/gserver/layers/PoolProjectionLayer.h
paddle/gserver/layers/PoolProjectionLayer.h
+9
-9
paddle/gserver/layers/SpatialPyramidPoolLayer.h
paddle/gserver/layers/SpatialPyramidPoolLayer.h
+9
-2
python/paddle/trainer_config_helpers/tests/configs/protostr/test_spp_layer.protostr
...ig_helpers/tests/configs/protostr/test_spp_layer.protostr
+34
-0
未找到文件。
paddle/gserver/layers/PoolProjection.cpp
浏览文件 @
eaf3dec9
...
...
@@ -18,6 +18,46 @@ namespace paddle {
REGISTER_PROJECTION_CREATE_FUNC
(
pool
,
&
PoolProjection
::
create
);
PoolProjection
::
PoolProjection
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
)
:
Projection
(
config
,
parameter
,
useGpu
)
{
const
PoolConfig
&
conf
=
config_
.
pool_conf
();
poolType_
=
conf
.
pool_type
();
channels_
=
conf
.
channels
();
sizeX_
=
conf
.
size_x
();
stride_
=
conf
.
stride
();
outputX_
=
conf
.
output_x
();
imgSize_
=
conf
.
img_size
();
confPadding_
=
conf
.
padding
();
sizeY_
=
conf
.
has_size_y
()
?
conf
.
size_y
()
:
conf
.
size_x
();
imgSizeY_
=
conf
.
has_img_size_y
()
?
conf
.
img_size_y
()
:
conf
.
img_size
();
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
();
}
size_t
PoolProjection
::
getSize
()
{
imgSizeY_
=
in_
->
getFrameHeight
();
imgSize_
=
in_
->
getFrameWidth
();
const
PoolConfig
&
conf
=
config_
.
pool_conf
();
if
(
imgSizeY_
==
0
)
{
imgSizeY_
=
conf
.
has_img_size_y
()
?
conf
.
img_size_y
()
:
conf
.
img_size
();
}
if
(
imgSize_
==
0
)
{
imgSize_
=
conf
.
img_size
();
}
outputY_
=
outputSize
(
imgSizeY_
,
sizeY_
,
confPaddingY_
,
strideY_
,
/* caffeMode */
false
);
outputX_
=
outputSize
(
imgSize_
,
sizeX_
,
confPadding_
,
stride_
,
/* caffeMode */
false
);
const_cast
<
Argument
*>
(
out_
)
->
setFrameHeight
(
outputY_
);
const_cast
<
Argument
*>
(
out_
)
->
setFrameWidth
(
outputX_
);
return
outputY_
*
outputX_
*
channels_
;
}
PoolProjection
*
PoolProjection
::
create
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
)
{
const
std
::
string
&
pool
=
config
.
pool_conf
().
pool_type
();
...
...
paddle/gserver/layers/PoolProjection.h
浏览文件 @
eaf3dec9
...
...
@@ -31,46 +31,14 @@ protected:
public:
PoolProjection
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
)
:
Projection
(
config
,
parameter
,
useGpu
)
{
const
PoolConfig
&
conf
=
config_
.
pool_conf
();
poolType_
=
conf
.
pool_type
();
channels_
=
conf
.
channels
();
sizeX_
=
conf
.
size_x
();
stride_
=
conf
.
stride
();
outputX_
=
conf
.
output_x
();
imgSize_
=
conf
.
img_size
();
confPadding_
=
conf
.
padding
();
bool
useGpu
);
sizeY_
=
conf
.
has_size_y
()
?
conf
.
size_y
()
:
conf
.
size_x
();
imgSizeY_
=
conf
.
has_img_size_y
()
?
conf
.
img_size_y
()
:
conf
.
img_size
();
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
();
}
static
PoolProjection
*
create
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
);
const
std
::
string
&
getPoolType
()
const
{
return
poolType_
;
}
size_t
getSize
()
{
imgSizeY_
=
in_
->
getFrameHeight
();
imgSize_
=
in_
->
getFrameWidth
();
const
PoolConfig
&
conf
=
config_
.
pool_conf
();
if
(
imgSizeY_
==
0
)
{
imgSizeY_
=
conf
.
has_img_size_y
()
?
conf
.
img_size_y
()
:
conf
.
img_size
();
}
if
(
imgSize_
==
0
)
{
imgSize_
=
conf
.
img_size
();
}
outputY_
=
outputSize
(
imgSizeY_
,
sizeY_
,
confPaddingY_
,
strideY_
,
/* caffeMode */
false
);
outputX_
=
outputSize
(
imgSize_
,
sizeX_
,
confPadding_
,
stride_
,
/* caffeMode */
false
);
const_cast
<
Argument
*>
(
out_
)
->
setFrameHeight
(
outputY_
);
const_cast
<
Argument
*>
(
out_
)
->
setFrameWidth
(
outputX_
);
const
std
::
string
&
getPoolType
()
const
{
return
poolType_
;
}
return
outputY_
*
outputX_
*
channels_
;
}
size_t
getSize
();
};
class
MaxPoolProjection
:
public
PoolProjection
{
...
...
@@ -78,6 +46,7 @@ public:
MaxPoolProjection
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
)
:
PoolProjection
(
config
,
parameter
,
useGpu
)
{}
virtual
void
forward
();
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
};
...
...
@@ -87,6 +56,7 @@ public:
AvgPoolProjection
(
const
ProjectionConfig
&
config
,
ParameterPtr
parameter
,
bool
useGpu
)
:
PoolProjection
(
config
,
parameter
,
useGpu
)
{}
virtual
void
forward
();
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
};
...
...
paddle/gserver/layers/PoolProjectionLayer.h
浏览文件 @
eaf3dec9
...
...
@@ -12,13 +12,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <vector>
#include "PoolLayer.h"
#include "PoolProjection.h"
#include "paddle/math/Matrix.h"
#include <vector>
namespace
paddle
{
/**
...
...
@@ -32,15 +31,16 @@ protected:
ProjectionConfig
projectionConfig_
;
public:
size_t
getSize
();
virtual
void
forward
(
PassType
passType
);
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
explicit
PoolProjectionLayer
(
const
LayerConfig
&
config
)
:
PoolLayer
(
config
)
{
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_
));
poolProjection_
.
reset
(
PoolProjection
::
create
(
projectionConfig_
,
nullptr
,
useGpu_
));
}
size_t
getSize
();
virtual
void
forward
(
PassType
passType
);
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
};
}
// namespace paddle
paddle/gserver/layers/SpatialPyramidPoolLayer.h
浏览文件 @
eaf3dec9
...
...
@@ -12,15 +12,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "Layer.h"
#include "PoolProjection.h"
#include "paddle/utils/Logging.h"
#include "paddle/math/MathUtils.h"
#include "paddle/utils/Logging.h"
namespace
paddle
{
/**
* @brief A layer for spatial pyramid pooling on the input image by taking
* the max, average, etc. within regions, so that the result vector of
* different sized images are of the same size.
*/
class
SpatialPyramidPoolLayer
:
public
Layer
{
protected:
...
...
@@ -36,12 +40,15 @@ protected:
public:
explicit
SpatialPyramidPoolLayer
(
const
LayerConfig
&
config
)
:
Layer
(
config
)
{}
~
SpatialPyramidPoolLayer
()
{}
virtual
bool
init
(
const
LayerMap
&
layerMap
,
const
ParameterMap
&
parameterMap
);
ProjectionConfig
getConfig
(
size_t
sizeX_
,
size_t
sizeY_
,
size_t
channels
,
size_t
pyamidLevel_
,
std
::
string
&
poolType_
);
size_t
getSize
();
virtual
void
forward
(
PassType
passType
);
virtual
void
backward
(
const
UpdateCallback
&
callback
=
nullptr
);
};
...
...
python/paddle/trainer_config_helpers/tests/configs/protostr/test_spp_layer.protostr
0 → 100644
浏览文件 @
eaf3dec9
type: "nn"
layers {
name: "data"
type: "data"
size: 3200
active_type: ""
}
layers {
name: "__spp_0__"
type: "spp"
size: 80
active_type: ""
inputs {
input_layer_name: "data"
spp_conf {
pool_type: "max-projection"
pyramid_height: 2
channels: 16
img_size: 10
img_size_y: 20
}
}
}
input_layer_names: "data"
output_layer_names: "__spp_0__"
sub_models {
name: "root"
layer_names: "data"
layer_names: "__spp_0__"
input_layer_names: "data"
output_layer_names: "__spp_0__"
is_recurrent_layer_group: false
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录