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>&& ,
83 OutputDataType
const&
Delta()
const {
return delta; }
85 OutputDataType&
Delta() {
return delta; }
115 template<
typename Archive>
116 void serialize(Archive& ar,
const unsigned int );
125 template<
typename eT>
126 void Pooling(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
128 const size_t rStep = kW;
129 const size_t cStep = kH;
131 for (
size_t j = 0, colidx = 0; j < output.n_cols; ++j, colidx += dH)
133 for (
size_t i = 0, rowidx = 0; i < output.n_rows; ++i, rowidx += dW)
135 arma::mat subInput = input(
136 arma::span(rowidx, rowidx + rStep - 1 - offset),
137 arma::span(colidx, colidx + cStep - 1 - offset));
139 output(i, j) = arma::mean(arma::mean(subInput));
150 template<
typename eT>
151 void Unpooling(
const arma::Mat<eT>& input,
152 const arma::Mat<eT>& error,
153 arma::Mat<eT>& output)
155 const size_t rStep = input.n_rows / error.n_rows - offset;
156 const size_t cStep = input.n_cols / error.n_cols - offset;
158 arma::Mat<eT> unpooledError;
159 for (
size_t j = 0; j < input.n_cols - cStep; j += cStep)
161 for (
size_t i = 0; i < input.n_rows - rStep; i += rStep)
163 const arma::Mat<eT>& inputArea = input(arma::span(i, i + rStep - 1),
164 arma::span(j, j + cStep - 1));
166 unpooledError = arma::Mat<eT>(inputArea.n_rows, inputArea.n_cols);
167 unpooledError.fill(error(i / rStep, j / cStep) / inputArea.n_elem);
169 output(arma::span(i, i + rStep - 1 - offset),
170 arma::span(j, j + cStep - 1 - offset)) += unpooledError;
221 arma::cube outputTemp;
224 arma::cube inputTemp;
230 OutputDataType delta;
233 OutputDataType gradient;
236 OutputDataType outputParameter;
244 #include "mean_pooling_impl.hpp" 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.
OutputDataType const & Delta() const
Get the delta.
MeanPooling()
Create the MeanPooling object.
size_t & OutputHeight()
Modify the height.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t const & OutputHeight() const
Get the height.
size_t const & InputHeight() const
Get the height.
bool Deterministic() const
Get the value of the deterministic parameter.
OutputDataType & Delta()
Modify the delta.
Implementation of the MeanPooling.
OutputDataType const & OutputParameter() const
Get the output parameter.
size_t const & OutputWidth() const
Get the width.
size_t & InputHeight()
Modify the height.
size_t const & InputWidth() const
Get the width.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t & InputWidth()
Modify the width.
bool & Deterministic()
Modify the value of the deterministic parameter.
size_t & OutputWidth()
Modify the width.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
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...