Caffe
spp_layer.hpp
1 #ifndef CAFFE_SPP_LAYER_HPP_
2 #define CAFFE_SPP_LAYER_HPP_
3 
4 #include <vector>
5 
6 #include "caffe/blob.hpp"
7 #include "caffe/layer.hpp"
8 #include "caffe/proto/caffe.pb.h"
9 
10 namespace caffe {
11 
18 template <typename Dtype>
19 class SPPLayer : public Layer<Dtype> {
20  public:
21  explicit SPPLayer(const LayerParameter& param)
22  : Layer<Dtype>(param) {}
23  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
24  const vector<Blob<Dtype>*>& top);
25  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
26  const vector<Blob<Dtype>*>& top);
27 
28  virtual inline const char* type() const { return "SPP"; }
29  virtual inline int ExactNumBottomBlobs() const { return 1; }
30  virtual inline int ExactNumTopBlobs() const { return 1; }
31 
32  protected:
33  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
34  const vector<Blob<Dtype>*>& top);
35  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
36  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
37  // calculates the kernel and stride dimensions for the pooling layer,
38  // returns a correctly configured LayerParameter for a PoolingLayer
39  virtual LayerParameter GetPoolingParam(const int pyramid_level,
40  const int bottom_h, const int bottom_w, const SPPParameter spp_param);
41 
42  int pyramid_height_;
43  int bottom_h_, bottom_w_;
44  int num_;
45  int channels_;
46  int kernel_h_, kernel_w_;
47  int pad_h_, pad_w_;
48  bool reshaped_first_time_;
49 
51  shared_ptr<SplitLayer<Dtype> > split_layer_;
53  vector<Blob<Dtype>*> split_top_vec_;
55  vector<vector<Blob<Dtype>*>*> pooling_bottom_vecs_;
57  vector<shared_ptr<PoolingLayer<Dtype> > > pooling_layers_;
59  vector<vector<Blob<Dtype>*>*> pooling_top_vecs_;
61  vector<Blob<Dtype>*> pooling_outputs_;
63  vector<FlattenLayer<Dtype>*> flatten_layers_;
65  vector<vector<Blob<Dtype>*>*> flatten_top_vecs_;
67  vector<Blob<Dtype>*> flatten_outputs_;
69  vector<Blob<Dtype>*> concat_bottom_vec_;
71  shared_ptr<ConcatLayer<Dtype> > concat_layer_;
72 };
73 
74 } // namespace caffe
75 
76 #endif // CAFFE_SPP_LAYER_HPP_
An interface for the units of computation which can be composed into a Net.
Definition: layer.hpp:33
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
virtual void Backward_cpu(const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
Using the CPU device, compute the gradients for any parameters and for the bottom blobs if propagate_...
Definition: spp_layer.cpp:205
vector< shared_ptr< PoolingLayer< Dtype > > > pooling_layers_
the internal Pooling layers of different kernel sizes
Definition: spp_layer.hpp:57
virtual void Forward_cpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Using the CPU device, compute the layer output.
Definition: spp_layer.cpp:188
vector< vector< Blob< Dtype > * > * > flatten_top_vecs_
top vector holders used in call to the underlying FlattenLayer::Forward
Definition: spp_layer.hpp:65
vector< vector< Blob< Dtype > * > * > pooling_top_vecs_
top vector holders used in call to the underlying PoolingLayer::Forward
Definition: spp_layer.hpp:59
vector< Blob< Dtype > * > split_top_vec_
top vector holder used in call to the underlying SplitLayer::Forward
Definition: spp_layer.hpp:53
Does spatial pyramid pooling on the input image by taking the max, average, etc. within regions so th...
Definition: spp_layer.hpp:19
virtual const char * type() const
Returns the layer type.
Definition: spp_layer.hpp:28
vector< vector< Blob< Dtype > * > * > pooling_bottom_vecs_
bottom vector holder used in call to the underlying PoolingLayer::Forward
Definition: spp_layer.hpp:55
vector< Blob< Dtype > * > concat_bottom_vec_
bottom vector holder used in call to the underlying ConcatLayer::Forward
Definition: spp_layer.hpp:69
vector< FlattenLayer< Dtype > * > flatten_layers_
the internal Flatten layers that the Pooling layers feed into
Definition: spp_layer.hpp:63
vector< Blob< Dtype > * > flatten_outputs_
flatten_outputs stores the outputs of the FlattenLayers
Definition: spp_layer.hpp:67
virtual void LayerSetUp(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Does layer-specific setup: your layer should implement this function as well as Reshape.
Definition: spp_layer.cpp:65
virtual void Reshape(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Adjust the shapes of top blobs and internal buffers to accommodate the shapes of the bottom blobs...
Definition: spp_layer.cpp:146
virtual int ExactNumTopBlobs() const
Returns the exact number of top blobs required by the layer, or -1 if no exact number is required...
Definition: spp_layer.hpp:30
shared_ptr< ConcatLayer< Dtype > > concat_layer_
the internal Concat layers that the Flatten layers feed into
Definition: spp_layer.hpp:71
shared_ptr< SplitLayer< Dtype > > split_layer_
the internal Split layer that feeds the pooling layers
Definition: spp_layer.hpp:51
virtual int ExactNumBottomBlobs() const
Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required...
Definition: spp_layer.hpp:29
vector< Blob< Dtype > * > pooling_outputs_
pooling_outputs stores the outputs of the PoolingLayers
Definition: spp_layer.hpp:61
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24