mlpack
|
Implementation of the Convolution class. More...
#include <convolution.hpp>
Public Member Functions | |
Convolution () | |
Create the Convolution object. | |
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... | |
void | Reset () |
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 | 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... | |
template<typename eT > | |
void | Gradient (const arma::Mat< eT > &, const arma::Mat< eT > &error, arma::Mat< eT > &gradient) |
OutputDataType const & | Parameters () const |
Get the parameters. | |
OutputDataType & | Parameters () |
Modify the parameters. | |
arma::cube const & | Weight () const |
Get the weight of the layer. | |
arma::cube & | Weight () |
Modify the weight of the layer. | |
arma::mat const & | Bias () const |
Get the bias of the layer. | |
arma::mat & | Bias () |
Modify the bias of the layer. | |
InputDataType const & | InputParameter () const |
Get the input parameter. | |
InputDataType & | InputParameter () |
Modify the input parameter. | |
OutputDataType const & | OutputParameter () const |
Get the output parameter. | |
OutputDataType & | OutputParameter () |
Modify the output parameter. | |
OutputDataType const & | Delta () const |
Get the delta. | |
OutputDataType & | Delta () |
Modify the delta. | |
OutputDataType const & | Gradient () const |
Get the gradient. | |
OutputDataType & | Gradient () |
Modify the gradient. | |
size_t | InputWidth () const |
Get the input width. | |
size_t & | InputWidth () |
Modify input the width. | |
size_t | InputHeight () const |
Get the input height. | |
size_t & | InputHeight () |
Modify the input height. | |
size_t | OutputWidth () const |
Get the output width. | |
size_t & | OutputWidth () |
Modify the output width. | |
size_t | OutputHeight () const |
Get the output height. | |
size_t & | OutputHeight () |
Modify the output height. | |
size_t | InputSize () const |
Get the number of input maps. | |
size_t | OutputSize () const |
Get the number of output maps. | |
size_t | KernelWidth () const |
Get the kernel width. | |
size_t & | KernelWidth () |
Modify the kernel width. | |
size_t | KernelHeight () const |
Get the kernel height. | |
size_t & | KernelHeight () |
Modify the kernel height. | |
size_t | StrideWidth () const |
Get the stride width. | |
size_t & | StrideWidth () |
Modify the stride width. | |
size_t | StrideHeight () const |
Get the stride height. | |
size_t & | StrideHeight () |
Modify the stride height. | |
size_t | PadHTop () const |
Get the top padding height. | |
size_t & | PadHTop () |
Modify the top padding height. | |
size_t | PadHBottom () const |
Get the bottom padding height. | |
size_t & | PadHBottom () |
Modify the bottom padding height. | |
size_t | PadWLeft () const |
Get the left padding width. | |
size_t & | PadWLeft () |
Modify the left padding width. | |
size_t | PadWRight () const |
Get the right padding width. | |
size_t & | PadWRight () |
Modify the right padding width. | |
size_t | WeightSize () const |
Get size of weights for the layer. | |
size_t | InputShape () const |
Get the shape of the input. | |
template<typename Archive > | |
void | serialize (Archive &ar, const uint32_t) |
Serialize the layer. | |
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:
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.
ForwardConvolutionRule | Convolution to perform forward process. |
BackwardConvolutionRule | Convolution to perform backward process. |
GradientConvolutionRule | Convolution to calculate gradient. |
InputDataType | Type of the input data (arma::colvec, arma::mat, arma::sp_mat or arma::cube). |
OutputDataType | Type of the output data (arma::colvec, arma::mat, arma::sp_mat or arma::cube). |
mlpack::ann::Convolution< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, InputDataType, OutputDataType >::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.
inSize | The number of input maps. |
outSize | The number of output maps. |
kernelWidth | Width of the filter/kernel. |
kernelHeight | Height of the filter/kernel. |
strideWidth | Stride of filter application in the x direction. |
strideHeight | Stride of filter application in the y direction. |
padW | Padding width of the input. |
padH | Padding height of the input. |
inputWidth | The width of the input data. |
inputHeight | The height of the input data. |
paddingType | The type of padding (Valid or Same). Defaults to None. |
mlpack::ann::Convolution< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, InputDataType, OutputDataType >::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.
inSize | The number of input maps. |
outSize | The number of output maps. |
kernelWidth | Width of the filter/kernel. |
kernelHeight | Height of the filter/kernel. |
strideWidth | Stride of filter application in the x direction. |
strideHeight | Stride of filter application in the y direction. |
padW | A two-value tuple indicating padding widths of the input. First value is padding at left side. Second value is padding on right side. |
padH | A two-value tuple indicating padding heights of the input. First value is padding at top. Second value is padding on bottom. |
inputWidth | The width of the input data. |
inputHeight | The height of the input data. |
paddingType | The type of padding (Valid or Same). Defaults to None. |
void mlpack::ann::Convolution< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, InputDataType, OutputDataType >::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.
* | (input) The propagated input activation. |
gy | The backpropagated error. |
g | The calculated gradient. |
void mlpack::ann::Convolution< ForwardConvolutionRule, BackwardConvolutionRule, GradientConvolutionRule, InputDataType, OutputDataType >::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.
input | Input data used for evaluating the specified function. |
output | Resulting output activation. |