Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
e2c07135
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看板
提交
e2c07135
编写于
11月 08, 2016
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
db569f29
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
81 addition
and
78 deletion
+81
-78
paddle/cuda/include/hl_cnn.h
paddle/cuda/include/hl_cnn.h
+4
-4
paddle/gserver/layers/PoolProjection.cpp
paddle/gserver/layers/PoolProjection.cpp
+10
-12
paddle/gserver/layers/PoolProjection.h
paddle/gserver/layers/PoolProjection.h
+1
-0
paddle/gserver/layers/SpatialPyramidPoolLayer.cpp
paddle/gserver/layers/SpatialPyramidPoolLayer.cpp
+10
-4
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+56
-56
python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh
...trainer_config_helpers/tests/configs/generate_protostr.sh
+0
-2
未找到文件。
paddle/cuda/include/hl_cnn.h
浏览文件 @
e2c07135
...
@@ -91,7 +91,7 @@ extern void hl_expand_feature2col(
...
@@ -91,7 +91,7 @@ extern void hl_expand_feature2col(
* @param[in] paddingH padding height.
* @param[in] paddingH padding height.
* @param[in] paddingW padding width.
* @param[in] paddingW padding width.
* @param[out] tgtData output data.
* @param[out] tgtData output data.
* @param[in] tgtStride
output data stride
.
* @param[in] tgtStride
stride between output data samples
.
*
*
*/
*/
extern
void
hl_maxpool_forward
(
extern
void
hl_maxpool_forward
(
...
@@ -125,7 +125,7 @@ extern void hl_maxpool_forward(
...
@@ -125,7 +125,7 @@ extern void hl_maxpool_forward(
* @param[in] paddingH padding height.
* @param[in] paddingH padding height.
* @param[in] paddingW padding width.
* @param[in] paddingW padding width.
* @param[out] targetGrad output grad.
* @param[out] targetGrad output grad.
* @param[in] outStride
output grad data stride
.
* @param[in] outStride
stride between output data samples
.
*
*
*/
*/
extern
void
hl_maxpool_backward
(
extern
void
hl_maxpool_backward
(
...
@@ -157,7 +157,7 @@ extern void hl_maxpool_backward(
...
@@ -157,7 +157,7 @@ extern void hl_maxpool_backward(
* @param[in] paddingH padding height.
* @param[in] paddingH padding height.
* @param[in] paddingW padding width.
* @param[in] paddingW padding width.
* @param[out] tgtData output data.
* @param[out] tgtData output data.
* @param[in] tgtStride
output data stride
.
* @param[in] tgtStride
stride between output data samples
.
*
*
*/
*/
extern
void
hl_avgpool_forward
(
extern
void
hl_avgpool_forward
(
...
@@ -189,7 +189,7 @@ extern void hl_avgpool_forward(
...
@@ -189,7 +189,7 @@ extern void hl_avgpool_forward(
* @param[in] scaleA scale.
* @param[in] scaleA scale.
* @param[in] scaleB scale.
* @param[in] scaleB scale.
* @param[out] backGrad output grad.
* @param[out] backGrad output grad.
* @param[in] outStride
output grad data stride
.
* @param[in] outStride
stride between output data samples
.
*
*
*/
*/
extern
void
hl_avgpool_backward
(
extern
void
hl_avgpool_backward
(
...
...
paddle/gserver/layers/PoolProjection.cpp
浏览文件 @
e2c07135
...
@@ -34,9 +34,9 @@ PoolProjection* PoolProjection::create(const ProjectionConfig& config,
...
@@ -34,9 +34,9 @@ PoolProjection* PoolProjection::create(const ProjectionConfig& config,
void
MaxPoolProjection
::
forward
()
{
void
MaxPoolProjection
::
forward
()
{
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
outV
->
maxPoolForward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
channels_
,
outV
->
maxPoolForward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
channels_
,
sizeX_
,
sizeY_
,
s
izeX_
,
sizeY_
,
strideY_
,
stride
_
,
s
trideY_
,
stride_
,
outputY_
,
outputX_
,
confPaddingY
_
,
outputY_
,
outputX_
,
confPaddingY_
,
confPadding_
);
confPadding_
);
}
}
void
MaxPoolProjection
::
backward
(
const
UpdateCallback
&
callback
)
{
void
MaxPoolProjection
::
backward
(
const
UpdateCallback
&
callback
)
{
...
@@ -50,17 +50,16 @@ void MaxPoolProjection::backward(const UpdateCallback& callback) {
...
@@ -50,17 +50,16 @@ void MaxPoolProjection::backward(const UpdateCallback& callback) {
return
;
return
;
}
}
inputGrad
->
maxPoolBackward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
*
outGrad
,
*
outV
,
inputGrad
->
maxPoolBackward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
*
outGrad
,
*
outV
,
sizeX_
,
sizeY_
,
sizeX_
,
sizeY_
,
strideY_
,
stride_
,
outputY_
,
strideY_
,
stride_
,
outputY_
,
outputX_
,
1
,
1
,
outputX_
,
1
,
1
,
confPaddingY_
,
confPadding_
);
confPaddingY_
,
confPadding_
);
}
}
void
AvgPoolProjection
::
forward
()
{
void
AvgPoolProjection
::
forward
()
{
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
inputV
=
in_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
MatrixPtr
outV
=
out_
->
value
;
outV
->
avgPoolForward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
channels_
,
outV
->
avgPoolForward
(
*
inputV
,
imgSizeY_
,
imgSize_
,
channels_
,
sizeX_
,
sizeY_
,
s
izeX_
,
sizeY_
,
strideY_
,
stride
_
,
s
trideY_
,
stride_
,
outputY_
,
outputX_
,
confPaddingY
_
,
outputY_
,
outputX_
,
confPaddingY_
,
confPadding_
);
confPadding_
);
}
}
void
AvgPoolProjection
::
backward
(
const
UpdateCallback
&
callback
)
{
void
AvgPoolProjection
::
backward
(
const
UpdateCallback
&
callback
)
{
...
@@ -73,9 +72,8 @@ void AvgPoolProjection::backward(const UpdateCallback& callback) {
...
@@ -73,9 +72,8 @@ void AvgPoolProjection::backward(const UpdateCallback& callback) {
return
;
return
;
}
}
inputGrad
->
avgPoolBackward
(
*
outputGrad
,
imgSizeY_
,
imgSize_
,
inputGrad
->
avgPoolBackward
(
*
outputGrad
,
imgSizeY_
,
imgSize_
,
sizeX_
,
sizeY_
,
sizeX_
,
sizeY_
,
strideY_
,
stride_
,
strideY_
,
stride_
,
outputY_
,
outputX_
,
1
,
1
,
outputY_
,
outputX_
,
1
,
1
,
confPaddingY_
,
confPadding_
);
confPaddingY_
,
confPadding_
);
}
}
}
// namespace paddle
}
// namespace paddle
paddle/gserver/layers/PoolProjection.h
浏览文件 @
e2c07135
...
@@ -15,6 +15,7 @@ limitations under the License. */
...
@@ -15,6 +15,7 @@ limitations under the License. */
#pragma once
#pragma once
#include "Projection.h"
#include "Projection.h"
#include "paddle/math/MathUtils.h"
namespace
paddle
{
namespace
paddle
{
...
...
paddle/gserver/layers/SpatialPyramidPoolLayer.cpp
浏览文件 @
e2c07135
...
@@ -56,8 +56,15 @@ ProjectionConfig SpatialPyramidPoolLayer::getConfig(size_t imgSizeW,
...
@@ -56,8 +56,15 @@ ProjectionConfig SpatialPyramidPoolLayer::getConfig(size_t imgSizeW,
size_t
SpatialPyramidPoolLayer
::
getSize
()
{
size_t
SpatialPyramidPoolLayer
::
getSize
()
{
CHECK_EQ
(
inputLayers_
.
size
(),
1UL
);
CHECK_EQ
(
inputLayers_
.
size
(),
1UL
);
size_t
layerSize
=
0
;
size_t
layerSize
=
0
;
const
SppConfig
&
sppConf
=
config_
.
inputs
(
0
).
spp_conf
();
imgSizeH_
=
inputLayers_
[
0
]
->
getOutput
().
getFrameHeight
();
imgSizeH_
=
inputLayers_
[
0
]
->
getOutput
().
getFrameHeight
();
imgSizeW_
=
inputLayers_
[
0
]
->
getOutput
().
getFrameWidth
();
imgSizeW_
=
inputLayers_
[
0
]
->
getOutput
().
getFrameWidth
();
if
(
imgSizeH_
==
0
)
{
imgSizeH_
=
sppConf
.
has_img_size_y
()
?
sppConf
.
img_size_y
()
:
imgSizeW_
;
}
if
(
imgSizeW_
==
0
)
{
imgSizeW_
=
sppConf
.
img_size
();
}
size_t
outputH
=
1
;
size_t
outputH
=
1
;
size_t
outputW
=
(
std
::
pow
(
4
,
pyramidHeight_
)
-
1
)
/
(
4
-
1
);
size_t
outputW
=
(
std
::
pow
(
4
,
pyramidHeight_
)
-
1
)
/
(
4
-
1
);
...
@@ -66,10 +73,10 @@ size_t SpatialPyramidPoolLayer::getSize() {
...
@@ -66,10 +73,10 @@ size_t SpatialPyramidPoolLayer::getSize() {
getOutput
().
setFrameHeight
(
outputH
);
getOutput
().
setFrameHeight
(
outputH
);
getOutput
().
setFrameWidth
(
outputW
);
getOutput
().
setFrameWidth
(
outputW
);
return
layerSize
;
return
layerSize
;
}
}
bool
SpatialPyramidPoolLayer
::
init
(
const
LayerMap
&
layerMap
,
bool
SpatialPyramidPoolLayer
::
init
(
const
LayerMap
&
layerMap
,
const
ParameterMap
&
parameterMap
)
{
const
ParameterMap
&
parameterMap
)
{
Layer
::
init
(
layerMap
,
parameterMap
);
Layer
::
init
(
layerMap
,
parameterMap
);
...
@@ -90,8 +97,8 @@ bool SpatialPyramidPoolLayer::init(const LayerMap& layerMap,
...
@@ -90,8 +97,8 @@ bool SpatialPyramidPoolLayer::init(const LayerMap& layerMap,
size_t
endCol
=
0
;
size_t
endCol
=
0
;
for
(
size_t
i
=
0
;
i
<
pyramidHeight_
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
pyramidHeight_
;
i
++
)
{
poolProjections_
.
emplace_back
(
PoolProjection
::
create
(
poolProjections_
.
emplace_back
(
PoolProjection
::
create
(
getConfig
(
imgSizeW_
,
imgSizeH_
,
channels_
,
i
,
poolType_
)
,
getConfig
(
imgSizeW_
,
imgSizeH_
,
channels_
,
i
,
poolType_
),
nullptr
,
nullptr
,
useGpu_
));
useGpu_
));
endCol
+=
poolProjections_
[
i
]
->
getOutputSize
();
endCol
+=
poolProjections_
[
i
]
->
getOutputSize
();
projCol_
.
push_back
(
std
::
make_pair
(
startCol
,
endCol
));
projCol_
.
push_back
(
std
::
make_pair
(
startCol
,
endCol
));
startCol
=
endCol
;
startCol
=
endCol
;
...
@@ -125,4 +132,3 @@ void SpatialPyramidPoolLayer::backward(const UpdateCallback& callback) {
...
@@ -125,4 +132,3 @@ void SpatialPyramidPoolLayer::backward(const UpdateCallback& callback) {
}
}
}
// namespace paddle
}
// namespace paddle
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
e2c07135
...
@@ -56,7 +56,7 @@ __all__ = ["full_matrix_projection", "AggregateLevel", "ExpandLevel",
...
@@ -56,7 +56,7 @@ __all__ = ["full_matrix_projection", "AggregateLevel", "ExpandLevel",
'rank_cost'
,
'lambda_cost'
,
'huber_cost'
,
'rank_cost'
,
'lambda_cost'
,
'huber_cost'
,
'block_expand_layer'
,
'block_expand_layer'
,
'maxout_layer'
,
'out_prod_layer'
,
'print_layer'
,
'maxout_layer'
,
'out_prod_layer'
,
'print_layer'
,
#
'spp_layer',
'spp_layer'
,
]
]
...
@@ -112,7 +112,7 @@ class LayerType(object):
...
@@ -112,7 +112,7 @@ class LayerType(object):
LINEAR_COMBINATION_LAYER
=
"convex_comb"
LINEAR_COMBINATION_LAYER
=
"convex_comb"
BLOCK_EXPAND
=
"blockexpand"
BLOCK_EXPAND
=
"blockexpand"
MAXOUT
=
"maxout"
MAXOUT
=
"maxout"
#
SPP_LAYER = "spp"
SPP_LAYER
=
"spp"
PRINT_LAYER
=
"print"
PRINT_LAYER
=
"print"
...
@@ -1711,60 +1711,60 @@ def img_pool_layer(input, pool_size, name=None,
...
@@ -1711,60 +1711,60 @@ def img_pool_layer(input, pool_size, name=None,
num_filters
=
num_channels
)
num_filters
=
num_channels
)
#
@wrap_name_default("spp")
@
wrap_name_default
(
"spp"
)
#
@layer_support()
@
layer_support
()
#
def spp_layer(input, name=None, num_channels=None, pool_type=None,
def
spp_layer
(
input
,
name
=
None
,
num_channels
=
None
,
pool_type
=
None
,
#
pyramid_height=None, img_width=None, layer_attr=None):
pyramid_height
=
None
,
img_width
=
None
,
layer_attr
=
None
):
#
pass
pass
#
"""
"""
#
Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition.
Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition.
#
The details please refer to
The details please refer to
#
`Kaiming He's paper <https://arxiv.org/abs/1406.4729>`_.
`Kaiming He's paper <https://arxiv.org/abs/1406.4729>`_.
#
:param name: layer name.
:param name: layer name.
#
:type name: basestring
:type name: basestring
#
:param input: layer's input.
:param input: layer's input.
#
:type input: LayerOutput
:type input: LayerOutput
#
:param num_channels: number of input channel.
:param num_channels: number of input channel.
#
:type num_channels: int
:type num_channels: int
#
:param pool_type: Pooling type. MaxPooling or AveragePooling. Default is MaxPooling.
:param pool_type: Pooling type. MaxPooling or AveragePooling. Default is MaxPooling.
#
:type scale: BasePoolingType
:type scale: BasePoolingType
#
:param pyramid_height: pyramid height.
:param pyramid_height: pyramid height.
#
:type pyramid_height: int
:type pyramid_height: int
#
:param img_width: the width of input feature map. If it is None, the input feature
:param img_width: the width of input feature map. If it is None, the input feature
#
map should be square.
map should be square.
#
:type img_width: int|None
:type img_width: int|None
#
:param layer_attr: Extra Layer Attribute.
:param layer_attr: Extra Layer Attribute.
#
:type layer_attr: ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute
#
:return: LayerOutput object.
:return: LayerOutput object.
#
:rtype: LayerOutput
:rtype: LayerOutput
#
"""
"""
#
if num_channels is None:
if
num_channels
is
None
:
#
assert input.num_filters is not None
assert
input
.
num_filters
is
not
None
#
num_channels = input.num_filters
num_channels
=
input
.
num_filters
#
if pool_type is None:
if
pool_type
is
None
:
#
pool_type = MaxPooling()
pool_type
=
MaxPooling
()
#
elif isinstance(pool_type, AvgPooling):
elif
isinstance
(
pool_type
,
AvgPooling
):
#
pool_type.name = 'avg'
pool_type
.
name
=
'avg'
#
type_name = pool_type.name
type_name
=
pool_type
.
name
#
if (isinstance(pool_type, AvgPooling) or isinstance(pool_type, MaxPooling)):
if
(
isinstance
(
pool_type
,
AvgPooling
)
or
isinstance
(
pool_type
,
MaxPooling
)):
#
type_name += '-projection'
type_name
+=
'-projection'
#
Layer(
Layer
(
#
name=name,
name
=
name
,
#
type=LayerType.SPP_LAYER,
type
=
LayerType
.
SPP_LAYER
,
#
inputs=Input(input.name,
inputs
=
Input
(
input
.
name
,
#
spp=SpatialPyramidPool(pool_type=type_name,
spp
=
SpatialPyramidPool
(
pool_type
=
type_name
,
#
channels=num_channels,
channels
=
num_channels
,
#
pyramid_height=pyramid_height,
pyramid_height
=
pyramid_height
,
#
img_width=img_width)
img_width
=
img_width
)
#
),
),
#
**ExtraLayerAttribute.to_kwargs(layer_attr)
**
ExtraLayerAttribute
.
to_kwargs
(
layer_attr
)
#
)
)
#
return LayerOutput(name, LayerType.SPP_LAYER, parents=[input],
return
LayerOutput
(
name
,
LayerType
.
SPP_LAYER
,
parents
=
[
input
],
#
num_filters=num_channels)
num_filters
=
num_channels
)
def
__img_norm_layer__
(
name
,
input
,
size
,
norm_type
,
scale
,
power
,
def
__img_norm_layer__
(
name
,
input
,
size
,
norm_type
,
scale
,
power
,
...
...
python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh
浏览文件 @
e2c07135
...
@@ -11,11 +11,9 @@ test_sequence_pooling test_lstmemory_layer test_grumemory_layer
...
@@ -11,11 +11,9 @@ test_sequence_pooling test_lstmemory_layer test_grumemory_layer
last_first_seq test_expand_layer test_ntm_layers test_hsigmoid
last_first_seq test_expand_layer test_ntm_layers test_hsigmoid
img_layers util_layers simple_rnn_layers unused_layers test_cost_layers
img_layers util_layers simple_rnn_layers unused_layers test_cost_layers
test_rnn_group shared_fc shared_lstm test_cost_layers_with_weight
test_rnn_group shared_fc shared_lstm test_cost_layers_with_weight
# test_maxout test_bi_grumemory math_ops test_spp_layer)
test_maxout test_bi_grumemory math_ops test_spp_layer
)
test_maxout test_bi_grumemory math_ops test_spp_layer
)
for
conf
in
${
configs
[*]
}
for
conf
in
${
configs
[*]
}
do
do
echo
"Generating "
$conf
echo
"Generating "
$conf
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录