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
51 const bool floor =
true);
61 void Forward(
const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
73 void Backward(
const arma::Mat<eT>&& ,
120 template<
typename Archive>
121 void Serialize(Archive& ar,
const unsigned int );
131 template<
typename eT>
132 void Pooling(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
134 const size_t rStep =
kW;
135 const size_t cStep =
kH;
137 for (
size_t j = 0, colidx = 0; j < output.n_cols; ++j, colidx +=
dH)
139 for (
size_t i = 0, rowidx = 0; i < output.n_rows; ++i, rowidx +=
dW)
141 arma::mat subInput = input(
142 arma::span(rowidx, rowidx + rStep - 1 -
offset),
143 arma::span(colidx, colidx + cStep - 1 -
offset));
145 output(i, j) = arma::mean(arma::mean(subInput));
156 template<
typename eT>
158 const arma::Mat<eT>& error,
159 arma::Mat<eT>& output)
161 const size_t rStep = input.n_rows / error.n_rows -
offset;
162 const size_t cStep = input.n_cols / error.n_cols -
offset;
164 arma::Mat<eT> unpooledError;
165 for (
size_t j = 0; j < input.n_cols - cStep; j += cStep)
167 for (
size_t i = 0; i < input.n_rows - rStep; i += rStep)
169 const arma::Mat<eT>& inputArea = input(arma::span(i, i + rStep - 1),
170 arma::span(j, j + cStep - 1));
172 unpooledError = arma::Mat<eT>(inputArea.n_rows, inputArea.n_cols);
173 unpooledError.fill(error(i / rStep, j / cStep) / inputArea.n_elem);
175 output(arma::span(i, i + rStep - 1 -
offset),
176 arma::span(j, j + cStep - 1 -
offset)) += unpooledError;
250 #include "mean_pooling_impl.hpp" arma::cube gTemp
Locally-stored transformed output parameter.
size_t & OutputHeight()
Modify the height.
OutputDataType delta
Locally-stored delta object.
size_t const & OutputWidth() const
Get the width.
OutputDataType gradient
Locally-stored gradient object.
Linear algebra utility functions, generally performed on matrices or vectors.
OutputDataType const & OutputParameter() const
Get the output parameter.
MeanPooling()
Create the MeanPooling object.
size_t & InputWidth()
Modify the width.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t kW
Locally-stored width of the pooling window.
size_t inputHeight
Locally-stored input height.
arma::cube outputTemp
Locally-stored output parameter.
Implementation of the MeanPooling.
InputDataType const & InputParameter() const
Get the input parameter.
size_t kH
Locally-stored height of the pooling window.
void Pooling(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Apply pooling to the input and store the results.
void Unpooling(const arma::Mat< eT > &input, const arma::Mat< eT > &error, arma::Mat< eT > &output)
Apply unpooling to the input and store the results.
size_t outputWidth
Locally-stored output width.
bool deterministic
If true use maximum a posteriori during the forward pass.
bool & Deterministic()
Modify the value of the deterministic parameter.
size_t outputHeight
Locally-stored output height.
bool Deterministic() const
Get the value of the deterministic parameter.
bool reset
Locally-stored reset parameter used to initialize the module once.
size_t offset
Locally-stored stored rounding offset.
size_t const & InputHeight() const
Get the height.
size_t & InputHeight()
Modify the height.
bool floor
Rounding operation used.
size_t inputWidth
Locally-stored input 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...
size_t const & InputWidth() const
Get the width.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t const & OutputHeight() const
Get the height.
void Backward(const arma::Mat< eT > &&, arma::Mat< eT > &&gy, arma::Mat< eT > &&g)
Ordinary feed backward pass of a neural network, using 3rd-order tensors as input, calculating the function f(x) by propagating x backwards through f.
size_t inSize
Locally-stored number of input units.
InputDataType & InputParameter()
Modify the input parameter.
size_t dW
Locally-stored width of the stride operation.
size_t outSize
Locally-stored number of output units.
void Serialize(Archive &ar, const unsigned int)
Serialize the layer.
arma::cube inputTemp
Locally-stored transformed input parameter.
OutputDataType outputParameter
Locally-stored output parameter object.
OutputDataType & Delta()
Modify the delta.
size_t dH
Locally-stored height of the stride operation.
OutputDataType const & Delta() const
Get the delta.
InputDataType inputParameter
Locally-stored input parameter object.
size_t & OutputWidth()
Modify the width.