Caffe
Public Member Functions | List of all members
caffe::LossLayer< Dtype > Class Template Reference

An interface for Layers that take two Blobs as input – usually (1) predictions and (2) ground-truth labels – and output a singleton Blob representing the loss. More...

#include <loss_layer.hpp>

Inheritance diagram for caffe::LossLayer< Dtype >:
caffe::Layer< Dtype > caffe::ContrastiveLossLayer< Dtype > caffe::EuclideanLossLayer< Dtype > caffe::HingeLossLayer< Dtype > caffe::InfogainLossLayer< Dtype > caffe::MultinomialLogisticLossLayer< Dtype > caffe::SigmoidCrossEntropyLossLayer< Dtype > caffe::SoftmaxWithLossLayer< Dtype >

Public Member Functions

 LossLayer (const LayerParameter &param)
 
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. More...
 
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. More...
 
virtual int ExactNumBottomBlobs () const
 Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required. More...
 
virtual bool AutoTopBlobs () const
 For convenience and backwards compatibility, instruct the Net to automatically allocate a single top Blob for LossLayers, into which they output their singleton loss, (even if the user didn't specify one in the prototxt, etc.).
 
virtual int ExactNumTopBlobs () const
 Returns the exact number of top blobs required by the layer, or -1 if no exact number is required. More...
 
virtual bool AllowForceBackward (const int bottom_index) const
 
- Public Member Functions inherited from caffe::Layer< Dtype >
 Layer (const LayerParameter &param)
 
void SetUp (const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
 Implements common layer setup functionality. More...
 
Dtype Forward (const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
 Given the bottom blobs, compute the top blobs and the loss. More...
 
void Backward (const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
 Given the top blob error gradients, compute the bottom blob error gradients. More...
 
vector< shared_ptr< Blob< Dtype > > > & blobs ()
 Returns the vector of learnable parameter blobs.
 
const LayerParameter & layer_param () const
 Returns the layer parameter.
 
virtual void ToProto (LayerParameter *param, bool write_diff=false)
 Writes the layer parameter to a protocol buffer.
 
Dtype loss (const int top_index) const
 Returns the scalar loss associated with a top blob at a given index.
 
void set_loss (const int top_index, const Dtype value)
 Sets the loss associated with a top blob at a given index.
 
virtual const char * type () const
 Returns the layer type.
 
virtual int MinBottomBlobs () const
 Returns the minimum number of bottom blobs required by the layer, or -1 if no minimum number is required. More...
 
virtual int MaxBottomBlobs () const
 Returns the maximum number of bottom blobs required by the layer, or -1 if no maximum number is required. More...
 
virtual int MinTopBlobs () const
 Returns the minimum number of top blobs required by the layer, or -1 if no minimum number is required. More...
 
virtual int MaxTopBlobs () const
 Returns the maximum number of top blobs required by the layer, or -1 if no maximum number is required. More...
 
virtual bool EqualNumBottomTopBlobs () const
 Returns true if the layer requires an equal number of bottom and top blobs. More...
 
bool param_propagate_down (const int param_id)
 Specifies whether the layer should compute gradients w.r.t. a parameter at a particular index given by param_id. More...
 
void set_param_propagate_down (const int param_id, const bool value)
 Sets whether the layer should compute gradients w.r.t. a parameter at a particular index given by param_id.
 

Additional Inherited Members

- Protected Member Functions inherited from caffe::Layer< Dtype >
virtual void Forward_cpu (const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)=0
 Using the CPU device, compute the layer output.
 
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)=0
 Using the CPU device, compute the gradients for any parameters and for the bottom blobs if propagate_down is true.
 
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_down is true. Fall back to Backward_cpu() if unavailable.
 
virtual void CheckBlobCounts (const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
 
void SetLossWeights (const vector< Blob< Dtype > *> &top)
 
- Protected Attributes inherited from caffe::Layer< Dtype >
LayerParameter layer_param_
 
Phase phase_
 
vector< shared_ptr< Blob< Dtype > > > blobs_
 
vector< bool > param_propagate_down_
 
vector< Dtype > loss_
 

Detailed Description

template<typename Dtype>
class caffe::LossLayer< Dtype >

An interface for Layers that take two Blobs as input – usually (1) predictions and (2) ground-truth labels – and output a singleton Blob representing the loss.

LossLayers are typically only capable of backpropagating to their first input – the predictions.

Member Function Documentation

§ AllowForceBackward()

template<typename Dtype >
virtual bool caffe::LossLayer< Dtype >::AllowForceBackward ( const int  bottom_index) const
inlinevirtual

We usually cannot backpropagate to the labels; ignore force_backward for these inputs.

Reimplemented from caffe::Layer< Dtype >.

Reimplemented in caffe::EuclideanLossLayer< Dtype >, and caffe::ContrastiveLossLayer< Dtype >.

§ ExactNumBottomBlobs()

template<typename Dtype >
virtual int caffe::LossLayer< Dtype >::ExactNumBottomBlobs ( ) const
inlinevirtual

Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required.

This method should be overridden to return a non-negative value if your layer expects some exact number of bottom blobs.

Reimplemented from caffe::Layer< Dtype >.

Reimplemented in caffe::InfogainLossLayer< Dtype >, and caffe::ContrastiveLossLayer< Dtype >.

§ ExactNumTopBlobs()

template<typename Dtype >
virtual int caffe::LossLayer< Dtype >::ExactNumTopBlobs ( ) const
inlinevirtual

Returns the exact number of top blobs required by the layer, or -1 if no exact number is required.

This method should be overridden to return a non-negative value if your layer expects some exact number of top blobs.

Reimplemented from caffe::Layer< Dtype >.

Reimplemented in caffe::SoftmaxWithLossLayer< Dtype >.

§ LayerSetUp()

template<typename Dtype >
void caffe::LossLayer< Dtype >::LayerSetUp ( const vector< Blob< Dtype > *> &  bottom,
const vector< Blob< Dtype > *> &  top 
)
virtual

Does layer-specific setup: your layer should implement this function as well as Reshape.

Parameters
bottomthe preshaped input blobs, whose data fields store the input data for this layer
topthe allocated but unshaped output blobs

This method should do one-time layer specific setup. This includes reading and processing relevent parameters from the layer_param_. Setting up the shapes of top blobs and internal buffers should be done in Reshape, which will be called before the forward pass to adjust the top blob sizes.

Reimplemented from caffe::Layer< Dtype >.

Reimplemented in caffe::SoftmaxWithLossLayer< Dtype >, caffe::InfogainLossLayer< Dtype >, caffe::SigmoidCrossEntropyLossLayer< Dtype >, and caffe::ContrastiveLossLayer< Dtype >.

§ Reshape()

template<typename Dtype >
void caffe::LossLayer< Dtype >::Reshape ( const vector< Blob< Dtype > *> &  bottom,
const vector< Blob< Dtype > *> &  top 
)
virtual

Adjust the shapes of top blobs and internal buffers to accommodate the shapes of the bottom blobs.

Parameters
bottomthe input blobs, with the requested input shapes
topthe top blobs, which should be reshaped as needed

This method should reshape top blobs as needed according to the shapes of the bottom (input) blobs, as well as reshaping any internal buffers and making any other necessary adjustments so that the layer can accommodate the bottom blobs.

Implements caffe::Layer< Dtype >.

Reimplemented in caffe::SoftmaxWithLossLayer< Dtype >, caffe::InfogainLossLayer< Dtype >, caffe::SigmoidCrossEntropyLossLayer< Dtype >, caffe::MultinomialLogisticLossLayer< Dtype >, and caffe::EuclideanLossLayer< Dtype >.


The documentation for this class was generated from the following files: