sigmoid_cross_entropy_loss_layer.hpp
#ifndef CAFFE_SIGMOID_CROSS_ENTROPY_LOSS_LAYER_HPP_
#define CAFFE_SIGMOID_CROSS_ENTROPY_LOSS_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/layers/loss_layer.hpp"
#include "caffe/layers/sigmoid_layer.hpp"
namespace caffe {
template <typename Dtype>
class SigmoidCrossEntropyLossLayer : public LossLayer<Dtype> {
public:
explicit SigmoidCrossEntropyLossLayer(const LayerParameter& param)
: LossLayer<Dtype>(param),
sigmoid_layer_(new SigmoidLayer<Dtype>(param)),
sigmoid_output_(new Blob<Dtype>()) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual inline const char* type() const { return "SigmoidCrossEntropyLoss"; }
protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
virtual Dtype get_normalizer(
LossParameter_NormalizationMode normalization_mode, int valid_count);
shared_ptr<SigmoidLayer<Dtype> > sigmoid_layer_;
shared_ptr<Blob<Dtype> > sigmoid_output_;
vector<Blob<Dtype>*> sigmoid_bottom_vec_;
vector<Blob<Dtype>*> sigmoid_top_vec_;
bool has_ignore_label_;
int ignore_label_;
LossParameter_NormalizationMode normalization_;
Dtype normalizer_;
int outer_num_, inner_num_;
};
} // namespace caffe
#endif // CAFFE_SIGMOID_CROSS_ENTROPY_LOSS_LAYER_HPP_
caffe::SigmoidLayer
Sigmoid function non-linearity , a classic choice in neural networks.
Definition: sigmoid_layer.hpp:23
caffe::SigmoidCrossEntropyLossLayer::Forward_gpu
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.
caffe::SigmoidCrossEntropyLossLayer::sigmoid_layer_
shared_ptr< SigmoidLayer< Dtype > > sigmoid_layer_
The internal SigmoidLayer used to map predictions to probabilities.
Definition: sigmoid_cross_entropy_loss_layer.hpp:108
caffe::SigmoidCrossEntropyLossLayer::sigmoid_output_
shared_ptr< Blob< Dtype > > sigmoid_output_
sigmoid_output stores the output of the SigmoidLayer.
Definition: sigmoid_cross_entropy_loss_layer.hpp:110
caffe::SigmoidCrossEntropyLossLayer::Forward_cpu
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
caffe::SigmoidCrossEntropyLossLayer
Computes the cross-entropy (logistic) loss , often used for predicting targets interpreted as probabi...
Definition: sigmoid_cross_entropy_loss_layer.hpp:45
caffe::SigmoidCrossEntropyLossLayer::Backward_cpu
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
caffe::Blob
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers,...
Definition: blob.hpp:24
caffe::LossLayer
An interface for Layers that take two Blobs as input – usually (1) predictions and (2) ground-truth l...
Definition: loss_layer.hpp:23
caffe::SigmoidCrossEntropyLossLayer::Reshape
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
caffe::SigmoidCrossEntropyLossLayer::LayerSetUp
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
caffe::SigmoidCrossEntropyLossLayer::ignore_label_
int ignore_label_
The label indicating that an instance should be ignored.
Definition: sigmoid_cross_entropy_loss_layer.hpp:119
caffe::SigmoidCrossEntropyLossLayer::has_ignore_label_
bool has_ignore_label_
Whether to ignore instances with a certain label.
Definition: sigmoid_cross_entropy_loss_layer.hpp:117
caffe::SigmoidCrossEntropyLossLayer::sigmoid_top_vec_
vector< Blob< Dtype > * > sigmoid_top_vec_
top vector holder to call the underlying SigmoidLayer::Forward
Definition: sigmoid_cross_entropy_loss_layer.hpp:114
caffe::SigmoidCrossEntropyLossLayer::normalization_
LossParameter_NormalizationMode normalization_
How to normalize the loss.
Definition: sigmoid_cross_entropy_loss_layer.hpp:121
caffe::SigmoidCrossEntropyLossLayer::type
virtual const char * type() const
Returns the layer type.
Definition: sigmoid_cross_entropy_loss_layer.hpp:56
caffe::SigmoidCrossEntropyLossLayer::sigmoid_bottom_vec_
vector< Blob< Dtype > * > sigmoid_bottom_vec_
bottom vector holder to call the underlying SigmoidLayer::Forward
Definition: sigmoid_cross_entropy_loss_layer.hpp:112
caffe::SigmoidCrossEntropyLossLayer::Backward_gpu
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_...
caffe
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
caffe::SigmoidCrossEntropyLossLayer::get_normalizer
virtual Dtype get_normalizer(LossParameter_NormalizationMode normalization_mode, int valid_count)
Definition: sigmoid_cross_entropy_loss_layer.cpp:49