12 #ifndef MLPACK_METHODS_ANN_LAYER_CONVOLUTION_HPP 13 #define MLPACK_METHODS_ANN_LAYER_CONVOLUTION_HPP 40 typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>,
41 typename BackwardConvolutionRule = NaiveConvolution<FullConvolution>,
42 typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>,
43 typename InputDataType = arma::mat,
44 typename OutputDataType = arma::mat
73 const size_t padW = 0,
74 const size_t padH = 0,
91 void Forward(
const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
102 template<
typename eT>
103 void Backward(
const arma::Mat<eT>&& ,
114 template<
typename eT>
115 void Gradient(
const arma::Mat<eT>&& ,
116 arma::Mat<eT>&& error,
167 template<
typename Archive>
168 void Serialize(Archive& ar,
const unsigned int );
186 return std::floor(size + p * 2 - k) / s + 1;
195 template<
typename eT>
196 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
198 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
201 for (
size_t s = 0; s < output.n_slices; s++)
202 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
211 template<
typename eT>
212 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
215 output = arma::fliplr(arma::flipud(input));
226 template<
typename eT>
227 void Pad(
const arma::Mat<eT>& input,
230 arma::Mat<eT>& output)
232 if (output.n_rows != input.n_rows + wPad * 2 ||
233 output.n_cols != input.n_cols + hPad * 2)
235 output = arma::zeros(input.n_rows + wPad * 2, input.n_cols + hPad * 2);
238 output.submat(wPad, hPad, wPad + input.n_rows - 1,
239 hPad + input.n_cols - 1) = input;
250 template<
typename eT>
251 void Pad(
const arma::Cube<eT>& input,
254 arma::Cube<eT>& output)
256 output = arma::zeros(input.n_rows + wPad * 2,
257 input.n_cols + hPad * 2, input.n_slices);
259 for (
size_t i = 0; i < input.n_slices; ++i)
261 Pad<double>(input.slice(i), wPad, hPad, output.slice(i));
342 #include "convolution_impl.hpp" size_t outSize
Locally-stored number of output units.
size_t & OutputHeight()
Modify the output height.
OutputDataType gradient
Locally-stored gradient object.
OutputDataType const & Delta() const
Get the delta.
Linear algebra utility functions, generally performed on matrices or vectors.
size_t ConvOutSize(const size_t size, const size_t k, const size_t s, const size_t p)
size_t & InputWidth()
Modify input the width.
OutputDataType const & Parameters() const
Get the parameters.
The core includes that mlpack expects; standard C++ includes and Armadillo.
arma::cube outputTemp
Locally-stored transformed output parameter.
Implementation of the Convolution class.
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
arma::cube inputPaddedTemp
Locally-stored transformed padded input parameter.
InputDataType & InputParameter()
Modify the input parameter.
size_t padH
Locally-stored padding height.
size_t inputHeight
Locally-stored input height.
size_t inSize
Locally-stored number of input units.
size_t kW
Locally-stored filter/kernel width.
size_t & OutputWidth()
Modify the output width.
size_t kH
Locally-stored filter/kernel height.
size_t padW
Locally-stored padding width.
void Pad(const arma::Mat< eT > &input, size_t wPad, size_t hPad, arma::Mat< eT > &output)
arma::mat bias
Locally-stored bias term object.
size_t const & OutputWidth() const
Get the output width.
OutputDataType delta
Locally-stored delta object.
arma::cube gTemp
Locally-stored transformed error parameter.
OutputDataType const & Gradient() const
Get the gradient.
void Pad(const arma::Cube< eT > &input, size_t wPad, size_t hPad, arma::Cube< eT > &output)
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
Locally-stored weight object.
Convolution()
Create the Convolution object.
size_t const & InputWidth() const
Get the input 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 outputHeight
Locally-stored output height.
void Rotate180(const arma::Mat< eT > &input, arma::Mat< eT > &output)
OutputDataType outputParameter
Locally-stored output parameter object.
size_t const & OutputHeight() const
Get the output height.
OutputDataType & Delta()
Modify the delta.
size_t dW
Locally-stored stride of the filter in x-direction.
size_t inputWidth
Locally-stored input width.
arma::cube gradientTemp
Locally-stored transformed gradient parameter.
size_t const & InputHeight() const
Get the input height.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType weights
Locally-stored weight object.
size_t outputWidth
Locally-stored output width.
OutputDataType & OutputParameter()
Modify the output parameter.
void Rotate180(const arma::Cube< eT > &input, arma::Cube< eT > &output)
OutputDataType & Parameters()
Modify the parameters.
size_t & InputHeight()
Modify the input height.
OutputDataType const & OutputParameter() const
Get the output parameter.
InputDataType const & InputParameter() const
Get the input parameter.
InputDataType inputParameter
Locally-stored input parameter object.
arma::cube inputTemp
Locally-stored transformed input parameter.
size_t dH
Locally-stored stride of the filter in y-direction.