Caffe
sigmoid_cross_entropy_loss_layer.hpp
1 #ifndef CAFFE_SIGMOID_CROSS_ENTROPY_LOSS_LAYER_HPP_
2 #define CAFFE_SIGMOID_CROSS_ENTROPY_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 #include "caffe/layers/sigmoid_layer.hpp"
12 
13 namespace caffe {
14 
44 template <typename Dtype>
45 class SigmoidCrossEntropyLossLayer : public LossLayer<Dtype> {
46  public:
47  explicit SigmoidCrossEntropyLossLayer(const LayerParameter& param)
48  : LossLayer<Dtype>(param),
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  virtual inline const char* type() const { return "SigmoidCrossEntropyLoss"; }
57 
58  protected:
60  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
61  const vector<Blob<Dtype>*>& top);
62  virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
63  const vector<Blob<Dtype>*>& top);
64 
95  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
96  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
97  virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
98  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
99 
104  virtual Dtype get_normalizer(
105  LossParameter_NormalizationMode normalization_mode, int valid_count);
106 
108  shared_ptr<SigmoidLayer<Dtype> > sigmoid_layer_;
110  shared_ptr<Blob<Dtype> > sigmoid_output_;
112  vector<Blob<Dtype>*> sigmoid_bottom_vec_;
114  vector<Blob<Dtype>*> sigmoid_top_vec_;
115 
121  LossParameter_NormalizationMode normalization_;
122  Dtype normalizer_;
123  int outer_num_, inner_num_;
124 };
125 
126 } // namespace caffe
127 
128 #endif // CAFFE_SIGMOID_CROSS_ENTROPY_LOSS_LAYER_HPP_
vector< Blob< Dtype > * > sigmoid_bottom_vec_
bottom vector holder to call the underlying SigmoidLayer::Forward
Definition: sigmoid_cross_entropy_loss_layer.hpp:112
virtual void Forward_cpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Computes the cross-entropy (logistic) loss , often used for predicting targets interpreted as probabi...
Definition: sigmoid_cross_entropy_loss_layer.cpp:79
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
Sigmoid function non-linearity , a classic choice in neural networks.
Definition: sigmoid_layer.hpp:23
shared_ptr< Blob< Dtype > > sigmoid_output_
sigmoid_output stores the output of the SigmoidLayer.
Definition: sigmoid_cross_entropy_loss_layer.hpp:110
vector< Blob< Dtype > * > sigmoid_top_vec_
top vector holder to call the underlying SigmoidLayer::Forward
Definition: sigmoid_cross_entropy_loss_layer.hpp:114
LossParameter_NormalizationMode normalization_
How to normalize the loss.
Definition: sigmoid_cross_entropy_loss_layer.hpp:121
virtual Dtype get_normalizer(LossParameter_NormalizationMode normalization_mode, int valid_count)
Definition: sigmoid_cross_entropy_loss_layer.cpp:49
shared_ptr< SigmoidLayer< Dtype > > sigmoid_layer_
The internal SigmoidLayer used to map predictions to probabilities.
Definition: sigmoid_cross_entropy_loss_layer.hpp:108
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: sigmoid_cross_entropy_loss_layer.cpp:10
bool has_ignore_label_
Whether to ignore instances with a certain label.
Definition: sigmoid_cross_entropy_loss_layer.hpp:117
virtual const char * type() const
Returns the layer type.
Definition: sigmoid_cross_entropy_loss_layer.hpp:56
virtual void Backward_gpu(const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
Using the GPU device, compute the gradients for any parameters and for the bottom blobs if propagate_...
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: sigmoid_cross_entropy_loss_layer.cpp:36
Computes the cross-entropy (logistic) loss , often used for predicting targets interpreted as probabi...
Definition: sigmoid_cross_entropy_loss_layer.hpp:45
An interface for Layers that take two Blobs as input – usually (1) predictions and (2) ground-truth ...
Definition: loss_layer.hpp:23
virtual void Forward_gpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Using the GPU device, compute the layer output. Fall back to Forward_cpu() if unavailable.
virtual void Backward_cpu(const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
Computes the sigmoid cross-entropy loss error gradient w.r.t. the predictions.
Definition: sigmoid_cross_entropy_loss_layer.cpp:104
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24
int ignore_label_
The label indicating that an instance should be ignored.
Definition: sigmoid_cross_entropy_loss_layer.hpp:119