13 #ifndef MLPACK_METHODS_ANN_LAYER_MAX_POOLING_HPP 14 #define MLPACK_METHODS_ANN_LAYER_MAX_POOLING_HPP 33 template<
typename MatType>
36 return arma::as_scalar(arma::find(input.max() == input, 1));
49 typename InputDataType = arma::mat,
50 typename OutputDataType = arma::mat
71 const bool floor =
true);
81 void Forward(
const arma::Mat<eT>&& input, arma::Mat<eT>&& output);
93 void Backward(
const arma::Mat<eT>&& ,
108 OutputDataType
const&
Delta()
const {
return delta; }
110 OutputDataType&
Delta() {
return delta; }
140 template<
typename Archive>
141 void serialize(Archive& ar,
const unsigned int );
151 template<
typename eT>
152 void PoolingOperation(
const arma::Mat<eT>& input,
153 arma::Mat<eT>& output,
154 arma::Mat<eT>& poolingIndices)
156 for (
size_t j = 0, colidx = 0; j < output.n_cols; ++j, colidx += dW)
158 for (
size_t i = 0, rowidx = 0; i < output.n_rows; ++i, rowidx += dH)
160 arma::mat subInput = input(arma::span(rowidx, rowidx + kW - 1 - offset),
161 arma::span(colidx, colidx + kH - 1 - offset));
163 const size_t idx = pooling.Pooling(subInput);
164 output(i, j) = subInput(idx);
168 arma::Mat<size_t> subIndices = indices(arma::span(rowidx,
169 rowidx + kW - 1 - offset),
170 arma::span(colidx, colidx + kH - 1 - offset));
172 poolingIndices(i, j) = subIndices(idx);
185 template<
typename eT>
186 void Unpooling(
const arma::Mat<eT>& error,
187 arma::Mat<eT>& output,
188 arma::Mat<eT>& poolingIndices)
190 for (
size_t i = 0; i < poolingIndices.n_elem; ++i)
192 output(poolingIndices(i)) += error(i);
239 arma::cube outputTemp;
242 arma::cube inputTemp;
251 OutputDataType delta;
254 OutputDataType gradient;
257 InputDataType inputParameter;
260 OutputDataType outputParameter;
263 arma::Mat<size_t> indices;
266 arma::Col<size_t> indicesCol;
269 std::vector<arma::cube> poolingIndices;
276 #include "max_pooling_impl.hpp" OutputDataType const & OutputParameter() const
Get the output parameter.
size_t & InputWidth()
Modify the width.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & OutputWidth()
Modify the width.
size_t const & InputWidth() const
Get the width.
bool & Deterministic()
Modify the value of the deterministic parameter.
size_t & InputHeight()
Modify the height.
size_t & OutputHeight()
Modify the height.
size_t const & OutputWidth() const
Get the width.
size_t Pooling(const MatType &input)
InputDataType const & InputParameter() const
Get the input parameter.
OutputDataType const & Delta() const
Get the delta.
size_t const & InputHeight() const
Get the height.
bool Deterministic() const
Get the value of the deterministic parameter.
InputDataType & InputParameter()
Modify the input parameter.
Implementation of the MaxPooling layer.
OutputDataType & Delta()
Modify the delta.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t const & OutputHeight() const
Get the height.