ConvNet  1.0
A GPU-based C++ implementation of Convolutional Neural Nets
 All Classes Namespaces Functions Variables
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Layer Class Referenceabstract

The base class for all layers. More...

#include <layer.h>

Inheritance diagram for Layer:
LinearLayer LogisticLayer SoftmaxLayer ReLULayer SoftmaxDistLayer

Public Member Functions

 Layer (const config::Layer &config)
 Instantiate a layer from config. More...
 
virtual void AllocateMemory (int imgsize, int batch_size)
 Allocate memory for storing the state and derivative at this layer. More...
 
virtual void ApplyActivation (bool train)=0
 Apply the activation function. More...
 
virtual void ApplyDerivativeOfActivation ()=0
 Apply the derivative of the activation. More...
 
virtual void ComputeDeriv ()=0
 Compute derivative of loss function. More...
 
virtual float GetLoss ()=0
 Compute the value of the loss function that is displayed during training. More...
 
virtual float GetLoss2 ()
 Compute the value of the actual loss function. More...
 
void ApplyDropout (bool train)
 Apply dropout to this layer. More...
 
void ApplyDerivativeofDropout ()
 Apply derivative of dropout. More...
 
void AccessStateBegin ()
 
void AccessStateEnd ()
 
void AccessDerivBegin ()
 
void AccessDerivEnd ()
 
EdgeGetIncomingEdge (int index)
 Returns the incoming edge by index. More...
 
MatrixGetState ()
 Returns a reference to the state of the layer. More...
 
MatrixGetDeriv ()
 Returns a reference to the deriv at this layer. More...
 
MatrixGetData ()
 Returns a reference to the data at this layer. More...
 
void Display ()
 
void Display (int image_id)
 
void AddIncoming (Edge *e)
 Add an incoming edge to this layer. More...
 
void AddOutgoing (Edge *e)
 Add an outgoing edge from this layer. More...
 
const string & GetName () const
 
int GetNumChannels () const
 
int GetSize () const
 
bool IsInput () const
 
bool IsOutput () const
 
int GetGPUId () const
 
void AllocateMemoryOnOtherGPUs ()
 
MatrixGetOtherState (int gpu_id)
 
MatrixGetOtherDeriv (int gpu_id)
 
void SyncIncomingState ()
 
void SyncOutgoingState ()
 
void SyncIncomingDeriv ()
 
void SyncOutgoingDeriv ()
 

Static Public Member Functions

static LayerChooseLayerClass (const config::Layer &layer_config)
 

Public Attributes

vector< Edge * > incoming_edge_
 
vector< Edge * > outgoing_edge_
 
bool has_incoming_from_same_gpu_
 
bool has_outgoing_to_same_gpu_
 
bool has_incoming_from_other_gpus_
 
bool has_outgoing_to_other_gpus_
 

Protected Member Functions

void ApplyDropoutAtTrainTime ()
 
void ApplyDropoutAtTestTime ()
 

Protected Attributes

const string name_
 
const int num_channels_
 
const bool is_input_
 
const bool is_output_
 
const float dropprob_
 
const bool display_
 
const bool dropout_scale_up_at_train_time_
 
const bool gaussian_dropout_
 
const float max_act_gaussian_dropout_
 
int scale_targets_
 
int image_size_
 
Matrix state_
 
Matrix deriv_
 State (activation) of the layer. More...
 
Matrix data_
 Deriv of the loss function w.r.t. More...
 
Matrix rand_gaussian_
 Data (targets) associated with this layer. More...
 
map< int, Matrixother_states_
 Need to store random variates when doing gaussian dropout. More...
 
map< int, Matrixother_derivs_
 Copies of this layer's state on other gpus. More...
 
ImageDisplayerimg_display_
 Copies of this layer's deriv on other gpus. More...
 
const int gpu_id_
 
set< int > other_incoming_gpu_ids_
 
set< int > other_outgoing_gpu_ids_
 

Detailed Description

The base class for all layers.

Each layer has a state_ and deriv_.

Constructor & Destructor Documentation

Layer::Layer ( const config::Layer &  config)

Instantiate a layer from config.

Member Function Documentation

void Layer::AddIncoming ( Edge e)

Add an incoming edge to this layer.

void Layer::AddOutgoing ( Edge e)

Add an outgoing edge from this layer.

void Layer::AllocateMemory ( int  imgsize,
int  batch_size 
)
virtual

Allocate memory for storing the state and derivative at this layer.

Parameters
imgsizeThe spatial size of the layer (width and height).
batch_sizeThe mini-batch size.

Reimplemented in LogisticLayer, SoftmaxDistLayer, SoftmaxLayer, and LinearLayer.

virtual void Layer::ApplyActivation ( bool  train)
pure virtual

Apply the activation function.

Derived classes must implement this. This method applies the activation function to the state_ and overwrites it.

Parameters
trainIf true, use dropout.

Implemented in LogisticLayer, SoftmaxLayer, ReLULayer, and LinearLayer.

virtual void Layer::ApplyDerivativeOfActivation ( )
pure virtual

Apply the derivative of the activation.

Derived classes must implement this. Computes the derivative w.r.t the inputs to this layer from the derivative w.r.t the outputs of this layer. Applies the derivative of the activation function to deriv_ and overwrites it.

Implemented in LogisticLayer, SoftmaxLayer, ReLULayer, and LinearLayer.

void Layer::ApplyDerivativeofDropout ( )

Apply derivative of dropout.

This method scales the derivative to compensate for dropout.

void Layer::ApplyDropout ( bool  train)

Apply dropout to this layer.

Parameters
trainIf train is true, drop units stochastically, else use all the units.
virtual void Layer::ComputeDeriv ( )
pure virtual

Compute derivative of loss function.

This is applicable only if this layer is an output layer.

Implemented in LogisticLayer, SoftmaxDistLayer, SoftmaxLayer, and LinearLayer.

Matrix& Layer::GetData ( )
inline

Returns a reference to the data at this layer.

Matrix& Layer::GetDeriv ( )
inline

Returns a reference to the deriv at this layer.

Edge* Layer::GetIncomingEdge ( int  index)
inline

Returns the incoming edge by index.

virtual float Layer::GetLoss ( )
pure virtual

Compute the value of the loss function that is displayed during training.

This is applicable only if this layer is an output layer.

Implemented in LogisticLayer, SoftmaxDistLayer, SoftmaxLayer, and LinearLayer.

float Layer::GetLoss2 ( )
virtual

Compute the value of the actual loss function.

This is applicable only if this layer is an output layer.

Reimplemented in SoftmaxLayer.

Matrix& Layer::GetState ( )
inline

Returns a reference to the state of the layer.

Member Data Documentation

Matrix Layer::data_
protected

Deriv of the loss function w.r.t.

the state.

Matrix Layer::deriv_
protected

State (activation) of the layer.

ImageDisplayer* Layer::img_display_
protected

Copies of this layer's deriv on other gpus.

map<int, Matrix> Layer::other_derivs_
protected

Copies of this layer's state on other gpus.

map<int, Matrix> Layer::other_states_
protected

Need to store random variates when doing gaussian dropout.

Matrix Layer::rand_gaussian_
protected

Data (targets) associated with this layer.


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