From 70e04683dddd4ae47f1947f95008413ce1e69fce Mon Sep 17 00:00:00 2001 From: qijun Date: Tue, 8 Nov 2016 13:26:41 +0000 Subject: [PATCH] add getSize method for PoolProjection --- paddle/gserver/layers/PoolProjection.cpp | 4 ++++ paddle/gserver/layers/PoolProjection.h | 20 +++++++++++++++++++ paddle/gserver/layers/PoolProjectionLayer.cpp | 2 -- .../layers/SpatialPyramidPoolLayer.cpp | 4 ---- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/paddle/gserver/layers/PoolProjection.cpp b/paddle/gserver/layers/PoolProjection.cpp index 8c7d027c072..a4fb001ffa0 100644 --- a/paddle/gserver/layers/PoolProjection.cpp +++ b/paddle/gserver/layers/PoolProjection.cpp @@ -32,6 +32,8 @@ PoolProjection* PoolProjection::create(const ProjectionConfig& config, } void MaxPoolProjection::forward() { + size_t width = getSize(); + CHECK_EQ(width, out_->value->getWidth()); MatrixPtr inputV = in_->value; MatrixPtr outV = out_->value; outV->maxPoolForward(*inputV, imgSizeY_, imgSize_, channels_, sizeX_, sizeY_, @@ -55,6 +57,8 @@ void MaxPoolProjection::backward(const UpdateCallback& callback) { } void AvgPoolProjection::forward() { + size_t width = getSize(); + CHECK_EQ(width, out_->value->getWidth()); MatrixPtr inputV = in_->value; MatrixPtr outV = out_->value; outV->avgPoolForward(*inputV, imgSizeY_, imgSize_, channels_, sizeX_, sizeY_, diff --git a/paddle/gserver/layers/PoolProjection.h b/paddle/gserver/layers/PoolProjection.h index 9fa16c1ea64..04d592f51fb 100644 --- a/paddle/gserver/layers/PoolProjection.h +++ b/paddle/gserver/layers/PoolProjection.h @@ -51,6 +51,26 @@ public: 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(out_)->setFrameHeight(outputY_); + const_cast(out_)->setFrameWidth(outputX_); + + return outputY_ * outputX_ * channels_; + } }; class MaxPoolProjection : public PoolProjection { diff --git a/paddle/gserver/layers/PoolProjectionLayer.cpp b/paddle/gserver/layers/PoolProjectionLayer.cpp index fbef55e4d49..cabb346d6c9 100644 --- a/paddle/gserver/layers/PoolProjectionLayer.cpp +++ b/paddle/gserver/layers/PoolProjectionLayer.cpp @@ -38,8 +38,6 @@ size_t PoolProjectionLayer::getSize() { layerSize = outputH_ * outputW_ * channels_; - getOutput().setFrameHeight(outputH_); - getOutput().setFrameWidth(outputW_); return layerSize; } diff --git a/paddle/gserver/layers/SpatialPyramidPoolLayer.cpp b/paddle/gserver/layers/SpatialPyramidPoolLayer.cpp index 846e2e06660..582abf78c84 100644 --- a/paddle/gserver/layers/SpatialPyramidPoolLayer.cpp +++ b/paddle/gserver/layers/SpatialPyramidPoolLayer.cpp @@ -70,10 +70,6 @@ size_t SpatialPyramidPoolLayer::getSize() { size_t outputW = (std::pow(4, pyramidHeight_) - 1) / (4 - 1); layerSize = outputH * outputW * channels_; - - getOutput().setFrameHeight(outputH); - getOutput().setFrameWidth(outputW); - return layerSize; } -- GitLab