Apache SINGA
A distributed deep learning platform .
 All Classes Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
singa::Layer Class Referenceabstract

Base layer class. More...

#include <layer.h>

Inheritance diagram for singa::Layer:
singa::ConnectionLayer singa::InputLayer singa::LossLayer singa::NeuronLayer singa::PrefetchLayer singa::RBMLayer singa::SigmoidLayer singa::BridgeLayer singa::ConcateLayer singa::SliceLayer singa::SplitLayer singa::DataLayer singa::ParserLayer singa::EuclideanLossLayer singa::SoftmaxLossLayer singa::ConvolutionLayer singa::DropoutLayer singa::InnerProductLayer singa::LRNLayer singa::PoolingLayer singa::ReLULayer singa::STanhLayer singa::RBMHidLayer singa::RBMVisLayer

Public Member Functions

virtual void Setup (const LayerProto &proto, int npartitions=1)
 Setup layer properties. More...
 
virtual void ComputeFeature (int flag, Metric *perf)=0
 Compute features of this layer based on connected layers. More...
 
virtual void ComputeGradient (int flag, Metric *perf)=0
 Compute gradients for parameters and connected layers. More...
 
virtual const std::vector
< Param * > 
GetParams () const
 Layers that have paramters must override this function. More...
 
virtual ConnectionType src_neuron_connection (int k) const
 Return the connection type between one neuron of this layer and its source layer. More...
 
virtual ConnectionType dst_layer_connection () const
 Return the connection type of this layer and all dst layers. More...
 
virtual const std::string DebugString (int step, int flag)
 For print debug info about each layer, e.g., norm of feature vector, norm of parameters. More...
 
int partition_dim () const
 
int partition_id () const
 
int type () const
 
const std::string & name () const
 Return name of this layer.
 
virtual const Blob< float > & data (const Layer *from) const
 
virtual Blob< float > * mutable_data (const Layer *from)
 
virtual const Blob< float > & grad (const Layer *from) const
 
virtual Blob< float > * mutable_grad (const Layer *from)
 
const std::vector< Layer * > srclayers () const
 return LayerS that connected to this layer
 
const std::vector< Layer * > dstlayers () const
 return LayerS that this layer connected to
 
int srclayers_size () const
 
int dstlayers_size () const
 
void clear_dstlayers ()
 
void clear_srclayers ()
 
void add_srclayer (Layer *src)
 
void add_dstlayer (Layer *dst)
 

Static Public Member Functions

static LayerCreate (const LayerProto &proto)
 

Protected Attributes

LayerProto layer_proto_
 
Blob< float > data_
 
Blob< float > grad_
 
std::vector< Layer * > srclayers_
 
std::vector< Layer * > dstlayers_
 

Detailed Description

Base layer class.

Children should implement at least Layer::ComputeFeature() and Layer::ComputGradient() functions for contrastive-divergence/back-propagation algorithm.

Member Function Documentation

virtual void singa::Layer::ComputeFeature ( int  flag,
Metric perf 
)
pure virtual
virtual void singa::Layer::ComputeGradient ( int  flag,
Metric perf 
)
pure virtual
virtual const Blob<float>& singa::Layer::data ( const Layer from) const
inlinevirtual
Returns
name of src data blob, used by prefetch layer to locate the data blob in parser layers; The default value is "unknown"; If the src layer is the prefetch layer and there are more than one parser layers, this value be set. const std::string &datablob() const { return layer_proto_.datablob(); }
a const ref for Blob storing neuron values of this layer for BP

Reimplemented in singa::BridgeSrcLayer.

virtual const std::string singa::Layer::DebugString ( int  step,
int  flag 
)
virtual

For print debug info about each layer, e.g., norm of feature vector, norm of parameters.

Parameters
steptraining/test/validation step
flagused to get the calling phase, e.g., forward of training (kForward | kTrain)
Returns
debug info about this layer.
virtual ConnectionType singa::Layer::dst_layer_connection ( ) const
inlinevirtual

Return the connection type of this layer and all dst layers.

Currently support two connection types: kOneToOne, and kOneToMany. kOneToOne indicates the users implement the ComputeFeature and ComputeGradient function considering only one dest layer. In this case, a SplitLayer will be added automatically to connect this layer with all dest layer. kOneToMany indicates the users has already considered multiple dest layers in the implementation.

Returns
connection type default is kOneToOne.

Reimplemented in singa::ParserLayer, and singa::DataLayer.

virtual const std::vector<Param*> singa::Layer::GetParams ( ) const
inlinevirtual

Layers that have paramters must override this function.

Parameters
flagused to get the calling phase, e.g., forward of training (kForward | kTrain)
Returns
parameters associated with this layer

Reimplemented in singa::RBMLayer, singa::InnerProductLayer, and singa::ConvolutionLayer.

virtual Blob<float>* singa::Layer::mutable_grad ( const Layer from)
inlinevirtual
Returns
a pointer to storing neuron grads of this layer for BP

Reimplemented in singa::LossLayer, singa::ParserLayer, singa::BridgeSrcLayer, and singa::DataLayer.

int singa::Layer::partition_dim ( ) const
inline
Returns
partition dimension of this layer. -1 for no partition; 0 for partition the mini-batch into sub-mini-batch. 1 for partition the layer feature vector into sub-vector.
virtual void singa::Layer::Setup ( const LayerProto &  proto,
int  npartitions = 1 
)
inlinevirtual

Setup layer properties.

Setup the shapes for data and parameters, also setup some properties based on the layer configuration and connected layers.

Parameters
protolayer configuration.
npartitionsnum of total partitions of the original layer. This layer should be setup as one partition.

Reimplemented in singa::RBMHidLayer, singa::RBMVisLayer, singa::RBMLayer, singa::SigmoidLayer, singa::RGBImageLayer, singa::STanhLayer, singa::MnistLayer, singa::LabelLayer, singa::InnerProductLayer, singa::SplitLayer, singa::ReLULayer, singa::CPoolingLayer, singa::SliceLayer, singa::PoolingLayer, singa::ConcateLayer, singa::ShardDataLayer, singa::DropoutLayer, singa::BridgeDstLayer, singa::SoftmaxLossLayer, and singa::ConvolutionLayer.

virtual ConnectionType singa::Layer::src_neuron_connection ( int  k) const
inlinevirtual

Return the connection type between one neuron of this layer and its source layer.

Currently support two connection types: kOneToOne, and kOneToAll. kOneToOne indicates the neuron depends on only one neuron from src layer. kOneToAll indicates the neuron depends on all neurons from src layer. TODO(wangwei) support kOneToMany.

Parameters
kindex of source layer (current only support k = 0.
connectiontype.

Reimplemented in singa::SoftmaxLossLayer, and singa::ConvolutionLayer.


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