-
Notifications
You must be signed in to change notification settings - Fork 108
/
psroi_pooling_layer.cpp
70 lines (58 loc) · 2.18 KB
/
psroi_pooling_layer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// ------------------------------------------------------------------
// R-FCN
// Copyright (c) 2016 Microsoft
// Licensed under The MIT License [see r-fcn/LICENSE for details]
// Written by Yi Li
// ------------------------------------------------------------------
#include <cfloat>
#include <string>
#include <utility>
#include <vector>
#include "caffe/rfcn_layers.hpp"
using std::max;
using std::min;
using std::floor;
using std::ceil;
namespace caffe {
template <typename Dtype>
void PSROIPoolingLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top){
PSROIPoolingParameter psroi_pooling_param = this->layer_param_.psroi_pooling_param();
spatial_scale_ = psroi_pooling_param.spatial_scale();
LOG(INFO) << "Spatial scale: " << spatial_scale_;
CHECK_GT(psroi_pooling_param.output_dim(), 0)
<< "output_dim must be > 0";
CHECK_GT(psroi_pooling_param.group_size(), 0)
<< "group_size must be > 0";
output_dim_ = psroi_pooling_param.output_dim();
group_size_ = psroi_pooling_param.group_size();
pooled_height_ = group_size_;
pooled_width_ = group_size_;
}
template <typename Dtype>
void PSROIPoolingLayer<Dtype>::Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top) {
channels_ = bottom[0]->channels();
CHECK_EQ(channels_, output_dim_*group_size_*group_size_)
<< "input channel number does not match layer parameters";
height_ = bottom[0]->height();
width_ = bottom[0]->width();
top[0]->Reshape(bottom[1]->num(), output_dim_, pooled_height_, pooled_width_);
mapping_channel_.Reshape(bottom[1]->num(), output_dim_, pooled_height_, pooled_width_);
}
template <typename Dtype>
void PSROIPoolingLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top){
NOT_IMPLEMENTED;
}
template <typename Dtype>
void PSROIPoolingLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom){
NOT_IMPLEMENTED;
}
#ifdef CPU_ONLY
STUB_GPU(PSROIPoolingLayer);
#endif
INSTANTIATE_CLASS(PSROIPoolingLayer);
REGISTER_LAYER_CLASS(PSROIPooling);
}