12 #ifndef MLPACK_METHODS_ANN_LAYER_CONVOLUTION_HPP 13 #define MLPACK_METHODS_ANN_LAYER_CONVOLUTION_HPP 41 typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>,
42 typename BackwardConvolutionRule = NaiveConvolution<FullConvolution>,
43 typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>,
44 typename InputDataType = arma::mat,
45 typename OutputDataType = arma::mat
71 const size_t kernelWidth,
72 const size_t kernelHeight,
73 const size_t strideWidth = 1,
74 const size_t strideHeight = 1,
75 const size_t padW = 0,
76 const size_t padH = 0,
77 const size_t inputWidth = 0,
78 const size_t inputHeight = 0,
79 const std::string& paddingType =
"None");
102 const size_t outSize,
103 const size_t kernelWidth,
104 const size_t kernelHeight,
105 const size_t strideWidth,
106 const size_t strideHeight,
107 const std::tuple<size_t, size_t>& padW,
108 const std::tuple<size_t, size_t>& padH,
109 const size_t inputWidth = 0,
110 const size_t inputHeight = 0,
111 const std::string& paddingType =
"None");
125 template<
typename eT>
126 void Forward(
const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
137 template<
typename eT>
138 void Backward(
const arma::Mat<eT>&& ,
149 template<
typename eT>
150 void Gradient(
const arma::Mat<eT>&& ,
151 arma::Mat<eT>&& error,
152 arma::Mat<eT>&& gradient);
170 const OutputDataType&
Delta()
const {
return delta; }
172 OutputDataType&
Delta() {
return delta; }
175 const OutputDataType&
Gradient()
const {
return gradient; }
246 arma::mat&
Bias() {
return bias; }
251 template<
typename Archive>
252 void serialize(Archive& ar,
const unsigned int );
265 size_t ConvOutSize(
const size_t size,
268 const size_t pSideOne,
269 const size_t pSideTwo)
271 return std::floor(size + pSideOne + pSideTwo - k) / s + 1;
277 void InitializeSamePadding();
285 template<
typename eT>
286 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
288 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
291 for (
size_t s = 0; s < output.n_slices; s++)
292 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
301 template<
typename eT>
302 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
305 output = arma::fliplr(arma::flipud(input));
342 OutputDataType weights;
363 arma::cube outputTemp;
366 arma::cube inputTemp;
369 arma::cube inputPaddedTemp;
375 arma::cube gradientTemp;
381 OutputDataType delta;
384 OutputDataType gradient;
387 InputDataType inputParameter;
390 OutputDataType outputParameter;
398 namespace serialization {
401 typename ForwardConvolutionRule,
402 typename BackwardConvolutionRule,
403 typename GradientConvolutionRule,
404 typename InputDataType,
405 typename OutputDataType
408 mlpack::ann::Convolution<ForwardConvolutionRule, BackwardConvolutionRule,
409 GradientConvolutionRule, InputDataType, OutputDataType> >
411 BOOST_STATIC_CONSTANT(
int, value = 1);
418 #include "convolution_impl.hpp" size_t & PadWLeft()
Modify the left padding width.
void Backward(const arma::Mat< eT > &&, 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 & PadWRight()
Modify the right padding width.
Set the serialization version of the adaboost class.
const OutputDataType & Parameters() const
Get the parameters.
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.
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.