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>&& ,
103 OutputDataType
const&
Delta()
const {
return delta; }
105 OutputDataType&
Delta() {
return delta; }
135 template<
typename Archive>
136 void serialize(Archive& ar,
const unsigned int );
146 template<
typename eT>
147 void PoolingOperation(
const arma::Mat<eT>& input,
148 arma::Mat<eT>& output,
149 arma::Mat<eT>& poolingIndices)
151 for (
size_t j = 0, colidx = 0; j < output.n_cols; ++j, colidx += dW)
153 for (
size_t i = 0, rowidx = 0; i < output.n_rows; ++i, rowidx += dH)
155 arma::mat subInput = input(arma::span(rowidx, rowidx + kW - 1 - offset),
156 arma::span(colidx, colidx + kH - 1 - offset));
158 const size_t idx = pooling.Pooling(subInput);
159 output(i, j) = subInput(idx);
163 arma::Mat<size_t> subIndices = indices(arma::span(rowidx,
164 rowidx + kW - 1 - offset),
165 arma::span(colidx, colidx + kH - 1 - offset));
167 poolingIndices(i, j) = subIndices(idx);
180 template<
typename eT>
181 void Unpooling(
const arma::Mat<eT>& error,
182 arma::Mat<eT>& output,
183 arma::Mat<eT>& poolingIndices)
185 for (
size_t i = 0; i < poolingIndices.n_elem; ++i)
187 output(poolingIndices(i)) += error(i);
237 arma::cube outputTemp;
240 arma::cube inputTemp;
249 OutputDataType delta;
252 OutputDataType gradient;
255 OutputDataType outputParameter;
258 arma::Mat<size_t> indices;
261 arma::Col<size_t> indicesCol;
264 std::vector<arma::cube> poolingIndices;
271 #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)
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.
Implementation of the MaxPooling layer.
OutputDataType & Delta()
Modify the delta.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t const & OutputHeight() const
Get the height.