提交 e2c07135 编写于 作者: Q qijun

follow comments

上级 db569f29
...@@ -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(
......
...@@ -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_,
sizeX_, sizeY_, strideY_, stride_, strideY_, 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_,
sizeX_, sizeY_, strideY_, stride_, strideY_, 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
...@@ -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 {
......
...@@ -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
...@@ -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,
......
...@@ -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.
先完成此消息的编辑!
想要评论请 注册