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 );
152 template<
typename eT>
154 arma::Mat<eT>& output,
155 arma::Mat<eT>& poolingIndices)
157 for (
size_t j = 0, colidx = 0; j < output.n_cols; ++j, colidx += dW)
159 for (
size_t i = 0, rowidx = 0; i < output.n_rows; ++i, rowidx += dH)
161 arma::mat subInput = input(arma::span(rowidx, rowidx + kW - 1 - offset),
162 arma::span(colidx, colidx + kH - 1 - offset));
164 const size_t idx = pooling.Pooling(subInput);
165 output(i, j) = subInput(idx);
169 arma::Mat<size_t> subIndices = indices(arma::span(rowidx,
170 rowidx + kW - 1 - offset),
171 arma::span(colidx, colidx + kH - 1 - offset));
173 poolingIndices(i, j) = subIndices(idx);
186 template<
typename eT>
188 arma::Mat<eT>& output,
189 arma::Mat<eT>& poolingIndices)
191 for (
size_t i = 0; i < poolingIndices.n_elem; ++i)
193 output(poolingIndices(i)) += error(i);
277 #include "max_pooling_impl.hpp" size_t dW
Locally-stored width of the stride operation.
InputDataType const & InputParameter() const
Get the input parameter.
size_t kH
Locally-stored height of the pooling window.
size_t const & InputHeight() const
Get the height.
Linear algebra utility functions, generally performed on matrices or vectors.
size_t & InputHeight()
Modify the height.
size_t & OutputHeight()
Modify the height.
The core includes that mlpack expects; standard C++ includes and Armadillo.
bool deterministic
If true use maximum a posteriori during the forward pass.
size_t outputWidth
Locally-stored output width.
size_t inputHeight
Locally-stored input height.
size_t const & OutputWidth() const
Get the width.
MaxPoolingRule pooling
Locally-stored pooling strategy.
std::vector< arma::cube > poolingIndices
Locally-stored pooling indicies.
void PoolingOperation(const arma::Mat< eT > &input, arma::Mat< eT > &output, arma::Mat< eT > &poolingIndices)
Apply pooling to the input and store the results.
InputDataType & InputParameter()
Modify the input parameter.
size_t offset
Locally-stored stored rounding offset.
OutputDataType outputParameter
Locally-stored output parameter object.
OutputDataType gradient
Locally-stored gradient object.
size_t Pooling(const MatType &input)
InputDataType inputParameter
Locally-stored input parameter object.
size_t dH
Locally-stored height of the stride operation.
bool floor
Rounding operation used.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t inSize
Locally-stored number of input units.
arma::Col< size_t > indicesCol
Locally-stored indices column parameter.
size_t & InputWidth()
Modify the width.
arma::Mat< size_t > indices
Locally-stored indices matrix parameter.
bool reset
Locally-stored reset parameter used to initialize the module once.
OutputDataType & Delta()
Modify the delta.
size_t & OutputWidth()
Modify the width.
OutputDataType delta
Locally-stored delta object.
arma::cube gTemp
Locally-stored transformed output parameter.
arma::cube outputTemp
Locally-stored output parameter.
size_t const & OutputHeight() const
Get the height.
arma::cube inputTemp
Locally-stored transformed input parameter.
Implementation of the MaxPooling layer.
size_t inputWidth
Locally-stored input width.
void Unpooling(const arma::Mat< eT > &error, arma::Mat< eT > &output, arma::Mat< eT > &poolingIndices)
Apply unpooling to the input and store the results.
bool & Deterministic()
Modify the value of the deterministic parameter.
size_t outSize
Locally-stored number of output units.
size_t outputHeight
Locally-stored output height.
size_t kW
Locally-stored width of the pooling window.
size_t const & InputWidth() const
Get the width.
bool Deterministic() const
Get the value of the deterministic parameter.
OutputDataType const & OutputParameter() const
Get the output parameter.
OutputDataType const & Delta() const
Get the delta.