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 
119  size_t WeightSize() const { return 0; }
120 
124  template<typename Archive>
125  void serialize(Archive& ar, const uint32_t version);
126 
127  private:
131  void IntializeAdaptivePadding()
132  {
133  poolingLayer.StrideWidth() = std::floor(poolingLayer.InputWidth() /
134  outputWidth);
135  poolingLayer.StrideHeight() = std::floor(poolingLayer.InputHeight() /
136  outputHeight);
137 
138  poolingLayer.KernelWidth() = poolingLayer.InputWidth() -
139  (outputWidth - 1) * poolingLayer.StrideWidth();
140  poolingLayer.KernelHeight() = poolingLayer.InputHeight() -
141  (outputHeight - 1) * poolingLayer.StrideHeight();
142 
143  if (poolingLayer.KernelHeight() <= 0 || poolingLayer.KernelWidth() <= 0 ||
144  poolingLayer.StrideWidth() <= 0 || poolingLayer.StrideHeight() <= 0)
145  {
146  Log::Fatal << "Given output shape (" << outputWidth << ", "
147  << outputHeight << ") is not possible for given input shape ("
148  << poolingLayer.InputWidth() << ", " << poolingLayer.InputHeight()
149  << ")." << std::endl;
150  }
151  }
152 
155 
157  size_t outputWidth;
158 
160  size_t outputHeight;
161 
163  bool reset;
164 }; // class AdaptiveMeanPooling
165 
166 } // namespace ann
167 } // namespace mlpack
168 
169 // Include implementation.
170 #include "adaptive_mean_pooling_impl.hpp"
171 
172 #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.
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.
size_t WeightSize() const
Get the size of the weights.
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.
void serialize(Archive &ar, const uint32_t version)
Serialize the layer.
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.
AdaptiveMeanPooling()
Create the AdaptiveMeanPooling object.