adaptive_mean_pooling.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_ADAPTIVE_MEAN_POOLING_HPP
14 #define MLPACK_METHODS_ANN_LAYER_ADAPTIVE_MEAN_POOLING_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 #include "layer_types.hpp"
18 
19 namespace mlpack {
20 namespace ann {
21 
30 template <
31  typename InputDataType = arma::mat,
32  typename OutputDataType = arma::mat
33 >
35 {
36  public:
39 
46  AdaptiveMeanPooling(const size_t outputWidth,
47  const size_t outputHeight);
48 
54  AdaptiveMeanPooling(const std::tuple<size_t, size_t>& outputShape);
55 
63  template<typename eT>
64  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
65 
75  template<typename eT>
76  void Backward(const arma::Mat<eT>& input,
77  const arma::Mat<eT>& gy,
78  arma::Mat<eT>& g);
79 
81  const OutputDataType& OutputParameter() const
82  { return poolingLayer.OutputParameter(); }
83 
85  OutputDataType& OutputParameter() { return poolingLayer.OutputParameter(); }
86 
88  const OutputDataType& Delta() const { return poolingLayer.Delta(); }
90  OutputDataType& Delta() { return poolingLayer.Delta(); }
91 
93  size_t InputWidth() const { return poolingLayer.InputWidth(); }
95  size_t& InputWidth() { return poolingLayer.InputWidth(); }
96 
98  size_t InputHeight() const { return poolingLayer.InputHeight(); }
100  size_t& InputHeight() { return poolingLayer.InputHeight(); }
101 
103  size_t OutputWidth() const { return outputWidth; }
105  size_t& OutputWidth() { return outputWidth; }
106 
108  size_t OutputHeight() const { return outputHeight; }
110  size_t& OutputHeight() { return outputHeight; }
111 
113  size_t InputSize() const { return poolingLayer.InputSize(); }
114 
116  size_t OutputSize() const { return poolingLayer.OutputSize(); }
117 
121  template<typename Archive>
122  void serialize(Archive& ar, const unsigned int version);
123 
124  private:
128  void IntializeAdaptivePadding()
129  {
130  poolingLayer.StrideWidth() = std::floor(poolingLayer.InputWidth() /
131  outputWidth);
132  poolingLayer.StrideHeight() = std::floor(poolingLayer.InputHeight() /
133  outputHeight);
134 
135  poolingLayer.KernelWidth() = poolingLayer.InputWidth() -
136  (outputWidth - 1) * poolingLayer.StrideWidth();
137  poolingLayer.KernelHeight() = poolingLayer.InputHeight() -
138  (outputHeight - 1) * poolingLayer.StrideHeight();
139 
140  if (poolingLayer.KernelHeight() <= 0 || poolingLayer.KernelWidth() <= 0 ||
141  poolingLayer.StrideWidth() <= 0 || poolingLayer.StrideHeight() <= 0)
142  {
143  Log::Fatal << "Given output shape (" << outputWidth << ", "
144  << outputHeight << ") is not possible for given input shape ("
145  << poolingLayer.InputWidth() << ", " << poolingLayer.InputHeight()
146  << ")." << std::endl;
147  }
148  }
149 
152 
154  size_t outputWidth;
155 
157  size_t outputHeight;
158 
160  bool reset;
161 }; // class AdaptiveMeanPooling
162 
163 } // namespace ann
164 } // namespace mlpack
165 
166 // Include implementation.
167 #include "adaptive_mean_pooling_impl.hpp"
168 
169 #endif
size_t & OutputHeight()
Modify the output height.
size_t & InputWidth()
Modify the input width.
size_t OutputHeight() const
Get the output height.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: add_to_po.hpp:21
size_t InputWidth() const
Get the input width.
The core includes that mlpack expects; standard C++ includes and Armadillo.
Implementation of the MeanPooling.
size_t OutputWidth() const
Get the output width.
OutputDataType & OutputParameter()
Modify the output parameter.
Implementation of the AdaptiveMeanPooling.
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
const OutputDataType & Delta() const
Get the delta.
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...
const OutputDataType & OutputParameter() const
Get the output parameter.
size_t & InputHeight()
Modify the input height.
size_t InputSize() const
Get the input size.
OutputDataType & Delta()
Modify the delta.
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.
size_t OutputSize() const
Get the output size.
size_t InputHeight() const
Get the input height.
size_t & OutputWidth()
Modify the output width.
void serialize(Archive &ar, const unsigned int version)
Serialize the layer.
AdaptiveMeanPooling()
Create the AdaptiveMeanPooling object.