Caffe
infogain_loss_layer.hpp
1 #ifndef CAFFE_INFOGAIN_LOSS_LAYER_HPP_
2 #define CAFFE_INFOGAIN_LOSS_LAYER_HPP_
3 
4 #include <vector>
5 
6 #include "caffe/blob.hpp"
7 #include "caffe/layer.hpp"
8 #include "caffe/proto/caffe.pb.h"
9 
10 #include "caffe/layers/loss_layer.hpp"
11 
12 namespace caffe {
13 
46 template <typename Dtype>
47 class InfogainLossLayer : public LossLayer<Dtype> {
48  public:
49  explicit InfogainLossLayer(const LayerParameter& param)
50  : LossLayer<Dtype>(param), infogain_() {}
51  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
52  const vector<Blob<Dtype>*>& top);
53  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
54  const vector<Blob<Dtype>*>& top);
55 
56  // InfogainLossLayer takes 2-3 bottom Blobs; if there are 3 the third should
57  // be the infogain matrix. (Otherwise the infogain matrix is loaded from a
58  // file specified by LayerParameter.)
59  virtual inline int ExactNumBottomBlobs() const { return -1; }
60  virtual inline int MinBottomBlobs() const { return 2; }
61  virtual inline int MaxBottomBlobs() const { return 3; }
62 
63  virtual inline const char* type() const { return "InfogainLoss"; }
64 
65  protected:
67  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
68  const vector<Blob<Dtype>*>& top);
69 
102  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
103  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
104 
105  Blob<Dtype> infogain_;
106 };
107 
108 } // namespace caffe
109 
110 #endif // CAFFE_INFOGAIN_LOSS_LAYER_HPP_
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: infogain_loss_layer.cpp:11
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
virtual const char * type() const
Returns the layer type.
Definition: infogain_loss_layer.hpp:63
A generalization of MultinomialLogisticLossLayer that takes an "information gain" (infogain) matrix s...
Definition: infogain_loss_layer.hpp:47
virtual void Backward_cpu(const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
Computes the infogain loss error gradient w.r.t. the predictions.
Definition: infogain_loss_layer.cpp:71
virtual int MaxBottomBlobs() const
Returns the maximum number of bottom blobs required by the layer, or -1 if no maximum number is requi...
Definition: infogain_loss_layer.hpp:61
virtual void Forward_cpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
A generalization of MultinomialLogisticLossLayer that takes an "information gain" (infogain) matrix s...
Definition: infogain_loss_layer.cpp:47
virtual int ExactNumBottomBlobs() const
Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required...
Definition: infogain_loss_layer.hpp:59
An interface for Layers that take two Blobs as input – usually (1) predictions and (2) ground-truth ...
Definition: loss_layer.hpp:23
virtual int MinBottomBlobs() const
Returns the minimum number of bottom blobs required by the layer, or -1 if no minimum number is requi...
Definition: infogain_loss_layer.hpp:60
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: infogain_loss_layer.cpp:25
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24