13#ifndef MLPACK_METHODS_ANN_LAYER_MEAN_POOLING_HPP
14#define MLPACK_METHODS_ANN_LAYER_MEAN_POOLING_HPP
30 typename InputDataType = arma::mat,
31 typename OutputDataType = arma::mat
49 const size_t kernelHeight,
50 const size_t strideWidth = 1,
51 const size_t strideHeight = 1,
52 const bool floor =
true);
62 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
75 const arma::Mat<eT>& gy,
84 OutputDataType
const&
Delta()
const {
return delta; }
86 OutputDataType&
Delta() {
return delta; }
135 bool const&
Floor()
const {
return floor; }
147 template<
typename Archive>
157 template<
typename eT>
158 void Pooling(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
160 for (
size_t j = 0, colidx = 0; j < output.n_cols;
161 ++j, colidx += strideHeight)
163 for (
size_t i = 0, rowidx = 0; i < output.n_rows;
164 ++i, rowidx += strideWidth)
166 arma::mat subInput = input(
167 arma::span(rowidx, rowidx + kernelWidth - 1 - offset),
168 arma::span(colidx, colidx + kernelHeight - 1 - offset));
170 output(i, j) = arma::mean(arma::mean(subInput));
181 template<
typename eT>
182 void Unpooling(
const arma::Mat<eT>& input,
183 const arma::Mat<eT>& error,
184 arma::Mat<eT>& output)
186 const size_t rStep = input.n_rows / error.n_rows - offset;
187 const size_t cStep = input.n_cols / error.n_cols - offset;
189 arma::Mat<eT> unpooledError;
190 for (
size_t j = 0; j < input.n_cols - cStep; j += cStep)
192 for (
size_t i = 0; i < input.n_rows - rStep; i += rStep)
194 const arma::Mat<eT>& inputArea = input(arma::span(i, i + rStep - 1),
195 arma::span(j, j + cStep - 1));
197 unpooledError = arma::Mat<eT>(inputArea.n_rows, inputArea.n_cols);
198 unpooledError.fill(error(i / rStep, j / cStep) / inputArea.n_elem);
200 output(arma::span(i, i + rStep - 1 - offset),
201 arma::span(j, j + cStep - 1 - offset)) += unpooledError;
252 arma::cube outputTemp;
255 arma::cube inputTemp;
261 OutputDataType delta;
264 OutputDataType gradient;
267 OutputDataType outputParameter;
275#include "mean_pooling_impl.hpp"
Implementation of the MeanPooling.
OutputDataType const & Delta() const
Get the delta.
size_t StrideHeight() const
Get the stride height.
size_t const & OutputHeight() const
Get the output height.
size_t & InputHeight()
Modify the input height.
bool const & Floor() const
Get the value of the rounding operation.
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...
OutputDataType const & OutputParameter() const
Get the output parameter.
MeanPooling()
Create the MeanPooling object.
size_t InputSize() const
Get the input size.
size_t & InputWidth()
Modify the input width.
size_t KernelWidth() const
Get the kernel width.
MeanPooling(const size_t kernelWidth, const size_t kernelHeight, const size_t strideWidth=1, const size_t strideHeight=1, const bool floor=true)
Create the MeanPooling object using the specified number of units.
size_t KernelHeight() const
Get the kernel height.
size_t & StrideWidth()
Modify the stride width.
size_t & KernelWidth()
Modify the kernel width.
size_t & OutputHeight()
Modify the output height.
size_t OutputSize() const
Get the output size.
bool & Deterministic()
Modify the value of the deterministic parameter.
bool Deterministic() const
Get the value of the deterministic parameter.
size_t const & InputWidth() const
Get the intput width.
bool & Floor()
Modify the value of the rounding operation.
size_t & KernelHeight()
Modify the kernel height.
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, using 3rd-order tensors as input,...
OutputDataType & OutputParameter()
Modify the output parameter.
size_t & OutputWidth()
Modify the output width.
size_t const & InputHeight() const
Get the input height.
size_t const & OutputWidth() const
Get the output width.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Delta()
Modify the delta.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.