]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - src/caffeine/vision_layers.hpp
lrn layer gpu forward
[jacinto-ai/caffe-jacinto.git] / src / caffeine / vision_layers.hpp
1 #ifndef CAFFEINE_VISION_LAYERS_HPP_
2 #define CAFFEINE_VISION_LAYERS_HPP_
4 #include "caffeine/layer.hpp"
6 namespace caffeine {
8 // The neuron layer is a specific type of layers that just works on single
9 // celements.
10 template <typename Dtype>
11 class NeuronLayer : public Layer<Dtype> {
12  public:
13   explicit NeuronLayer(const LayerParameter& param)
14      : Layer<Dtype>(param) {};
15   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
16       vector<Blob<Dtype>*>* top);
17 };
20 template <typename Dtype>
21 class ReLULayer : public NeuronLayer<Dtype> {
22  public:
23   explicit ReLULayer(const LayerParameter& param)
24       : NeuronLayer<Dtype>(param) {};
25  protected:
26   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
27       vector<Blob<Dtype>*>* top);
28   virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
29       vector<Blob<Dtype>*>* top);
31   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
32       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
33   virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
34       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
35 };
38 template <typename Dtype>
39 class DropoutLayer : public NeuronLayer<Dtype> {
40  public:
41   explicit DropoutLayer(const LayerParameter& param)
42       : NeuronLayer<Dtype>(param) {};
43   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
44       vector<Blob<Dtype>*>* top);
45  protected:
46   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
47       vector<Blob<Dtype>*>* top);
48   virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
49       vector<Blob<Dtype>*>* top);
51   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
52       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
53   virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
54       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
55   shared_ptr<SyncedMemory> rand_vec_;
56   float threshold_;
57   float scale_;
58   unsigned int uint_thres_;
59 };
62 template <typename Dtype>
63 class InnerProductLayer : public Layer<Dtype> {
64  public:
65   explicit InnerProductLayer(const LayerParameter& param)
66       : Layer<Dtype>(param) {};
67   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
68       vector<Blob<Dtype>*>* top);
69  protected:
70   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
71       vector<Blob<Dtype>*>* top);
72   virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
73       vector<Blob<Dtype>*>* top);
75   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
76       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
77   virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
78       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
79   int M_;
80   int K_;
81   int N_;
82   bool biasterm_;
83   shared_ptr<SyncedMemory> bias_multiplier_;
84 };
86 template <typename Dtype>
87 class PaddingLayer : public Layer<Dtype> {
88  public:
89   explicit PaddingLayer(const LayerParameter& param)
90       : Layer<Dtype>(param) {};
91   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
92       vector<Blob<Dtype>*>* top);
93  protected:
94   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
95       vector<Blob<Dtype>*>* top);
96   virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
97       vector<Blob<Dtype>*>* top);
98   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
99       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
100   virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
101       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
102   unsigned int PAD_;
103   int NUM_;
104   int CHANNEL_;
105   int HEIGHT_IN_;
106   int WIDTH_IN_;
107   int HEIGHT_OUT_;
108   int WIDTH_OUT_;
109 };
111 template <typename Dtype>
112 class LRNLayer : public Layer<Dtype> {
113  public:
114   explicit LRNLayer(const LayerParameter& param)
115       : Layer<Dtype>(param) {};
116   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
117       vector<Blob<Dtype>*>* top);
118  protected:
119   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
120       vector<Blob<Dtype>*>* top);
121   virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
122       vector<Blob<Dtype>*>* top);
123   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
124       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
125   virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
126       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
127   // scale_ stores the intermediate summing results
128   Blob<Dtype> scale_;
129   int size_;
130   int pre_pad_;
131   Dtype alpha_;
132   Dtype beta_;
133   int num_;
134   int channels_;
135   int height_;
136   int width_;
137 };
139 template <typename Dtype>
140 class Im2colLayer : public Layer<Dtype> {
141  public:
142   explicit Im2colLayer(const LayerParameter& param)
143       : Layer<Dtype>(param) {};
144   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
145       vector<Blob<Dtype>*>* top);
146  protected:
147   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
148       vector<Blob<Dtype>*>* top);
149   virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
150       vector<Blob<Dtype>*>* top);
151   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
152       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
153   virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
154       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
155   int KSIZE_;
156   int STRIDE_;
157   int CHANNELS_;
158   int HEIGHT_;
159   int WIDTH_;
160 };
162 template <typename Dtype>
163 class ConvolutionLayer : public Layer<Dtype> {
164  public:
165   explicit ConvolutionLayer(const LayerParameter& param)
166       : Layer<Dtype>(param) {};
167   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
168       vector<Blob<Dtype>*>* top);
169  protected:
170   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
171       vector<Blob<Dtype>*>* top);
172   virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
173       vector<Blob<Dtype>*>* top);
174   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
175       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
176   virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
177       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
178   Blob<Dtype> col_bob_;
179  protected:
180   int KSIZE_;
181   int STRIDE_;
182   int NUM_;
183   int CHANNELS_;
184   int HEIGHT_;
185   int WIDTH_;
186   int NUM_OUTPUT_;
187   int GROUP_;
188   Blob<Dtype> col_buffer_;
189   shared_ptr<SyncedMemory> bias_multiplier_;
190   bool biasterm_;
191   int M_;
192   int K_;
193   int N_;
194 };
196 }  // namespace caffeine
198 #endif  // CAFFEINE_VISION_LAYERS_HPP_