ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType > Class Template Reference

Implementation of the Convolution class. More...

Inheritance diagram for ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType >:

Public Member Functions

 ConvolutionType ()
 Create the ConvolutionType object. More...

 
 ConvolutionType (const size_t maps, const size_t kernelWidth, const size_t kernelHeight, const size_t strideWidth=1, const size_t strideHeight=1, const size_t padW=0, const size_t padH=0, const std::string &paddingType="none")
 Create the ConvolutionType object using the specified number of output maps, filter size, stride and padding parameter. More...

 
 ConvolutionType (const size_t maps, const size_t kernelWidth, const size_t kernelHeight, const size_t strideWidth, const size_t strideHeight, const std::tuple< size_t, size_t > &padW, const std::tuple< size_t, size_t > &padH, const std::string &paddingType="none")
 Create the Convolution object using the specified number of input maps, output maps, filter size, stride and padding parameter. More...

 
 ConvolutionType (const ConvolutionType &layer)
 Copy the given ConvolutionType (but not weights). More...

 
 ConvolutionType (ConvolutionType &&)
 Take ownership of the given ConvolutionType (but not weights). More...

 
virtual ~ConvolutionType ()
 
void Backward (const MatType &, const MatType &gy, MatType &g)
 Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backwards through f. More...

 
MatType const & Bias () const
 Get the bias of the layer. More...

 
MatType & Bias ()
 Modify the bias of the layer. More...

 
ConvolutionTypeClone () const
 Clone the ConvolutionType object. This handles polymorphism correctly. More...

 
void ComputeOutputDimensions ()
 Compute the output dimensions of the layer based on InputDimensions(). More...

 
void Forward (const MatType &input, MatType &output)
 Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f. More...

 
void Gradient (const MatType &, const MatType &error, MatType &gradient)
 Calculate the gradient using the output delta and the input activation. More...

 
size_t const & KernelHeight () const
 Get the kernel height. More...

 
size_t & KernelHeight ()
 Modify the kernel height. More...

 
size_t const & KernelWidth () const
 Get the kernel width. More...

 
size_t & KernelWidth ()
 Modify the kernel width. More...

 
size_t const & Maps () const
 Get the number of output maps. More...

 
ConvolutionTypeoperator= (const ConvolutionType &layer)
 Copy the given ConvolutionType (but not weights). More...

 
ConvolutionTypeoperator= (ConvolutionType &&layer)
 Take ownership of the given ConvolutionType (but not weights). More...

 
size_t const & PadHBottom () const
 Get the bottom padding height. More...

 
size_t & PadHBottom ()
 Modify the bottom padding height. More...

 
size_t const & PadHTop () const
 Get the top padding height. More...

 
size_t & PadHTop ()
 Modify the top padding height. More...

 
size_t const & PadWLeft () const
 Get the left padding width. More...

 
size_t & PadWLeft ()
 Modify the left padding width. More...

 
size_t const & PadWRight () const
 Get the right padding width. More...

 
size_t & PadWRight ()
 Modify the right padding width. More...

 
MatType const & Parameters () const
 Get the parameters. More...

 
MatType & Parameters ()
 Modify the parameters. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
 Serialize the layer. More...

 
void SetWeights (typename MatType::elem_type *weightsPtr)
 Reset the layer parameter. More...

 
size_t const & StrideHeight () const
 Get the stride height. More...

 
size_t & StrideHeight ()
 Modify the stride height. More...

 
size_t const & StrideWidth () const
 Get the stride width. More...

 
size_t & StrideWidth ()
 Modify the stride width. More...

 
arma::Cube< typename MatType::elem_type > const & Weight () const
 Get the weight of the layer as a cube. More...

 
arma::Cube< typename MatType::elem_type > & Weight ()
 Modify the weight of the layer as a cube. More...

 
size_t WeightSize () const
 Get size of weights for the layer. More...

 
- Public Member Functions inherited from Layer< MatType >
 Layer ()
 Default constructor. More...

 
 Layer (const Layer &layer)
 Copy constructor. This is not responsible for copying weights! More...

 
 Layer (Layer &&layer)
 Move constructor. This is not responsible for moving weights! More...

 
virtual ~Layer ()
 Default deconstructor. More...

 
virtual void Forward (const MatType &, const MatType &)
 Takes an input and output object, and computes the corresponding loss of the layer. More...

 
const std::vector< size_t > & InputDimensions () const
 Get the input dimensions. More...

 
std::vector< size_t > & InputDimensions ()
 Modify the input dimensions. More...

 
virtual double Loss ()
 Get the layer loss. More...

 
virtual Layeroperator= (const Layer &layer)
 Copy assignment operator. This is not responsible for copying weights! More...

 
virtual Layeroperator= (Layer &&layer)
 Move assignment operator. This is not responsible for moving weights! More...

 
const std::vector< size_t > & OutputDimensions ()
 Get the output dimensions. More...

 
virtual size_t OutputSize () final
 Get the number of elements in the output from this layer. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
 Serialize the layer. More...

 
virtual bool const & Training () const
 Get whether the layer is currently in training mode. More...

 
virtual bool & Training ()
 Modify whether the layer is currently in training mode. More...

 

Additional Inherited Members

- Protected Attributes inherited from Layer< MatType >
std::vector< size_t > inputDimensions
 Logical input dimensions of each point. More...

 
std::vector< size_t > outputDimensions
 Logical output dimensions of each point. More...

 
bool training
 If true, the layer is in training mode; otherwise, it is in testing mode. More...

 
bool validOutputDimensions
 This is true if ComputeOutputDimensions() has been called, and outputDimensions can be considered to be up-to-date. More...

 

Detailed Description


template<typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>, typename BackwardConvolutionRule = NaiveConvolution<FullConvolution>, typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>, typename MatType = arma::mat>
class mlpack::ann::ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType >

Implementation of the Convolution class.

The Convolution class represents a single layer of a neural network. Example usage:

Suppose we want to pass a matrix M (2744x100) to a Convolution layer; in this example, M was obtained from "flattening" 100 images (or Mel cepstral coefficients, if we talk about speech, or whatever you like) of dimension 196x14. In other words, the first 196 columns of each row of M will be made of the 196 columns of the first row of each of the 100 images (or Mel cepstral coefficients). Then the next 295 columns of M (196 - 393) will be made of the 196 columns of the second row of the 100 images (or Mel cepstral coefficients), etc. Given that the size of our 2-D input images is 196x14, the parameters for our Convolution layer will be something like this:

Convolution<> c(1, // Number of input activation maps.
14, // Number of output activation maps.
3, // Filter width.
3, // Filter height.
1, // Stride along width.
1, // Stride along height.
0, // Padding width.
0, // Padding height.
196, // Input width.
14); // Input height.

This Convolution<> layer will treat each column of the input matrix M as a 2-D image (or object) of the original 196x14 size, using this as the input for the 14 filters of this example.

Template Parameters
ForwardConvolutionRuleConvolution to perform forward process.
BackwardConvolutionRuleConvolution to perform backward process.
GradientConvolutionRuleConvolution to calculate gradient.
MatTypeMatrix representation to accept as input and use for computation.

Definition at line 74 of file convolution.hpp.

Constructor & Destructor Documentation

◆ ConvolutionType() [1/5]

◆ ConvolutionType() [2/5]

ConvolutionType ( const size_t  maps,
const size_t  kernelWidth,
const size_t  kernelHeight,
const size_t  strideWidth = 1,
const size_t  strideHeight = 1,
const size_t  padW = 0,
const size_t  padH = 0,
const std::string &  paddingType = "none" 
)

Create the ConvolutionType object using the specified number of output maps, filter size, stride and padding parameter.

Parameters
mapsThe number of output maps.
kernelWidthWidth of the filter/kernel.
kernelHeightHeight of the filter/kernel.
strideWidthStride of filter application in the x direction.
strideHeightStride of filter application in the y direction.
padWPadding width of the input.
padHPadding height of the input.
paddingTypeThe type of padding ("valid" or "same"). Defaults to "none". If not specified or "none", the values for padW and padH will be used.

◆ ConvolutionType() [3/5]

ConvolutionType ( const size_t  maps,
const size_t  kernelWidth,
const size_t  kernelHeight,
const size_t  strideWidth,
const size_t  strideHeight,
const std::tuple< size_t, size_t > &  padW,
const std::tuple< size_t, size_t > &  padH,
const std::string &  paddingType = "none" 
)

Create the Convolution object using the specified number of input maps, output maps, filter size, stride and padding parameter.

Parameters
mapsThe number of output maps.
kernelWidthWidth of the filter/kernel.
kernelHeightHeight of the filter/kernel.
strideWidthStride of filter application in the x direction.
strideHeightStride of filter application in the y direction.
padWA two-value tuple indicating padding widths of the input. The first value is the padding for the left side; the second value is the padding on the right side.
padHA two-value tuple indicating padding heights of the input. The first value is the padding for the top; the second value is the padding on the bottom.
paddingTypeThe type of padding ("valid" or "same"). Defaults to "none". If not specified or "none", the values for padW and padH will be used.

◆ ConvolutionType() [4/5]

ConvolutionType ( const ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType > &  layer)

Copy the given ConvolutionType (but not weights).

◆ ConvolutionType() [5/5]

ConvolutionType ( ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType > &&  )

Take ownership of the given ConvolutionType (but not weights).

◆ ~ConvolutionType()

Member Function Documentation

◆ Backward()

void Backward ( const MatType &  ,
const MatType &  gy,
MatType &  g 
)
virtual

Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backwards through f.

Using the results from the feed forward pass.

Parameters
*(input) The propagated input activation.
gyThe backpropagated error.
gThe calculated gradient.

Reimplemented from Layer< MatType >.

Referenced by ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType >::~ConvolutionType().

◆ Bias() [1/2]

MatType const& Bias ( ) const
inline

Get the bias of the layer.

Definition at line 202 of file convolution.hpp.

◆ Bias() [2/2]

MatType& Bias ( )
inline

Modify the bias of the layer.

Definition at line 204 of file convolution.hpp.

◆ Clone()

◆ ComputeOutputDimensions()

void ComputeOutputDimensions ( )
virtual

◆ Forward()

void Forward ( const MatType &  input,
MatType &  output 
)
virtual

Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f.

Parameters
inputInput data used for evaluating the specified function.
outputResulting output activation.

Reimplemented from Layer< MatType >.

Referenced by ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType >::~ConvolutionType().

◆ Gradient()

void Gradient ( const MatType &  ,
const MatType &  error,
MatType &  gradient 
)
virtual

Calculate the gradient using the output delta and the input activation.

Parameters
inputThe input parameter used for calculating the gradient.
errorThe calculated error.
gradientThe calculated gradient.

Reimplemented from Layer< MatType >.

Referenced by ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType >::~ConvolutionType().

◆ KernelHeight() [1/2]

size_t const& KernelHeight ( ) const
inline

Get the kernel height.

Definition at line 215 of file convolution.hpp.

◆ KernelHeight() [2/2]

size_t& KernelHeight ( )
inline

Modify the kernel height.

Definition at line 217 of file convolution.hpp.

◆ KernelWidth() [1/2]

size_t const& KernelWidth ( ) const
inline

Get the kernel width.

Definition at line 210 of file convolution.hpp.

◆ KernelWidth() [2/2]

size_t& KernelWidth ( )
inline

Modify the kernel width.

Definition at line 212 of file convolution.hpp.

◆ Maps()

size_t const& Maps ( ) const
inline

Get the number of output maps.

Definition at line 207 of file convolution.hpp.

◆ operator=() [1/2]

ConvolutionType& operator= ( const ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType > &  layer)

◆ operator=() [2/2]

ConvolutionType& operator= ( ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType > &&  layer)

Take ownership of the given ConvolutionType (but not weights).

◆ PadHBottom() [1/2]

size_t const& PadHBottom ( ) const
inline

Get the bottom padding height.

Definition at line 235 of file convolution.hpp.

◆ PadHBottom() [2/2]

size_t& PadHBottom ( )
inline

Modify the bottom padding height.

Definition at line 237 of file convolution.hpp.

◆ PadHTop() [1/2]

size_t const& PadHTop ( ) const
inline

Get the top padding height.

Definition at line 230 of file convolution.hpp.

◆ PadHTop() [2/2]

size_t& PadHTop ( )
inline

Modify the top padding height.

Definition at line 232 of file convolution.hpp.

◆ PadWLeft() [1/2]

size_t const& PadWLeft ( ) const
inline

Get the left padding width.

Definition at line 240 of file convolution.hpp.

◆ PadWLeft() [2/2]

size_t& PadWLeft ( )
inline

Modify the left padding width.

Definition at line 242 of file convolution.hpp.

◆ PadWRight() [1/2]

size_t const& PadWRight ( ) const
inline

Get the right padding width.

Definition at line 245 of file convolution.hpp.

◆ PadWRight() [2/2]

size_t& PadWRight ( )
inline

Modify the right padding width.

Definition at line 247 of file convolution.hpp.

◆ Parameters() [1/2]

MatType const& Parameters ( ) const
inlinevirtual

Get the parameters.

Reimplemented from Layer< MatType >.

Definition at line 189 of file convolution.hpp.

◆ Parameters() [2/2]

MatType& Parameters ( )
inlinevirtual

Modify the parameters.

Reimplemented from Layer< MatType >.

Definition at line 191 of file convolution.hpp.

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t   
)

◆ SetWeights()

void SetWeights ( typename MatType::elem_type *  )
virtual

Reset the layer parameter.

The method is called to assigned the allocated memory to the internal layer parameters like weights and biases. The method should be called before the first call of Forward(input, output). If you do not respect this rule, Forward(input, output) and Backward(input, gy, g) might compute incorrect results.

Parameters
weightsPtrThis pointer should be used as the first element of the memory that is allocated for this layer. In general, SetWeights() implementations should use MakeAlias() with weightsPtr to wrap the weights of a layer.

Reimplemented from Layer< MatType >.

Referenced by ConvolutionType< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, MatType >::~ConvolutionType().

◆ StrideHeight() [1/2]

size_t const& StrideHeight ( ) const
inline

Get the stride height.

Definition at line 225 of file convolution.hpp.

◆ StrideHeight() [2/2]

size_t& StrideHeight ( )
inline

Modify the stride height.

Definition at line 227 of file convolution.hpp.

◆ StrideWidth() [1/2]

size_t const& StrideWidth ( ) const
inline

Get the stride width.

Definition at line 220 of file convolution.hpp.

◆ StrideWidth() [2/2]

size_t& StrideWidth ( )
inline

Modify the stride width.

Definition at line 222 of file convolution.hpp.

◆ Weight() [1/2]

arma::Cube<typename MatType::elem_type> const& Weight ( ) const
inline

Get the weight of the layer as a cube.

Definition at line 194 of file convolution.hpp.

◆ Weight() [2/2]

arma::Cube<typename MatType::elem_type>& Weight ( )
inline

Modify the weight of the layer as a cube.

Definition at line 199 of file convolution.hpp.

◆ WeightSize()


The documentation for this class was generated from the following file:
  • /home/jenkins-mlpack/mlpack.org/_src/mlpack-git/src/mlpack/methods/ann/layer/convolution.hpp