mlpack
adaptive_max_pooling_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LAYER_ADAPTIVE_MAX_POOLING_IMPL_HPP
13 #define MLPACK_METHODS_ANN_LAYER_ADAPTIVE_MAX_POOLING_IMPL_HPP
14 
15 // In case it hasn't yet been included.
16 #include "adaptive_max_pooling.hpp"
17 
18 namespace mlpack {
19 namespace ann {
20 
21 template<typename InputDataType, typename OutputDataType>
23 {
24  // Nothing to do here.
25 }
26 
27 template <typename InputDataType, typename OutputDataType>
29  const size_t outputWidth,
30  const size_t outputHeight) :
31  AdaptiveMaxPooling(std::tuple<size_t, size_t>(outputWidth, outputHeight))
32 {
33  // Nothing to do here.
34 }
35 
36 template <typename InputDataType, typename OutputDataType>
38  const std::tuple<size_t, size_t>& outputShape):
39  outputWidth(std::get<0>(outputShape)),
40  outputHeight(std::get<1>(outputShape)),
41  reset(false)
42 {
43  poolingLayer = ann::MaxPooling<>(0, 0);
44 }
45 
46 template<typename InputDataType, typename OutputDataType>
47 template<typename eT>
49  const arma::Mat<eT>& input, arma::Mat<eT>& output)
50 {
51  if (!reset)
52  {
53  IntializeAdaptivePadding();
54  reset = true;
55  }
56 
57  poolingLayer.Forward(input, output);
58 }
59 
60 template<typename InputDataType, typename OutputDataType>
61 template<typename eT>
63  const arma::Mat<eT>& input,
64  const arma::Mat<eT>& gy,
65  arma::Mat<eT>& g)
66 {
67  poolingLayer.Backward(input, gy, g);
68 }
69 
70 template<typename InputDataType, typename OutputDataType>
71 template<typename Archive>
73  Archive& ar,
74  const uint32_t /* version */)
75 {
76  ar(CEREAL_NVP(outputWidth));
77  ar(CEREAL_NVP(outputHeight));
78  ar(CEREAL_NVP(reset));
79  ar(CEREAL_NVP(poolingLayer));
80 }
81 
82 } // namespace ann
83 } // namespace mlpack
84 
85 #endif
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...
Definition: adaptive_max_pooling_impl.hpp:48
Implementation of the AdaptiveMaxPooling layer.
Definition: adaptive_max_pooling.hpp:33
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
Definition: pointer_wrapper.hpp:23
AdaptiveMaxPooling()
Create the AdaptiveMaxPooling object.
Definition: adaptive_max_pooling_impl.hpp:22
void serialize(Archive &ar, const uint32_t version)
Serialize the layer.
Definition: adaptive_max_pooling_impl.hpp:72
void Backward(const arma::Mat< eT > &input, 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.
Definition: adaptive_max_pooling_impl.hpp:62
Implementation of the MaxPooling layer.
Definition: max_pooling.hpp:52