Convolution< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, InputDataType, OutputDataType > Class Template Reference

Implementation of the Convolution class. More...

Public Member Functions

 Convolution ()
 Create the Convolution object. More...

 
 Convolution (const size_t inSize, const size_t outSize, 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 size_t inputWidth=0, const size_t inputHeight=0, 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...

 
 Convolution (const size_t inSize, const size_t outSize, 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 size_t inputWidth=0, const size_t inputHeight=0, 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...

 
template
<
typename
eT
>
void Backward (const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
 Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backwards through f. More...

 
arma::mat const & Bias () const
 Get the bias of the layer. More...

 
arma::mat & Bias ()
 Modify the bias of the layer. More...

 
OutputDataType const & Delta () const
 Get the delta. More...

 
OutputDataType & Delta ()
 Modify the delta. More...

 
template
<
typename
eT
>
void Forward (const arma::Mat< eT > &input, arma::Mat< eT > &output)
 Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f. More...

 
template
<
typename
eT
>
void Gradient (const arma::Mat< eT > &, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
 
OutputDataType const & Gradient () const
 Get the gradient. More...

 
OutputDataType & Gradient ()
 Modify the gradient. More...

 
size_t InputHeight () const
 Get the input height. More...

 
size_t & InputHeight ()
 Modify the input height. More...

 
InputDataType const & InputParameter () const
 Get the input parameter. More...

 
InputDataType & InputParameter ()
 Modify the input parameter. More...

 
size_t InputShape () const
 Get the shape of the input. More...

 
size_t InputSize () const
 Get the number of input maps. More...

 
size_t InputWidth () const
 Get the input width. More...

 
size_t & InputWidth ()
 Modify input the width. More...

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

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

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

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

 
size_t OutputHeight () const
 Get the output height. More...

 
size_t & OutputHeight ()
 Modify the output height. More...

 
OutputDataType const & OutputParameter () const
 Get the output parameter. More...

 
OutputDataType & OutputParameter ()
 Modify the output parameter. More...

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

 
size_t OutputWidth () const
 Get the output width. More...

 
size_t & OutputWidth ()
 Modify the output width. More...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

 
arma::cube const & Weight () const
 Get the weight of the layer. More...

 
arma::cube & Weight ()
 Modify the weight of the layer. More...

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

 

Detailed Description


template<typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>, typename BackwardConvolutionRule = NaiveConvolution<FullConvolution>, typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>, typename InputDataType = arma::mat, typename OutputDataType = arma::mat>
class mlpack::ann::Convolution< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, InputDataType, OutputDataType >

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.
InputDataTypeType of the input data (arma::colvec, arma::mat, arma::sp_mat or arma::cube).
OutputDataTypeType of the output data (arma::colvec, arma::mat, arma::sp_mat or arma::cube).

Definition at line 77 of file convolution.hpp.

Constructor & Destructor Documentation

◆ Convolution() [1/3]

Create the Convolution object.

◆ Convolution() [2/3]

Convolution ( const size_t  inSize,
const size_t  outSize,
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 size_t  inputWidth = 0,
const size_t  inputHeight = 0,
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
inSizeThe number of input maps.
outSizeThe 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.
inputWidthThe width of the input data.
inputHeightThe height of the input data.
paddingTypeThe type of padding (Valid or Same). Defaults to None.

◆ Convolution() [3/3]

Convolution ( const size_t  inSize,
const size_t  outSize,
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 size_t  inputWidth = 0,
const size_t  inputHeight = 0,
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
inSizeThe number of input maps.
outSizeThe 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. First value is padding at left side. Second value is padding on right side.
padHA two-value tuple indicating padding heights of the input. First value is padding at top. Second value is padding on bottom.
inputWidthThe width of the input data.
inputHeightThe height of the input data.
paddingTypeThe type of padding (Valid or Same). Defaults to None.

Member Function Documentation

◆ Backward()

void Backward ( const arma::Mat< eT > &  ,
const arma::Mat< eT > &  gy,
arma::Mat< eT > &  g 
)

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.

◆ Bias() [1/2]

arma::mat const& Bias ( ) const
inline

Get the bias of the layer.

Definition at line 195 of file convolution.hpp.

◆ Bias() [2/2]

arma::mat& Bias ( )
inline

Modify the bias of the layer.

Definition at line 197 of file convolution.hpp.

◆ Delta() [1/2]

OutputDataType const& Delta ( ) const
inline

Get the delta.

Definition at line 210 of file convolution.hpp.

◆ Delta() [2/2]

OutputDataType& Delta ( )
inline

Modify the delta.

Definition at line 212 of file convolution.hpp.

◆ Forward()

void Forward ( const arma::Mat< eT > &  input,
arma::Mat< eT > &  output 
)

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.

◆ Gradient() [1/3]

void Gradient ( const arma::Mat< eT > &  ,
const arma::Mat< eT > &  error,
arma::Mat< eT > &  gradient 
)

◆ Gradient() [2/3]

OutputDataType const& Gradient ( ) const
inline

Get the gradient.

Definition at line 215 of file convolution.hpp.

◆ Gradient() [3/3]

OutputDataType& Gradient ( )
inline

Modify the gradient.

Definition at line 217 of file convolution.hpp.

◆ InputHeight() [1/2]

size_t InputHeight ( ) const
inline

Get the input height.

Definition at line 225 of file convolution.hpp.

◆ InputHeight() [2/2]

size_t& InputHeight ( )
inline

Modify the input height.

Definition at line 227 of file convolution.hpp.

◆ InputParameter() [1/2]

InputDataType const& InputParameter ( ) const
inline

Get the input parameter.

Definition at line 200 of file convolution.hpp.

◆ InputParameter() [2/2]

InputDataType& InputParameter ( )
inline

Modify the input parameter.

Definition at line 202 of file convolution.hpp.

◆ InputShape()

size_t InputShape ( ) const
inline

◆ InputSize()

size_t InputSize ( ) const
inline

Get the number of input maps.

Definition at line 240 of file convolution.hpp.

◆ InputWidth() [1/2]

size_t InputWidth ( ) const
inline

Get the input width.

Definition at line 220 of file convolution.hpp.

◆ InputWidth() [2/2]

size_t& InputWidth ( )
inline

Modify input the width.

Definition at line 222 of file convolution.hpp.

◆ KernelHeight() [1/2]

size_t KernelHeight ( ) const
inline

Get the kernel height.

Definition at line 251 of file convolution.hpp.

◆ KernelHeight() [2/2]

size_t& KernelHeight ( )
inline

Modify the kernel height.

Definition at line 253 of file convolution.hpp.

◆ KernelWidth() [1/2]

size_t KernelWidth ( ) const
inline

Get the kernel width.

Definition at line 246 of file convolution.hpp.

◆ KernelWidth() [2/2]

size_t& KernelWidth ( )
inline

Modify the kernel width.

Definition at line 248 of file convolution.hpp.

◆ OutputHeight() [1/2]

size_t OutputHeight ( ) const
inline

Get the output height.

Definition at line 235 of file convolution.hpp.

◆ OutputHeight() [2/2]

size_t& OutputHeight ( )
inline

Modify the output height.

Definition at line 237 of file convolution.hpp.

◆ OutputParameter() [1/2]

OutputDataType const& OutputParameter ( ) const
inline

Get the output parameter.

Definition at line 205 of file convolution.hpp.

◆ OutputParameter() [2/2]

OutputDataType& OutputParameter ( )
inline

Modify the output parameter.

Definition at line 207 of file convolution.hpp.

◆ OutputSize()

size_t OutputSize ( ) const
inline

Get the number of output maps.

Definition at line 243 of file convolution.hpp.

◆ OutputWidth() [1/2]

size_t OutputWidth ( ) const
inline

Get the output width.

Definition at line 230 of file convolution.hpp.

◆ OutputWidth() [2/2]

size_t& OutputWidth ( )
inline

Modify the output width.

Definition at line 232 of file convolution.hpp.

◆ PadHBottom() [1/2]

size_t PadHBottom ( ) const
inline

Get the bottom padding height.

Definition at line 271 of file convolution.hpp.

◆ PadHBottom() [2/2]

size_t& PadHBottom ( )
inline

Modify the bottom padding height.

Definition at line 273 of file convolution.hpp.

◆ PadHTop() [1/2]

size_t PadHTop ( ) const
inline

Get the top padding height.

Definition at line 266 of file convolution.hpp.

◆ PadHTop() [2/2]

size_t& PadHTop ( )
inline

Modify the top padding height.

Definition at line 268 of file convolution.hpp.

◆ PadWLeft() [1/2]

size_t PadWLeft ( ) const
inline

Get the left padding width.

Definition at line 276 of file convolution.hpp.

◆ PadWLeft() [2/2]

size_t& PadWLeft ( )
inline

Modify the left padding width.

Definition at line 278 of file convolution.hpp.

◆ PadWRight() [1/2]

size_t PadWRight ( ) const
inline

Get the right padding width.

Definition at line 281 of file convolution.hpp.

◆ PadWRight() [2/2]

size_t& PadWRight ( )
inline

Modify the right padding width.

Definition at line 283 of file convolution.hpp.

◆ Parameters() [1/2]

OutputDataType const& Parameters ( ) const
inline

Get the parameters.

Definition at line 185 of file convolution.hpp.

◆ Parameters() [2/2]

OutputDataType& Parameters ( )
inline

Modify the parameters.

Definition at line 187 of file convolution.hpp.

◆ Reset()

void Reset ( )

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t   
)

◆ StrideHeight() [1/2]

size_t StrideHeight ( ) const
inline

Get the stride height.

Definition at line 261 of file convolution.hpp.

◆ StrideHeight() [2/2]

size_t& StrideHeight ( )
inline

Modify the stride height.

Definition at line 263 of file convolution.hpp.

◆ StrideWidth() [1/2]

size_t StrideWidth ( ) const
inline

Get the stride width.

Definition at line 256 of file convolution.hpp.

◆ StrideWidth() [2/2]

size_t& StrideWidth ( )
inline

Modify the stride width.

Definition at line 258 of file convolution.hpp.

◆ Weight() [1/2]

arma::cube const& Weight ( ) const
inline

Get the weight of the layer.

Definition at line 190 of file convolution.hpp.

◆ Weight() [2/2]

arma::cube& Weight ( )
inline

Modify the weight of the layer.

Definition at line 192 of file convolution.hpp.

◆ WeightSize()

size_t WeightSize ( ) const
inline

Get size of weights for the layer.

Definition at line 286 of file convolution.hpp.


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