| 63 | |
| 64 | template <typename Dtype> |
| 65 | void SPPLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom, |
| 66 | const vector<Blob<Dtype>*>& top) { |
| 67 | SPPParameter spp_param = this->layer_param_.spp_param(); |
| 68 | |
| 69 | num_ = bottom[0]->num(); |
| 70 | channels_ = bottom[0]->channels(); |
| 71 | bottom_h_ = bottom[0]->height(); |
| 72 | bottom_w_ = bottom[0]->width(); |
| 73 | reshaped_first_time_ = false; |
| 74 | CHECK_GT(bottom_h_, 0) << "Input dimensions cannot be zero."; |
| 75 | CHECK_GT(bottom_w_, 0) << "Input dimensions cannot be zero."; |
| 76 | |
| 77 | pyramid_height_ = spp_param.pyramid_height(); |
| 78 | split_top_vec_.clear(); |
| 79 | pooling_bottom_vecs_.clear(); |
| 80 | pooling_layers_.clear(); |
| 81 | pooling_top_vecs_.clear(); |
| 82 | pooling_outputs_.clear(); |
| 83 | flatten_layers_.clear(); |
| 84 | flatten_top_vecs_.clear(); |
| 85 | flatten_outputs_.clear(); |
| 86 | concat_bottom_vec_.clear(); |
| 87 | |
| 88 | if (pyramid_height_ == 1) { |
| 89 | // pooling layer setup |
| 90 | LayerParameter pooling_param = GetPoolingParam(0, bottom_h_, bottom_w_, |
| 91 | spp_param); |
| 92 | pooling_layers_.push_back(shared_ptr<PoolingLayer<Dtype> > ( |
| 93 | new PoolingLayer<Dtype>(pooling_param))); |
| 94 | pooling_layers_[0]->SetUp(bottom, top); |
| 95 | return; |
| 96 | } |
| 97 | // split layer output holders setup |
| 98 | for (int i = 0; i < pyramid_height_; i++) { |
| 99 | split_top_vec_.push_back(new Blob<Dtype>()); |
| 100 | } |
| 101 | |
| 102 | // split layer setup |
| 103 | LayerParameter split_param; |
| 104 | split_layer_.reset(new SplitLayer<Dtype>(split_param)); |
| 105 | split_layer_->SetUp(bottom, split_top_vec_); |
| 106 | |
| 107 | for (int i = 0; i < pyramid_height_; i++) { |
| 108 | // pooling layer input holders setup |
| 109 | pooling_bottom_vecs_.push_back(new vector<Blob<Dtype>*>); |
| 110 | pooling_bottom_vecs_[i]->push_back(split_top_vec_[i]); |
| 111 | |
| 112 | // pooling layer output holders setup |
| 113 | pooling_outputs_.push_back(new Blob<Dtype>()); |
| 114 | pooling_top_vecs_.push_back(new vector<Blob<Dtype>*>); |
| 115 | pooling_top_vecs_[i]->push_back(pooling_outputs_[i]); |
| 116 | |
| 117 | // pooling layer setup |
| 118 | LayerParameter pooling_param = GetPoolingParam( |
| 119 | i, bottom_h_, bottom_w_, spp_param); |
| 120 | |
| 121 | pooling_layers_.push_back(shared_ptr<PoolingLayer<Dtype> > ( |
| 122 | new PoolingLayer<Dtype>(pooling_param))); |