12 #ifndef MLPACK_METHODS_ANN_LAYER_LP_POOLING_HPP 13 #define MLPACK_METHODS_ANN_LAYER_LP_POOLING_HPP 29 typename InputDataType = arma::mat,
30 typename OutputDataType = arma::mat
49 const size_t kernelWidth,
50 const size_t kernelHeight,
51 const size_t strideWidth = 1,
52 const size_t strideHeight = 1,
53 const bool floor =
true);
63 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
76 const arma::Mat<eT>& gy,
85 OutputDataType
const&
Delta()
const {
return delta; }
87 OutputDataType&
Delta() {
return delta; }
141 bool const&
Floor()
const {
return floor; }
151 template<
typename Archive>
152 void serialize(Archive& ar,
const uint32_t );
161 template<
typename eT>
162 void Pooling(
const arma::Mat<eT>& input, arma::Mat<eT>& output)
164 for (
size_t j = 0, colidx = 0; j < output.n_cols;
165 ++j, colidx += strideHeight)
167 for (
size_t i = 0, rowidx = 0; i < output.n_rows;
168 ++i, rowidx += strideWidth)
170 arma::mat subInput = input(
171 arma::span(rowidx, rowidx + kernelWidth - 1 - offset),
172 arma::span(colidx, colidx + kernelHeight - 1 - offset));
174 output(i, j) = pow(arma::accu(arma::pow(subInput,
175 normType)), 1.0 / normType);
186 template<
typename eT>
187 void Unpooling(
const arma::Mat<eT>& input,
188 const arma::Mat<eT>& error,
189 arma::Mat<eT>& output)
191 const size_t rStep = input.n_rows / error.n_rows - offset;
192 const size_t cStep = input.n_cols / error.n_cols - offset;
194 arma::Mat<eT> unpooledError;
195 for (
size_t j = 0; j < input.n_cols - cStep; j += cStep)
197 for (
size_t i = 0; i < input.n_rows - rStep; i += rStep)
199 const arma::Mat<eT>& inputArea = input(arma::span(i, i + rStep - 1),
200 arma::span(j, j + cStep - 1));
201 size_t sum = pow(arma::accu(arma::pow(inputArea, normType)),
202 (normType - 1) / normType);
203 unpooledError = arma::Mat<eT>(inputArea.n_rows, inputArea.n_cols);
204 unpooledError.fill(error(i / rStep, j / cStep));
205 unpooledError %= arma::pow(inputArea, normType - 1);
206 unpooledError /= sum;
207 output(arma::span(i, i + rStep - 1 - offset),
208 arma::span(j, j + cStep - 1 - offset)) += unpooledError;
259 arma::cube outputTemp;
262 arma::cube inputTemp;
268 OutputDataType delta;
271 OutputDataType gradient;
274 OutputDataType outputParameter;
282 #include "lp_pooling_impl.hpp" size_t const & InputWidth() const
Get the intput width.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
size_t StrideWidth() const
Get the stride width.
LpPooling()
Create the LpPooling object.
Linear algebra utility functions, generally performed on matrices or vectors.
size_t & StrideWidth()
Modify the stride width.
Implementation of the LPPooling.
size_t & KernelWidth()
Modify the kernel width.
size_t KernelHeight() const
Get the kernel height.
size_t OutputSize() const
Get the output size.
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t WeightSize() const
Get the size of the weights.
OutputDataType const & Delta() const
Get the delta.
size_t & InputWidth()
Modify the input width.
size_t StrideHeight() const
Get the stride height.
bool & Floor()
Modify the value of the rounding operation.
size_t KernelWidth() const
Get the kernel width.
size_t & NormType()
Modify the normType.
OutputDataType const & OutputParameter() const
Get the output parameter.
size_t const & OutputWidth() const
Get the output width.
size_t & OutputWidth()
Modify the output width.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t & StrideHeight()
Modify the stride height.
size_t & KernelHeight()
Modify the kernel height.
size_t const & InputHeight() const
Get the input height.
size_t const & OutputHeight() const
Get the output height.
size_t & OutputHeight()
Modify the output height.
size_t NormType() const
Get the normType.
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...
OutputDataType & Delta()
Modify the delta.
size_t & InputHeight()
Modify the input height.
void Backward(const arma::Mat< eT > &, const 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.
size_t InputSize() const
Get the input size.
bool const & Floor() const
Get the value of the rounding operation.