12#ifndef MLPACK_METHODS_ANN_LAYER_CONVOLUTION_HPP
13#define MLPACK_METHODS_ANN_LAYER_CONVOLUTION_HPP
42 typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>,
43 typename BackwardConvolutionRule = NaiveConvolution<FullConvolution>,
44 typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>,
45 typename InputDataType = arma::mat,
46 typename OutputDataType = arma::mat
72 const size_t kernelWidth,
73 const size_t kernelHeight,
74 const size_t strideWidth = 1,
75 const size_t strideHeight = 1,
76 const size_t padW = 0,
77 const size_t padH = 0,
78 const size_t inputWidth = 0,
79 const size_t inputHeight = 0,
80 const std::string& paddingType =
"None");
103 const size_t outSize,
104 const size_t kernelWidth,
105 const size_t kernelHeight,
106 const size_t strideWidth,
107 const size_t strideHeight,
108 const std::tuple<size_t, size_t>& padW,
109 const std::tuple<size_t, size_t>& padH,
110 const size_t inputWidth = 0,
111 const size_t inputHeight = 0,
112 const std::string& paddingType =
"None");
126 template<
typename eT>
127 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
138 template<
typename eT>
140 const arma::Mat<eT>& gy,
150 template<
typename eT>
152 const arma::Mat<eT>& error,
153 arma::Mat<eT>& gradient);
161 arma::cube
const&
Weight()
const {
return weight; }
166 arma::mat
const&
Bias()
const {
return bias; }
168 arma::mat&
Bias() {
return bias; }
181 OutputDataType
const&
Delta()
const {
return delta; }
183 OutputDataType&
Delta() {
return delta; }
186 OutputDataType
const&
Gradient()
const {
return gradient; }
259 return (outSize * inSize * kernelWidth * kernelHeight) + outSize;
265 template<
typename Archive>
279 size_t ConvOutSize(
const size_t size,
282 const size_t pSideOne,
283 const size_t pSideTwo)
285 return std::floor(size + pSideOne + pSideTwo - k) / s + 1;
291 void InitializeSamePadding();
299 template<
typename eT>
300 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
302 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
305 for (
size_t s = 0; s < output.n_slices; s++)
306 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
315 template<
typename eT>
316 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
319 output = arma::fliplr(arma::flipud(input));
356 OutputDataType weights;
377 arma::cube outputTemp;
380 arma::cube inputPaddedTemp;
386 arma::cube gradientTemp;
389 ann::Padding<> padding;
392 OutputDataType delta;
395 OutputDataType gradient;
398 InputDataType inputParameter;
401 OutputDataType outputParameter;
409namespace serialization {
412 typename ForwardConvolutionRule,
413 typename BackwardConvolutionRule,
414 typename GradientConvolutionRule,
415 typename InputDataType,
416 typename OutputDataType
419 mlpack::ann::Convolution<ForwardConvolutionRule, BackwardConvolutionRule,
420 GradientConvolutionRule, InputDataType, OutputDataType> >
429#include "convolution_impl.hpp"
Implementation of the Convolution class.
arma::cube const & Weight() const
Get the weight of the layer.
OutputDataType const & Delta() const
Get the delta.
size_t StrideHeight() const
Get the stride height.
OutputDataType const & Parameters() const
Get the parameters.
size_t & PadHTop()
Modify the top padding height.
size_t & InputHeight()
Modify the input height.
size_t PadWLeft() const
Get the left padding width.
size_t InputWidth() const
Get the input width.
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 activ...
arma::cube & Weight()
Modify the weight of the layer.
InputDataType & InputParameter()
Modify the input parameter.
OutputDataType const & OutputParameter() const
Get the output parameter.
size_t & PadHBottom()
Modify the bottom padding height.
size_t InputSize() const
Get the input size.
size_t & InputWidth()
Modify input the width.
size_t KernelWidth() const
Get the kernel width.
Convolution()
Create the Convolution object.
size_t KernelHeight() const
Get the kernel height.
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,...
size_t & StrideWidth()
Modify the stride width.
size_t PadHBottom() const
Get the bottom padding height.
size_t WeightSize() const
Get size of weights for the layer.
arma::mat const & Bias() const
Get the bias of the layer.
size_t & KernelWidth()
Modify the kernel width.
size_t PadWRight() const
Get the right padding width.
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,...
size_t & OutputHeight()
Modify the output height.
size_t & PadWRight()
Modify the right padding width.
size_t OutputHeight() const
Get the output height.
size_t OutputSize() const
Get the output size.
void Gradient(const arma::Mat< eT > &, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
size_t OutputWidth() const
Get the output width.
OutputDataType const & Gradient() const
Get the gradient.
InputDataType const & InputParameter() const
Get the input parameter.
size_t InputHeight() const
Get the input height.
OutputDataType & Gradient()
Modify the gradient.
size_t & KernelHeight()
Modify the kernel height.
size_t & PadWLeft()
Modify the left padding width.
size_t StrideWidth() const
Get the stride width.
size_t & StrideHeight()
Modify the stride height.
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 backw...
OutputDataType & OutputParameter()
Modify the output parameter.
size_t & OutputWidth()
Modify the output width.
size_t PadHTop() const
Get the top padding height.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
arma::mat & Bias()
Modify the bias of the layer.
OutputDataType & Delta()
Modify the delta.
Set the serialization version of the adaboost class.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
BOOST_STATIC_CONSTANT(int, value=1)