softmax_loss_layer.hpp
#ifndef CAFFE_SOFTMAX_WITH_LOSS_LAYER_HPP_
#define CAFFE_SOFTMAX_WITH_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/softmax_layer.hpp"
namespace caffe {
template <typename Dtype>
class SoftmaxWithLossLayer : public LossLayer<Dtype> {
public:
explicit SoftmaxWithLossLayer(const LayerParameter& param)
: LossLayer<Dtype>(param) {}
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 "SoftmaxWithLoss"; }
virtual inline int ExactNumTopBlobs() const { return -1; }
virtual inline int MinTopBlobs() const { return 1; }
virtual inline int MaxTopBlobs() const { return 2; }
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<Layer<Dtype> > softmax_layer_;
Blob<Dtype> prob_;
vector<Blob<Dtype>*> softmax_bottom_vec_;
vector<Blob<Dtype>*> softmax_top_vec_;
bool has_ignore_label_;
int ignore_label_;
LossParameter_NormalizationMode normalization_;
int softmax_axis_, outer_num_, inner_num_;
};
} // namespace caffe
#endif // CAFFE_SOFTMAX_WITH_LOSS_LAYER_HPP_
caffe::SoftmaxWithLossLayer::ignore_label_
int ignore_label_
The label indicating that an instance should be ignored.
Definition: softmax_loss_layer.hpp:121
caffe::SoftmaxWithLossLayer::prob_
Blob< Dtype > prob_
prob stores the output probability predictions from the SoftmaxLayer.
Definition: softmax_loss_layer.hpp:113
caffe::SoftmaxWithLossLayer::SoftmaxWithLossLayer
SoftmaxWithLossLayer(const LayerParameter &param)
Definition: softmax_loss_layer.hpp:54
caffe::SoftmaxWithLossLayer::has_ignore_label_
bool has_ignore_label_
Whether to ignore instances with a certain label.
Definition: softmax_loss_layer.hpp:119
caffe::SoftmaxWithLossLayer::softmax_top_vec_
vector< Blob< Dtype > * > softmax_top_vec_
top vector holder used in call to the underlying SoftmaxLayer::Forward
Definition: softmax_loss_layer.hpp:117
caffe::SoftmaxWithLossLayer::ExactNumTopBlobs
virtual int ExactNumTopBlobs() const
Returns the exact number of top blobs required by the layer, or -1 if no exact number is required.
Definition: softmax_loss_layer.hpp:62
caffe::SoftmaxWithLossLayer::softmax_layer_
shared_ptr< Layer< Dtype > > softmax_layer_
The internal SoftmaxLayer used to map predictions to a distribution.
Definition: softmax_loss_layer.hpp:111
caffe::SoftmaxWithLossLayer::type
virtual const char * type() const
Returns the layer type.
Definition: softmax_loss_layer.hpp:61
caffe::SoftmaxWithLossLayer::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::SoftmaxWithLossLayer::softmax_bottom_vec_
vector< Blob< Dtype > * > softmax_bottom_vec_
bottom vector holder used in call to the underlying SoftmaxLayer::Forward
Definition: softmax_loss_layer.hpp:115
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::SoftmaxWithLossLayer::get_normalizer
virtual Dtype get_normalizer(LossParameter_NormalizationMode normalization_mode, int valid_count)
Definition: softmax_loss_layer.cpp:59
caffe::SoftmaxWithLossLayer::Forward_cpu
virtual void Forward_cpu(const vector< Blob< Dtype > * > &bottom, const vector< Blob< Dtype > * > &top)
Using the CPU device, compute the layer output.
Definition: softmax_loss_layer.cpp:89
caffe::SoftmaxWithLossLayer::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: softmax_loss_layer.cpp:11
caffe::SoftmaxWithLossLayer::normalization_
LossParameter_NormalizationMode normalization_
How to normalize the output loss.
Definition: softmax_loss_layer.hpp:123
caffe::SoftmaxWithLossLayer
Computes the multinomial logistic loss for a one-of-many classification task, passing real-valued pre...
Definition: softmax_loss_layer.hpp:44
caffe::SoftmaxWithLossLayer::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::SoftmaxWithLossLayer::MinTopBlobs
virtual int MinTopBlobs() const
Returns the minimum number of top blobs required by the layer, or -1 if no minimum number is required...
Definition: softmax_loss_layer.hpp:63
caffe::SoftmaxWithLossLayer::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: softmax_loss_layer.cpp:39
caffe::SoftmaxWithLossLayer::Backward_cpu
virtual void Backward_cpu(const vector< Blob< Dtype > * > &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > * > &bottom)
Computes the softmax loss error gradient w.r.t. the predictions.
Definition: softmax_loss_layer.cpp:118
caffe
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
caffe::SoftmaxWithLossLayer::MaxTopBlobs
virtual int MaxTopBlobs() const
Returns the maximum number of top blobs required by the layer, or -1 if no maximum number is required...
Definition: softmax_loss_layer.hpp:64