Apache Singa
A General Distributed Deep Learning Library
|
The base layer class. More...
#include <layer.h>
Public Member Functions | |
void | Setup (const Shape &in_shape, const string &proto_str) |
Set meta data fields from a string representing a proto message. More... | |
void | Setup (const vector< Shape > &in_shapes, const string &proto_str) |
'in_shapes' is the shape of the input feature for one sample | |
virtual | ~Layer () |
Destruct objects created by this layer. | |
virtual const std::string | layer_type () const |
Each layer sub-class would optionaly have a type name. More... | |
virtual void | Setup (const Shape &in_sample, const LayerConf &conf) |
Set meta data fields configured in 'conf' (a proto message). More... | |
virtual void | Setup (const vector< Shape > &in_samples, const LayerConf &conf) |
Used for layers that have multiple input tensors, e.g., concatenate layer. | |
virtual const Shape | GetOutputSampleShape () const |
Return the shape of the generated Tensor without the batchsize dimension. | |
virtual const Shape | GetOutputSampleShape (int k) |
Return the shape of the k-th generated tensor without the batchsize dimension. More... | |
virtual const Tensor | Forward (int flag, const Tensor &input) |
Do feature transformation for the given 'input' tensor (denoted as x). More... | |
virtual const vector< Tensor > | Forward (int flag, const vector< Tensor > &inputs) |
Do feature transformation for the given 'input' tensor (denoted as x). More... | |
virtual const std::pair< Tensor, vector< Tensor > > | Backward (int flag, const Tensor &grad) |
Compute gradients of this layer. More... | |
virtual const std::pair< vector< Tensor >, vector< Tensor > > | Backward (int flag, const vector< Tensor > &grads) |
virtual void | ToDevice (std::shared_ptr< Device > device) |
Clone the layer to the given device. More... | |
virtual void | AsType (DataType dtype) |
Set the data type of Tensor in this layer. | |
virtual void | ToProto (LayerConf *conf) const |
Serialize the layer info (including params) into a LayerConf proto message. | |
std::string | ToProtoStr () const |
Serialize the layer info, including params_, into a string representing a LayerParameter message. More... | |
const vector< ParamSpec > | param_specs () |
Return specs/configuration of all parameter instances of this layer. More... | |
const ParamSpec & | param_specs (size_t i) |
Return the i-th ParamSpec. | |
virtual const vector< Tensor > | param_values () |
Return pointers to parameter Tensor s. | |
const vector< string > | param_names () |
Return names of all parmaeters. | |
const string & | param_name (size_t i) |
Return the 'i'-th parameter name. | |
const std::string | name () const |
Each layer instance would optionally have a name. More... | |
Protected Attributes | |
std::string | name_ |
vector< ParamSpec > | param_specs_ |
The base layer class.
Generally, a layer conducts feature transformation against a set of Tensor to generate a set of Tensor. Each layer may have some parameters.
|
inlinevirtual |
Compute gradients of this layer.
Specifically, there are two types of gradients:
Do feature transformation for the given 'input' tensor (denoted as x).
'flag' is either kTrain or kEval for feed-forward nets, and would be used for other phases of training other nets. For example, when training RBM, we may create an alias of this function as ComputeFeature where flag could be kPositive and kNegative. It will return a Tensor (denoted as y). If the 'input' or 'output' is required for computing the gradients in Backward(), then buffer them as internal data.
|
inlinevirtual |
Do feature transformation for the given 'input' tensor (denoted as x).
'flag' is either kTrain or kEval for feed-forward nets, and would be used for other phases of training other nets. For example, when training RBM, we may create an alias of this function as ComputeFeature where flag could be kPositive and kNegative. It will return a Tensor (denoted as y). If the 'input' or 'output' is required for computing the gradients in Backward(), then buffer them as internal data. Accept multiple input tensors and generate multiple output tensors. If there is only one input tensor, it will call Forward(int, const Tensor&) by default. Users can override this function for layers who generate more than one outputs.
|
inlinevirtual |
Return the shape of the k-th generated tensor without the batchsize dimension.
Used for layers that generate multiple tensors.
|
inlinevirtual |
Each layer sub-class would optionaly have a type name.
Used for debugging and logging.
|
inline |
Each layer instance would optionally have a name.
Used for debugging and logging.
|
inline |
Return specs/configuration of all parameter instances of this layer.
ParamSpec.
|
inline |
Set meta data fields from a string representing a proto message.
'in_shape' is the shape of the input feature for one sample
|
inlinevirtual |
Set meta data fields configured in 'conf' (a proto message).
Some layers would use input tensor shapes for setting its parameter shapes (e.g, desen layer and convolution layer). 'in_shape' provides such shape info. It represents the shape of the Tensor (with a single sample) from the last layer. After calling Setup, the shape info of parameters should be accssed correctly. Internal buffer/fields are set assuming batchsize is 1.
|
inlinevirtual |
|
inline |
Serialize the layer info, including params_, into a string representing a LayerParameter message.