spp_layer.hpp
#ifndef CAFFE_SPP_LAYER_HPP_
#define CAFFE_SPP_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"
namespace caffe {
template <typename Dtype>
class SPPLayer : public Layer<Dtype> {
public:
explicit SPPLayer(const LayerParameter& param)
: Layer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual inline const char* type() const { return "SPP"; }
virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int ExactNumTopBlobs() const { return 1; }
protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
// calculates the kernel and stride dimensions for the pooling layer,
// returns a correctly configured LayerParameter for a PoolingLayer
virtual LayerParameter GetPoolingParam(const int pyramid_level,
const int bottom_h, const int bottom_w, const SPPParameter spp_param);
int pyramid_height_;
int bottom_h_, bottom_w_;
int num_;
int channels_;
int kernel_h_, kernel_w_;
int pad_h_, pad_w_;
bool reshaped_first_time_;
shared_ptr<SplitLayer<Dtype> > split_layer_;
vector<Blob<Dtype>*> split_top_vec_;
vector<vector<Blob<Dtype>*>*> pooling_bottom_vecs_;
vector<shared_ptr<PoolingLayer<Dtype> > > pooling_layers_;
vector<vector<Blob<Dtype>*>*> pooling_top_vecs_;
vector<Blob<Dtype>*> pooling_outputs_;
vector<FlattenLayer<Dtype>*> flatten_layers_;
vector<vector<Blob<Dtype>*>*> flatten_top_vecs_;
vector<Blob<Dtype>*> flatten_outputs_;
vector<Blob<Dtype>*> concat_bottom_vec_;
shared_ptr<ConcatLayer<Dtype> > concat_layer_;
};
} // namespace caffe
#endif // CAFFE_SPP_LAYER_HPP_
caffe::SPPLayer::concat_layer_
shared_ptr< ConcatLayer< Dtype > > concat_layer_
the internal Concat layers that the Flatten layers feed into
Definition: spp_layer.hpp:71
caffe::SPPLayer::split_top_vec_
vector< Blob< Dtype > * > split_top_vec_
top vector holder used in call to the underlying SplitLayer::Forward
Definition: spp_layer.hpp:53
caffe::SPPLayer::Forward_cpu
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
caffe::SPPLayer
Does spatial pyramid pooling on the input image by taking the max, average, etc. within regions so th...
Definition: spp_layer.hpp:19
caffe::SPPLayer::type
virtual const char * type() const
Returns the layer type.
Definition: spp_layer.hpp:28
caffe::SPPLayer::pooling_bottom_vecs_
vector< vector< Blob< Dtype > * > * > pooling_bottom_vecs_
bottom vector holder used in call to the underlying PoolingLayer::Forward
Definition: spp_layer.hpp:55
caffe::SPPLayer::pooling_outputs_
vector< Blob< Dtype > * > pooling_outputs_
pooling_outputs stores the outputs of the PoolingLayers
Definition: spp_layer.hpp:61
caffe::SPPLayer::LayerSetUp
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
caffe::Blob
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers,...
Definition: blob.hpp:24
caffe::SPPLayer::pooling_top_vecs_
vector< vector< Blob< Dtype > * > * > pooling_top_vecs_
top vector holders used in call to the underlying PoolingLayer::Forward
Definition: spp_layer.hpp:59
caffe::Layer
An interface for the units of computation which can be composed into a Net.
Definition: layer.hpp:33
caffe::SPPLayer::split_layer_
shared_ptr< SplitLayer< Dtype > > split_layer_
the internal Split layer that feeds the pooling layers
Definition: spp_layer.hpp:51
caffe::SPPLayer::ExactNumTopBlobs
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
caffe::SPPLayer::concat_bottom_vec_
vector< Blob< Dtype > * > concat_bottom_vec_
bottom vector holder used in call to the underlying ConcatLayer::Forward
Definition: spp_layer.hpp:69
caffe::SPPLayer::ExactNumBottomBlobs
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
caffe::SPPLayer::flatten_outputs_
vector< Blob< Dtype > * > flatten_outputs_
flatten_outputs stores the outputs of the FlattenLayers
Definition: spp_layer.hpp:67
caffe
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
caffe::SPPLayer::Reshape
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
caffe::SPPLayer::Backward_cpu
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
caffe::SPPLayer::flatten_layers_
vector< FlattenLayer< Dtype > * > flatten_layers_
the internal Flatten layers that the Pooling layers feed into
Definition: spp_layer.hpp:63
caffe::SPPLayer::flatten_top_vecs_
vector< vector< Blob< Dtype > * > * > flatten_top_vecs_
top vector holders used in call to the underlying FlattenLayer::Forward
Definition: spp_layer.hpp:65
caffe::SPPLayer::pooling_layers_
vector< shared_ptr< PoolingLayer< Dtype > > > pooling_layers_
the internal Pooling layers of different kernel sizes
Definition: spp_layer.hpp:57