]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - src/caffeine/vision_layers.hpp
working version
[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 }  // namespace caffeine
88 #endif  // CAFFEINE_VISION_LAYERS_HPP_