]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - src/caffeine/vision_layers.hpp
2fe6a1bff7166b80e258447163d02e567e5b19e9
[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 };
129 template <typename Dtype>
130 class Im2colLayer : public Layer<Dtype> {
131  public:
132   explicit Im2colLayer(const LayerParameter& param)
133       : Layer<Dtype>(param) {};
134   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
135       vector<Blob<Dtype>*>* top);
136  protected:
137   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
138       vector<Blob<Dtype>*>* top);
139   //virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
140   //    vector<Blob<Dtype>*>* top);
141   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
142       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
143   //virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
144   //    const bool propagate_down, vector<Blob<Dtype>*>* bottom);
145   int KSIZE_;
146   int STRIDE_;
147   int CHANNELS_;
148   int HEIGHT_;
149   int WIDTH_;
150 };
152 template <typename Dtype>
153 class ConvolutionLayer : public Layer<Dtype> {
154  public:
155   explicit ConvolutionLayer(const LayerParameter& param)
156       : Layer<Dtype>(param) {};
157   virtual void SetUp(const vector<Blob<Dtype>*>& bottom,
158       vector<Blob<Dtype>*>* top);
159  protected:
160   virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
161       vector<Blob<Dtype>*>* top);
162   //virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
163   //    vector<Blob<Dtype>*>* top);
164   virtual Dtype Backward_cpu(const vector<Blob<Dtype>*>& top,
165       const bool propagate_down, vector<Blob<Dtype>*>* bottom);
166   //virtual Dtype Backward_gpu(const vector<Blob<Dtype>*>& top,
167   //    const bool propagate_down, vector<Blob<Dtype>*>* bottom);
168   Blob<Dtype> col_bob_;
169 };
171 }  // namespace caffeine
173 #endif  // CAFFEINE_VISION_LAYERS_HPP_