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

Base layer class. More...

#include <base_layer.h>

Inheritance diagram for singa::Layer:
singa::BridgeDstLayer singa::BridgeSrcLayer singa::ConcateLayer singa::ConvolutionLayer singa::DataLayer singa::DropoutLayer singa::InnerProductLayer singa::LossLayer singa::LRNLayer singa::ParserLayer singa::PoolingLayer singa::PrefetchLayer singa::ReLULayer singa::SliceLayer singa::SplitLayer singa::TanhLayer

Public Member Functions

virtual void Init (const LayerProto &proto)
 Layer initialization. More...
 
void Init (const Layer &other, const vector< int > &shape)
 Copy layer configuration from the other Layer, and use the shape argument to as its data shape.
 
virtual void ToProto (LayerProto *layer_proto, bool copyData)
 TODO(wangsheng) Marshal layer properties and data into google protobuf object (i.e., snapshot). More...
 
virtual void Setup (const LayerProto &proto, const vector< SLayer > &srclayers)=0
 Setup layer properties. More...
 
virtual void Setup ()
 Setup layer properties. More...
 
virtual void SetupAfterPartition (const LayerProto &proto, const vector< int > &shape, const vector< SLayer > &srclayers)=0
 Setup the layer properties except shape. More...
 
virtual void SetupAfterPartition ()
 Setup the layer properties except shape.
 
virtual vector< shared_ptr
< Param > > 
GetParams ()
 Layers that have paramters must overload this function. More...
 
virtual void ComputeFeature (bool training, const vector< SLayer > &srclayers)=0
 Compute features of this layer based on connected layers. More...
 
virtual void ComputeFeature (bool training)
 
virtual void ComputeGradient (const vector< SLayer > &srclayers)=0
 Compute gradients for parameters and connecting layers. More...
 
virtual void ComputeGradient ()
 Compute gradients for parameters and connecting layers.
 
virtual int partition_dimension () const
 Decide on which dimension to do the partitioning. More...
 
virtual ConnectionType connection_type (int k) const
 Return connection type between two layers. More...
 
virtual PartitionType partition_type () const
 
virtual void set_partitionid (int id)
 partition id is the ID of the layer in the original layer.
 
virtual int partitionid () const
 
virtual void set_name (string name)
 
virtual const string type () const
 
const std::string & name () const
 Return name of this layer.
 
const std::string & datablob () const
 
const vector< int > & shape (const Layer *layer) const
 
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)
 
virtual const vector< SLayer > srclayers () const
 return LayerS that connected to this layer
 
virtual const vector< SLayer > dstlayers () const
 return LayerS that this layer connected to
 
virtual const int srclayers_size () const
 
virtual const int dstlayers_size () const
 
virtual void ClearDstLayers ()
 
virtual void ClearSrcLayers ()
 
virtual void AddSrcLayer (SLayer src)
 
virtual void AddDstLayer (SLayer dst)
 
virtual bool is_datalayer () const
 
virtual bool is_parserlayer () const
 
virtual bool is_losslayer () const
 
virtual bool is_bridgesrclayer () const
 
virtual bool is_bridgedstlayer () const
 

Protected Attributes

string name_
 
Blob< float > data_
 
Blob< float > grad_
 
LayerProto layer_proto_
 
vector< SLayer > srclayers_
 
vector< SLayer > dstlayers_
 

Detailed Description

Base layer class.

Children should implement at least Layer::Setup, Layer::ComputeFeature(), Layer::ComputGradient() functions for backpropagation method; TODO(zhaojing) subclass the base layer class to support contrastive divergence, The identifier of each layer is the literal string of the class name without the suffix "Layer", which is used in layer registration and creation.

Member Function Documentation

virtual void singa::Layer::ComputeFeature ( bool  training,
const vector< SLayer > &  srclayers 
)
pure virtual

Compute features of this layer based on connected layers.

Implement forward propagation for BP. TODO(zhaojing) Implement both postive phase and negative phase for CD.

Parameters
trainingtrue if in training phase
srclayerslayers connecting to this layer

Implemented in singa::ParserLayer, singa::PrefetchLayer, singa::DataLayer, singa::BridgeDstLayer, and singa::BridgeSrcLayer.

virtual void singa::Layer::ComputeGradient ( const vector< SLayer > &  srclayers)
pure virtual

Compute gradients for parameters and connecting layers.

Implement backward propagation for BP. TODO(zhaojing) Calculate gradients for parameters for CD.

Parameters
srclayerslayers connecting to this layer.

Implemented in singa::ParserLayer, singa::PrefetchLayer, singa::DataLayer, singa::BridgeDstLayer, and singa::BridgeSrcLayer.

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

Return connection type between two layers.

Currently support two connections: kOneToOne, and kOneToAll. kOneToOne indicates the dst neuron depends on only one neuron from src layer. kOneToAll indicates the dst neuron depends on all neurons from src layer. TODO support kOneToMany.

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

virtual const Blob<float>& singa::Layer::data ( const Layer from) const
inlinevirtual
Returns
a const ref for Blob storing neuron values of this layer for BP

Reimplemented in singa::SliceLayer, singa::PrefetchLayer, and singa::BridgeSrcLayer.

const std::string& singa::Layer::datablob ( ) const
inline
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 value be set.
virtual vector<shared_ptr<Param> > singa::Layer::GetParams ( )
inlinevirtual

Layers that have paramters must overload this function.

Returns
parameters associated with this layer

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

virtual void singa::Layer::Init ( const LayerProto proto)
virtual

Layer initialization.

It simply saves the proto configuation, most initializations are done by Setup().

Parameters
protouser defined layer configuration
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::ParserLayer, singa::LossLayer, singa::SliceLayer, singa::PrefetchLayer, singa::DataLayer, and singa::BridgeSrcLayer.

virtual int singa::Layer::partition_dimension ( ) const
inlinevirtual

Decide on which dimension to do the partitioning.

kLayer, kData, kNone (no partition)

Returns
the partition dimension, -1 for no partition
virtual PartitionType singa::Layer::partition_type ( ) const
inlinevirtual
Returns
partition type of this layer, e.g., kNone, kLayer or kData.

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

virtual void singa::Layer::Setup ( const LayerProto proto,
const vector< SLayer > &  srclayers 
)
pure virtual
virtual void singa::Layer::Setup ( )
virtual

Setup layer properties.

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

Parameters
srclayerslayers connecting to this layer

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

virtual void singa::Layer::SetupAfterPartition ( const LayerProto proto,
const vector< int > &  shape,
const vector< SLayer > &  srclayers 
)
pure virtual

Setup the layer properties except shape.

The shape is already set and passed in to set other properties. properties are set according to shapes of itself and connected layers, and configuration. this should not change the current shape_( shape check is done outside the function).

Implemented in singa::ParserLayer, singa::LossLayer, singa::SplitLayer, singa::SliceLayer, singa::PrefetchLayer, singa::DataLayer, singa::ConcateLayer, singa::TanhLayer, singa::BridgeDstLayer, singa::BridgeSrcLayer, singa::SoftmaxLossLayer, singa::ReLULayer, singa::PoolingLayer, singa::LRNLayer, singa::InnerProductLayer, singa::DropoutLayer, and singa::ConvolutionLayer.

virtual void singa::Layer::ToProto ( LayerProto layer_proto,
bool  copyData 
)
virtual

TODO(wangsheng) Marshal layer properties and data into google protobuf object (i.e., snapshot).

Parameters are marshalled separately into another object (i.e., model).

Parameters
layer_proto
copyDataif true marshal layer data, e.g., feature value

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