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>
139 void Backward(
const arma::Mat<eT>& ,
140 const arma::Mat<eT>& gy,
150 template<
typename eT>
151 void Gradient(
const arma::Mat<eT>& ,
152 const arma::Mat<eT>& error,
153 arma::Mat<eT>& gradient);
171 const OutputDataType&
Delta()
const {
return delta; }
173 OutputDataType&
Delta() {
return delta; }
176 const OutputDataType&
Gradient()
const {
return gradient; }
247 arma::mat&
Bias() {
return bias; }
252 template<
typename Archive>
253 void serialize(Archive& ar,
const unsigned int );
266 size_t ConvOutSize(
const size_t size,
269 const size_t pSideOne,
270 const size_t pSideTwo)
272 return std::floor(size + pSideOne + pSideTwo - k) / s + 1;
278 void InitializeSamePadding();
286 template<
typename eT>
287 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
289 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
292 for (
size_t s = 0; s < output.n_slices; s++)
293 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
302 template<
typename eT>
303 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
306 output = arma::fliplr(arma::flipud(input));
343 OutputDataType weights;
364 arma::cube outputTemp;
367 arma::cube inputPaddedTemp;
373 arma::cube gradientTemp;
379 OutputDataType delta;
382 OutputDataType gradient;
385 InputDataType inputParameter;
388 OutputDataType outputParameter;
396 namespace serialization {
399 typename ForwardConvolutionRule,
400 typename BackwardConvolutionRule,
401 typename GradientConvolutionRule,
402 typename InputDataType,
403 typename OutputDataType
406 mlpack::ann::Convolution<ForwardConvolutionRule, BackwardConvolutionRule,
407 GradientConvolutionRule, InputDataType, OutputDataType> >
409 BOOST_STATIC_CONSTANT(
int, value = 1);
416 #include "convolution_impl.hpp" size_t & PadWLeft()
Modify the left padding width.
size_t & PadWRight()
Modify the right padding width.
Set the serialization version of the adaboost class.
const OutputDataType & Parameters() const
Get the parameters.
Linear algebra utility functions, generally performed on matrices or vectors.
Implementation of the Padding module class.
const InputDataType & InputParameter() const
Get the input parameter.
size_t & OutputHeight()
Modify the output height.
The core includes that mlpack expects; standard C++ includes and Armadillo.
const size_t & InputHeight() const
Get the input height.
Implementation of the Convolution class.
size_t KernelHeight() const
Get the kernel height.
size_t PadWRight() const
Get the right padding width.
size_t KernelWidth() const
Get the kernel width.
size_t PadHTop() const
Get the top padding height.
OutputDataType & Gradient()
Modify the gradient.
size_t StrideHeight() const
Get the stride height.
InputDataType & InputParameter()
Modify the input parameter.
size_t InputSize() const
Get the input size.
size_t & KernelHeight()
Modify the kernel height.
size_t & InputHeight()
Modify the input height.
arma::mat & Bias()
Modify the bias weights of the layer.
size_t & PadHTop()
Modify the top padding height.
const size_t & OutputHeight() const
Get the output height.
const OutputDataType & Delta() const
Get the delta.
size_t StrideWidth() const
Get the stride width.
const size_t & OutputWidth() const
Get the output 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...
const OutputDataType & Gradient() const
Get the gradient.
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...
size_t & InputWidth()
Modify input the width.
OutputDataType & Parameters()
Modify the parameters.
size_t & PadHBottom()
Modify the bottom padding height.
size_t PadWLeft() const
Get the left padding width.
const size_t & InputWidth() const
Get the input width.
size_t & StrideHeight()
Modify the stride height.
size_t & OutputWidth()
Modify the output width.
const OutputDataType & OutputParameter() const
Get the output parameter.
OutputDataType & Delta()
Modify the delta.
OutputDataType & OutputParameter()
Modify the output parameter.
Convolution()
Create the Convolution object.
size_t & KernelWidth()
Modify the kernel width.
size_t & StrideWidth()
Modify the stride width.
size_t PadHBottom() const
Get the bottom padding height.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
size_t OutputSize() const
Get the output size.