Caffe
parameter_layer.hpp
1 #ifndef CAFFE_PARAMETER_LAYER_HPP_
2 #define CAFFE_PARAMETER_LAYER_HPP_
3 
4 #include <vector>
5 
6 #include "caffe/layer.hpp"
7 
8 namespace caffe {
9 
10 template <typename Dtype>
11 class ParameterLayer : public Layer<Dtype> {
12  public:
13  explicit ParameterLayer(const LayerParameter& param)
14  : Layer<Dtype>(param) {}
15  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
16  const vector<Blob<Dtype>*>& top) {
17  if (this->blobs_.size() > 0) {
18  LOG(INFO) << "Skipping parameter initialization";
19  } else {
20  this->blobs_.resize(1);
21  this->blobs_[0].reset(new Blob<Dtype>());
22  this->blobs_[0]->Reshape(this->layer_param_.parameter_param().shape());
23  }
24  top[0]->Reshape(this->layer_param_.parameter_param().shape());
25  }
26  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
27  const vector<Blob<Dtype>*>& top) { }
28  virtual inline const char* type() const { return "Parameter"; }
29  virtual inline int ExactNumBottomBlobs() const { return 0; }
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  top[0]->ShareData(*(this->blobs_[0]));
36  top[0]->ShareDiff(*(this->blobs_[0]));
37  }
38  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
39  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom)
40  { }
41 };
42 
43 } // namespace caffe
44 
45 #endif
virtual int ExactNumBottomBlobs() const
Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required...
Definition: parameter_layer.hpp:29
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
vector< shared_ptr< Blob< Dtype > > > blobs_
Definition: layer.hpp:301
virtual const char * type() const
Returns the layer type.
Definition: parameter_layer.hpp:28
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: parameter_layer.hpp:15
virtual void Forward_cpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Using the CPU device, compute the layer output.
Definition: parameter_layer.hpp:33
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: parameter_layer.hpp:38
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: parameter_layer.hpp:26
LayerParameter layer_param_
Definition: layer.hpp:297
Definition: parameter_layer.hpp:11
virtual int ExactNumTopBlobs() const
Returns the exact number of top blobs required by the layer, or -1 if no exact number is required...
Definition: parameter_layer.hpp:30
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24