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

A helper for LSTMLayer: computes a single timestep of the non-linearity of the LSTM, producing the updated cell and hidden states. More...

#include <lstm_layer.hpp>

Inheritance diagram for caffe::LSTMUnitLayer< Dtype >:
caffe::Layer< Dtype >

Public Member Functions

 LSTMUnitLayer (const LayerParameter &param)
 
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 const char * type () const
 Returns the layer type.
 
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 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
 Return whether to allow force_backward for a given bottom blob index. More...
 
- 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...
 
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...
 
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 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...
 
virtual bool AutoTopBlobs () const
 Return whether "anonymous" top blobs are created automatically by the layer. 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.
 

Protected Member Functions

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)
 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 error gradient w.r.t. the LSTMUnit inputs. More...
 
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.
 
- Protected Member Functions inherited from caffe::Layer< Dtype >
virtual void CheckBlobCounts (const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
 
void SetLossWeights (const vector< Blob< Dtype > *> &top)
 

Protected Attributes

int hidden_dim_
 The hidden and output dimension.
 
Blob< Dtype > X_acts_
 
- 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::LSTMUnitLayer< Dtype >

A helper for LSTMLayer: computes a single timestep of the non-linearity of the LSTM, producing the updated cell and hidden states.

Member Function Documentation

§ AllowForceBackward()

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

Return whether to allow force_backward for a given bottom blob index.

If AllowForceBackward(i) == false, we will ignore the force_backward setting and backpropagate to blob i only if it needs gradient information (as is done when force_backward == false).

Reimplemented from caffe::Layer< Dtype >.

§ Backward_cpu()

template<typename Dtype >
void caffe::LSTMUnitLayer< Dtype >::Backward_cpu ( const vector< Blob< Dtype > *> &  top,
const vector< bool > &  propagate_down,
const vector< Blob< Dtype > *> &  bottom 
)
protectedvirtual

Computes the error gradient w.r.t. the LSTMUnit inputs.

Parameters
topoutput Blob vector (length 2), providing the error gradient with respect to the outputs
  1. $ (1 \times N \times D) $: containing error gradients $ \frac{\partial E}{\partial c_t} $ with respect to the updated cell state $ c_t $
  2. $ (1 \times N \times D) $: containing error gradients $ \frac{\partial E}{\partial h_t} $ with respect to the updated cell state $ h_t $
propagate_downsee Layer::Backward.
bottominput Blob vector (length 3), into which the error gradients with respect to the LSTMUnit inputs $ c_{t-1} $ and the gate inputs are computed. Computatation of the error gradients w.r.t. the sequence indicators is not implemented.
  1. $ (1 \times N \times D) $ the error gradient w.r.t. the previous timestep cell state $ c_{t-1} $
  2. $ (1 \times N \times 4D) $ the error gradient w.r.t. the "gate inputs" $ [ \frac{\partial E}{\partial i_t} \frac{\partial E}{\partial f_t} \frac{\partial E}{\partial o_t} \frac{\partial E}{\partial g_t} ] $
  3. $ (1 \times 1 \times N) $ the gradient w.r.t. the sequence continuation indicators $ \delta_t $ is currently not computed.

Implements caffe::Layer< Dtype >.

§ ExactNumBottomBlobs()

template<typename Dtype >
virtual int caffe::LSTMUnitLayer< 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 >.

§ ExactNumTopBlobs()

template<typename Dtype >
virtual int caffe::LSTMUnitLayer< 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 >.

§ Forward_cpu()

template<typename Dtype >
void caffe::LSTMUnitLayer< Dtype >::Forward_cpu ( const vector< Blob< Dtype > *> &  bottom,
const vector< Blob< Dtype > *> &  top 
)
protectedvirtual
Parameters
bottominput Blob vector (length 3)
  1. $ (1 \times N \times D) $ the previous timestep cell state $ c_{t-1} $
  2. $ (1 \times N \times 4D) $ the "gate inputs" $ [i_t', f_t', o_t', g_t'] $
  3. $ (1 \times N) $ the sequence continuation indicators $ \delta_t $
topoutput Blob vector (length 2)
  1. $ (1 \times N \times D) $ the updated cell state $ c_t $, computed as: i_t := [i_t'] f_t := [f_t'] o_t := [o_t'] g_t := [g_t'] c_t := cont_t * (f_t .* c_{t-1}) + (i_t .* g_t)
  2. $ (1 \times N \times D) $ the updated hidden state $ h_t $, computed as: h_t := o_t .* [c_t]

Implements caffe::Layer< Dtype >.

§ Reshape()

template<typename Dtype >
void caffe::LSTMUnitLayer< 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 >.


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