Caffe
loss_layer.hpp
1 #ifndef CAFFE_LOSS_LAYER_HPP_
2 #define CAFFE_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 namespace caffe {
11 
12 const float kLOG_THRESHOLD = 1e-20;
13 
22 template <typename Dtype>
23 class LossLayer : public Layer<Dtype> {
24  public:
25  explicit LossLayer(const LayerParameter& param)
26  : Layer<Dtype>(param) {}
27  virtual void LayerSetUp(
28  const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top);
29  virtual void Reshape(
30  const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top);
31 
32  virtual inline int ExactNumBottomBlobs() const { return 2; }
33 
40  virtual inline bool AutoTopBlobs() const { return true; }
41  virtual inline int ExactNumTopBlobs() const { return 1; }
46  virtual inline bool AllowForceBackward(const int bottom_index) const {
47  return bottom_index != 1;
48  }
49 };
50 
51 } // namespace caffe
52 
53 #endif // CAFFE_LOSS_LAYER_HPP_
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
virtual bool AutoTopBlobs() const
For convenience and backwards compatibility, instruct the Net to automatically allocate a single top ...
Definition: loss_layer.hpp:40
virtual bool AllowForceBackward(const int bottom_index) const
Definition: loss_layer.hpp:46
virtual int ExactNumBottomBlobs() const
Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required...
Definition: loss_layer.hpp:32
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: loss_layer.cpp:17
An interface for Layers that take two Blobs as input – usually (1) predictions and (2) ground-truth ...
Definition: loss_layer.hpp:23
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: loss_layer.cpp:8
virtual int ExactNumTopBlobs() const
Returns the exact number of top blobs required by the layer, or -1 if no exact number is required...
Definition: loss_layer.hpp:41
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24