12 #ifndef MLPACK_METHODS_ANN_LAYER_CONVOLUTION_HPP 13 #define MLPACK_METHODS_ANN_LAYER_CONVOLUTION_HPP 69 typename ForwardConvolutionRule = NaiveConvolution<ValidConvolution>,
70 typename BackwardConvolutionRule = NaiveConvolution<FullConvolution>,
71 typename GradientConvolutionRule = NaiveConvolution<ValidConvolution>,
72 typename MatType = arma::mat
96 const size_t kernelWidth,
97 const size_t kernelHeight,
98 const size_t strideWidth = 1,
99 const size_t strideHeight = 1,
100 const size_t padW = 0,
101 const size_t padH = 0,
102 const std::string& paddingType =
"none");
124 const size_t kernelWidth,
125 const size_t kernelHeight,
126 const size_t strideWidth,
127 const size_t strideHeight,
128 const std::tuple<size_t, size_t>& padW,
129 const std::tuple<size_t, size_t>& padH,
130 const std::string& paddingType =
"none");
153 void SetWeights(
typename MatType::elem_type* weightsPtr);
162 void Forward(
const MatType& input, MatType& output);
185 const MatType& error,
194 arma::Cube<typename MatType::elem_type>
const&
Weight()
const 199 arma::Cube<typename MatType::elem_type>&
Weight() {
return weight; }
202 MatType
const&
Bias()
const {
return bias; }
204 MatType&
Bias() {
return bias; }
207 size_t const&
Maps()
const {
return maps; }
230 size_t const&
PadHTop()
const {
return padHTop; }
240 size_t const&
PadWLeft()
const {
return padWLeft; }
252 return (maps * inMaps * higherInDimensions * kernelWidth * kernelHeight) +
262 template<
typename Archive>
263 void serialize(Archive& ar,
const uint32_t );
276 size_t ConvOutSize(
const size_t size,
279 const size_t pSideOne,
280 const size_t pSideTwo)
282 return std::floor(size + pSideOne + pSideTwo - k) / s + 1;
288 void InitializeSamePadding();
296 template<
typename eT>
297 void Rotate180(
const arma::Cube<eT>& input, arma::Cube<eT>& output)
299 output = arma::Cube<eT>(input.n_rows, input.n_cols, input.n_slices);
302 for (
size_t s = 0; s < output.n_slices; s++)
303 output.slice(s) = arma::fliplr(arma::flipud(input.slice(s)));
312 template<
typename eT>
313 void Rotate180(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
316 output = arma::fliplr(arma::flipud(input));
353 arma::Cube<typename MatType::elem_type> weight;
359 arma::Cube<typename MatType::elem_type> outputTemp;
365 arma::Cube<typename MatType::elem_type> gTemp;
368 arma::Cube<typename MatType::elem_type> gradientTemp;
374 std::string paddingType;
379 size_t higherInDimensions;
386 NaiveConvolution<ValidConvolution>,
394 #include "convolution_impl.hpp" size_t & PadWRight()
Modify the right padding width.
size_t & StrideWidth()
Modify the stride width.
Implementation of the Convolution class.
void SetWeights(typename MatType::elem_type *weightsPtr)
Reset the layer parameter.
constexpr auto size(Container const &container) noexcept -> decltype(container.size())
MatType const & Bias() const
Get the bias of the layer.
void Gradient(const MatType &, const MatType &error, MatType &gradient)
Calculate the gradient using the output delta and the input activation.
ConvolutionType()
Create the ConvolutionType object.
Linear algebra utility functions, generally performed on matrices or vectors.
size_t const & PadHTop() const
Get the top padding height.
size_t const & PadWRight() const
Get the right padding width.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & KernelHeight()
Modify the kernel height.
arma::Cube< typename MatType::elem_type > & Weight()
Modify the weight of the layer as a cube.
size_t const & Maps() const
Get the number of output maps.
size_t & PadHBottom()
Modify the bottom padding height.
ConvolutionType & operator=(const ConvolutionType &layer)
Copy the given ConvolutionType (but not weights).
size_t & StrideHeight()
Modify the stride height.
size_t const & StrideHeight() const
Get the stride height.
size_t & PadHTop()
Modify the top padding height.
void Backward(const MatType &, const MatType &gy, MatType &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
size_t const & PadWLeft() const
Get the left padding width.
size_t const & PadHBottom() const
Get the bottom padding height.
ConvolutionType * Clone() const
Clone the ConvolutionType object. This handles polymorphism correctly.
MatType & Parameters()
Modify the parameters.
size_t const & KernelWidth() const
Get the kernel width.
size_t WeightSize() const
Get size of weights for the layer.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
void ComputeOutputDimensions()
Compute the output dimensions of the layer based on InputDimensions().
size_t const & StrideWidth() const
Get the stride width.
Computes the two-dimensional convolution.
MatType const & Parameters() const
Get the parameters.
arma::Cube< typename MatType::elem_type > const & Weight() const
Get the weight of the layer as a cube.
void Forward(const MatType &input, MatType &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
size_t & KernelWidth()
Modify the kernel width.
virtual ~ConvolutionType()
A layer is an abstract class implementing common neural networks operations, such as convolution...
MatType & Bias()
Modify the bias of the layer.
size_t & PadWLeft()
Modify the left padding width.
size_t const & KernelHeight() const
Get the kernel height.
ConvolutionType< NaiveConvolution< ValidConvolution >, NaiveConvolution< FullConvolution >, NaiveConvolution< ValidConvolution >, arma::mat > Convolution