mlpack 3.4.2
adaptive_max_pooling.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_METHODS_ANN_LAYER_ADAPTIVE_MAX_POOLING_HPP
13#define MLPACK_METHODS_ANN_LAYER_ADAPTIVE_MAX_POOLING_HPP
14
15#include <mlpack/prereqs.hpp>
16#include "layer_types.hpp"
17
18namespace mlpack {
19namespace ann {
20
29template <
30 typename InputDataType = arma::mat,
31 typename OutputDataType = arma::mat
32>
34{
35 public:
38
45 AdaptiveMaxPooling(const size_t outputWidth,
46 const size_t outputHeight);
47
53 AdaptiveMaxPooling(const std::tuple<size_t, size_t>& outputShape);
54
62 template<typename eT>
63 void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
64
74 template<typename eT>
75 void Backward(const arma::Mat<eT>& input,
76 const arma::Mat<eT>& gy,
77 arma::Mat<eT>& g);
78
80 const OutputDataType& OutputParameter() const
81 { return poolingLayer.OutputParameter(); }
82
84 OutputDataType& OutputParameter() { return poolingLayer.OutputParameter(); }
85
87 const OutputDataType& Delta() const { return poolingLayer.Delta(); }
89 OutputDataType& Delta() { return poolingLayer.Delta(); }
90
92 size_t InputWidth() const { return poolingLayer.InputWidth(); }
94 size_t& InputWidth() { return poolingLayer.InputWidth(); }
95
97 size_t InputHeight() const { return poolingLayer.InputHeight(); }
99 size_t& InputHeight() { return poolingLayer.InputHeight(); }
100
102 size_t OutputWidth() const { return outputWidth; }
104 size_t& OutputWidth() { return outputWidth; }
105
107 size_t OutputHeight() const { return outputHeight; }
109 size_t& OutputHeight() { return outputHeight; }
110
112 size_t InputSize() const { return poolingLayer.InputSize(); }
113
115 size_t OutputSize() const { return poolingLayer.OutputSize(); }
116
120 template<typename Archive>
121 void serialize(Archive& ar, const unsigned int version);
122
123 private:
127 void IntializeAdaptivePadding()
128 {
129 poolingLayer.StrideWidth() = std::floor(poolingLayer.InputWidth() /
130 outputWidth);
131 poolingLayer.StrideHeight() = std::floor(poolingLayer.InputHeight() /
132 outputHeight);
133
134 poolingLayer.KernelWidth() = poolingLayer.InputWidth() -
135 (outputWidth - 1) * poolingLayer.StrideWidth();
136 poolingLayer.KernelHeight() = poolingLayer.InputHeight() -
137 (outputHeight - 1) * poolingLayer.StrideHeight();
138
139 if (poolingLayer.KernelHeight() <= 0 || poolingLayer.KernelWidth() <= 0 ||
140 poolingLayer.StrideWidth() <= 0 || poolingLayer.StrideHeight() <= 0)
141 {
142 Log::Fatal << "Given output shape (" << outputWidth << ", "
143 << outputHeight << ") is not possible for given input shape ("
144 << poolingLayer.InputWidth() << ", " << poolingLayer.InputHeight()
145 << ")." << std::endl;
146 }
147 }
148
150 MaxPooling<InputDataType, OutputDataType> poolingLayer;
151
153 size_t outputWidth;
154
156 size_t outputHeight;
157
159 bool reset;
160}; // class AdaptiveMaxPooling
161
162} // namespace ann
163} // namespace mlpack
164
165// Include implementation.
166#include "adaptive_max_pooling_impl.hpp"
167
168#endif
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
Implementation of the AdaptiveMaxPooling layer.
size_t & InputHeight()
Modify the input height.
AdaptiveMaxPooling()
Create the AdaptiveMaxPooling object.
size_t InputWidth() const
Get the input width.
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...
size_t InputSize() const
Get the input size.
size_t & InputWidth()
Modify the input width.
void serialize(Archive &ar, const unsigned int version)
Serialize the layer.
AdaptiveMaxPooling(const size_t outputWidth, const size_t outputHeight)
Create the AdaptiveMaxPooling object.
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,...
size_t & OutputHeight()
Modify the output height.
AdaptiveMaxPooling(const std::tuple< size_t, size_t > &outputShape)
Create the AdaptiveMaxPooling object.
size_t OutputHeight() const
Get the output height.
size_t OutputSize() const
Get the output size.
size_t OutputWidth() const
Get the output width.
size_t InputHeight() const
Get the input height.
const OutputDataType & OutputParameter() const
Get the output parameter.
OutputDataType & OutputParameter()
Modify the output parameter.
size_t & OutputWidth()
Modify the output width.
OutputDataType & Delta()
Modify the delta.
const OutputDataType & Delta() const
Get the delta.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.