PoolProjectionLayer.cpp 1.8 KB
Newer Older
Z
zhangjinchao01 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.

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. */

#include "paddle/utils/Logging.h"
#include "paddle/utils/Stat.h"
#include "PoolProjectionLayer.h"

namespace paddle {

21

Z
zhangjinchao01 已提交
22 23 24 25 26 27
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) {
28
    imgSizeH_ = imgSizeY_;
Z
zhangjinchao01 已提交
29 30 31 32
  }
  if (imgSizeW_ == 0) {
    imgSizeW_ = imgSize_;
  }
33

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

Z
zhangjinchao01 已提交
39 40 41 42 43 44 45
  layerSize = outputH_ * outputW_ * channels_;

  getOutput().setFrameHeight(outputH_);
  getOutput().setFrameWidth(outputW_);
  return layerSize;
}

46
void PoolProjectionLayer::forward(PassType passType) {
Z
zhangjinchao01 已提交
47
  Layer::forward(passType);
48 49
  const Argument& in = getInput(0);
  int batchSize = in.value->getHeight();
Z
zhangjinchao01 已提交
50 51
  int size = getSize();
  resetOutput(batchSize, size);
52
  poolProjection_->forward(&in, &output_, passType);
Z
zhangjinchao01 已提交
53 54
}

55
void PoolProjectionLayer::backward(const UpdateCallback& callback) {
Z
zhangjinchao01 已提交
56 57 58 59
  (void)callback;
  if (NULL == getInputGrad(0)) {
    return;
  }
60
  poolProjection_->backward(callback);
Z
zhangjinchao01 已提交
61 62
}
}  // namespace paddle