|
|
|
@ -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 AvgPoolProjectionLayer::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
|
|
|
|
|