PoolProjectionLayer.cpp 2.1 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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. */

Y
Yu Yang 已提交
15
#include "PoolProjectionLayer.h"
Z
zhangjinchao01 已提交
16 17 18 19 20 21 22 23 24 25 26
#include "paddle/utils/Logging.h"
#include "paddle/utils/Stat.h"

namespace paddle {

size_t PoolProjectionLayer::getSize() {
  CHECK_EQ(inputLayers_.size(), 1UL);
  size_t layerSize = 0;
  imgSizeH_ = inputLayers_[0]->getOutput().getFrameHeight();
  imgSizeW_ = inputLayers_[0]->getOutput().getFrameWidth();
  if (imgSizeH_ == 0) {
27
    imgSizeH_ = imgSizeY_;
Z
zhangjinchao01 已提交
28 29 30 31
  }
  if (imgSizeW_ == 0) {
    imgSizeW_ = imgSize_;
  }
32

33 34 35 36
  outputH_ = outputSize(imgSizeH_,
                        sizeY_,
                        confPaddingY_,
                        strideY_,
37
                        /* caffeMode */ false);
38 39 40 41
  outputW_ = outputSize(imgSizeW_,
                        sizeX_,
                        confPadding_,
                        stride_,
42
                        /* caffeMode */ false);
43

Z
zhangjinchao01 已提交
44 45 46 47 48
  layerSize = outputH_ * outputW_ * channels_;

  return layerSize;
}

49
void PoolProjectionLayer::forward(PassType passType) {
Z
zhangjinchao01 已提交
50
  Layer::forward(passType);
51 52
  const Argument& in = getInput(0);
  int batchSize = in.value->getHeight();
Z
zhangjinchao01 已提交
53
  int size = getSize();
X
xzl 已提交
54 55 56 57 58 59 60 61

  if (with_mask_) {
    resetSpecifyOutput(mask_,
                       batchSize,
                       size,
                       /* isValueClean */ false,
                       /* isGradClean */ true);
  }
Z
zhangjinchao01 已提交
62
  resetOutput(batchSize, size);
X
xzl 已提交
63
  poolProjection_->forward(&in, &output_, &mask_, passType);
Z
zhangjinchao01 已提交
64 65
}

66
void PoolProjectionLayer::backward(const UpdateCallback& callback) {
Z
zhangjinchao01 已提交
67 68 69 70
  (void)callback;
  if (NULL == getInputGrad(0)) {
    return;
  }
71
  poolProjection_->backward(callback);
Z
zhangjinchao01 已提交
72 73
}
}  // namespace paddle