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>&& ,
88 OutputDataType
const&
Delta()
const {
return delta; }
90 OutputDataType&
Delta() {
return delta; }
120 template<
typename Archive>
121 void serialize(Archive& ar,
const unsigned int );
130 template<
typename eT>
131 void Pooling(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
133 const size_t rStep = kW;
134 const size_t cStep = kH;
136 for (
size_t j = 0, colidx = 0; j < output.n_cols; ++j, colidx += dH)
138 for (
size_t i = 0, rowidx = 0; i < output.n_rows; ++i, rowidx += dW)
140 arma::mat subInput = input(
141 arma::span(rowidx, rowidx + rStep - 1 - offset),
142 arma::span(colidx, colidx + cStep - 1 - offset));
144 output(i, j) = arma::mean(arma::mean(subInput));
155 template<
typename eT>
156 void Unpooling(
const arma::Mat<eT>& input,
157 const arma::Mat<eT>& error,
158 arma::Mat<eT>& output)
160 const size_t rStep = input.n_rows / error.n_rows - offset;
161 const size_t cStep = input.n_cols / error.n_cols - offset;
163 arma::Mat<eT> unpooledError;
164 for (
size_t j = 0; j < input.n_cols - cStep; j += cStep)
166 for (
size_t i = 0; i < input.n_rows - rStep; i += rStep)
168 const arma::Mat<eT>& inputArea = input(arma::span(i, i + rStep - 1),
169 arma::span(j, j + cStep - 1));
171 unpooledError = arma::Mat<eT>(inputArea.n_rows, inputArea.n_cols);
172 unpooledError.fill(error(i / rStep, j / cStep) / inputArea.n_elem);
174 output(arma::span(i, i + rStep - 1 - offset),
175 arma::span(j, j + cStep - 1 - offset)) += unpooledError;
223 arma::cube outputTemp;
226 arma::cube inputTemp;
232 OutputDataType delta;
235 OutputDataType gradient;
238 InputDataType inputParameter;
241 OutputDataType outputParameter;
249 #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.
InputDataType const & InputParameter() const
Get the input parameter.
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...
InputDataType & InputParameter()
Modify the input parameter.