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
68 const size_t kernelHeight,
69 const size_t strideWidth = 1,
70 const size_t strideHeight = 1,
71 const bool floor =
true);
81 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
93 void Backward(
const arma::Mat<eT>& ,
94 const arma::Mat<eT>& gy,
103 const OutputDataType&
Delta()
const {
return delta; }
105 OutputDataType&
Delta() {
return delta; }
154 bool Floor()
const {
return floor; }
169 template<
typename Archive>
170 void serialize(Archive& ar,
const uint32_t );
180 template<
typename eT>
181 void PoolingOperation(
const arma::Mat<eT>& input,
182 arma::Mat<eT>& output,
183 arma::Mat<eT>& poolingIndices)
185 for (
size_t j = 0, colidx = 0; j < output.n_cols;
186 ++j, colidx += strideHeight)
188 for (
size_t i = 0, rowidx = 0; i < output.n_rows;
189 ++i, rowidx += strideWidth)
191 size_t rowEnd = rowidx + kernelWidth - 1;
192 size_t colEnd = colidx + kernelHeight - 1;
194 if (rowEnd > input.n_rows - 1)
195 rowEnd = input.n_rows - 1;
196 if (colEnd > input.n_cols - 1)
197 colEnd = input.n_cols - 1;
199 arma::mat subInput = input(
200 arma::span(rowidx, rowEnd),
201 arma::span(colidx, colEnd));
203 const size_t idx = pooling.Pooling(subInput);
204 output(i, j) = subInput(idx);
208 arma::Mat<size_t> subIndices = indices(arma::span(rowidx, rowEnd),
209 arma::span(colidx, colEnd));
211 poolingIndices(i, j) = subIndices(idx);
224 template<
typename eT>
225 void Unpooling(
const arma::Mat<eT>& error,
226 arma::Mat<eT>& output,
227 arma::Mat<eT>& poolingIndices)
229 for (
size_t i = 0; i < poolingIndices.n_elem; ++i)
231 output(poolingIndices(i)) += error(i);
279 arma::cube outputTemp;
282 arma::cube inputTemp;
291 OutputDataType delta;
294 OutputDataType gradient;
297 OutputDataType outputParameter;
300 arma::Mat<size_t> indices;
303 arma::Col<size_t> indicesCol;
306 std::vector<arma::cube> poolingIndices;
313 #include "max_pooling_impl.hpp" bool Floor() const
Get the value of the rounding operation.
size_t InputSize() const
Get the input size.
size_t KernelWidth() const
Get the kernel width.
size_t & InputWidth()
Modify the input width.
Linear algebra utility functions, generally performed on matrices or vectors.
size_t InputHeight() const
Get the input height.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & OutputWidth()
Modify the output width.
size_t OutputSize() const
Get the output size.
bool & Deterministic()
Modify the value of the deterministic parameter.
size_t & StrideWidth()
Modify the stride width.
size_t & StrideHeight()
Modify the stride height.
size_t & KernelHeight()
Modify the kernel height.
size_t OutputWidth() const
Get the output width.
size_t & InputHeight()
Modify the input height.
size_t & OutputHeight()
Modify the output height.
size_t Pooling(const MatType &input)
size_t StrideHeight() const
Get the stride height.
size_t KernelHeight() const
Get the kernel height.
size_t InputWidth() const
Get the input width.
const OutputDataType & Delta() const
Get the delta.
size_t OutputHeight() const
Get the output height.
size_t WeightSize() const
Get the size of the weights.
size_t StrideWidth() const
Get the stride width.
size_t & KernelWidth()
Modify the kernel width.
bool & Floor()
Modify the value of the rounding operation.
bool Deterministic() const
Get the value of the deterministic parameter.
Implementation of the MaxPooling layer.
OutputDataType & Delta()
Modify the delta.
const OutputDataType & OutputParameter() const
Get the output parameter.
OutputDataType & OutputParameter()
Modify the output parameter.