padding.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_ANN_LAYER_PADDING_HPP
13 #define MLPACK_METHODS_ANN_LAYER_PADDING_HPP
14 
15 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace ann {
20 
30 template <
31  typename InputDataType = arma::mat,
32  typename OutputDataType = arma::mat
33 >
34 class Padding
35 {
36  public:
47  Padding(const size_t padWLeft = 0,
48  const size_t padWRight = 0,
49  const size_t padHTop = 0,
50  const size_t padHBottom = 0,
51  const size_t inputWidth = 0,
52  const size_t inputHeight = 0);
53 
61  template<typename eT>
62  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
63 
73  template<typename eT>
74  void Backward(const arma::Mat<eT>& /* input */,
75  const arma::Mat<eT>& gy,
76  arma::Mat<eT>& g);
77 
79  OutputDataType const& OutputParameter() const { return outputParameter; }
81  OutputDataType& OutputParameter() { return outputParameter; }
82 
84  OutputDataType const& Delta() const { return delta; }
86  OutputDataType& Delta() { return delta; }
87 
89  size_t PadWLeft() const { return padWLeft; }
91  size_t& PadWLeft() { return padWLeft; }
92 
94  size_t PadWRight() const { return padWRight; }
96  size_t& PadWRight() { return padWRight; }
97 
99  size_t PadHTop() const { return padHTop; }
101  size_t& PadHTop() { return padHTop; }
102 
104  size_t PadHBottom() const { return padHBottom; }
106  size_t& PadHBottom() { return padHBottom; }
107 
109  size_t InputWidth() const { return inputWidth; }
111  size_t& InputWidth() { return inputWidth; }
112 
114  size_t InputHeight() const { return inputHeight; }
116  size_t& InputHeight() { return inputHeight; }
117 
119  size_t OutputWidth() const { return outputWidth; }
121  size_t& OutputWidth() { return outputWidth; }
122 
124  size_t OutputHeight() const { return outputHeight; }
126  size_t& OutputHeight() { return outputHeight; }
127 
131  template<typename Archive>
132  void serialize(Archive& ar, const uint32_t /* version */);
133 
134  private:
136  size_t padWLeft;
137 
139  size_t padWRight;
140 
142  size_t padHTop;
143 
145  size_t padHBottom;
146 
148  size_t nRows, nCols;
149 
151  size_t inputHeight;
152 
154  size_t inputWidth;
155 
157  size_t outputHeight;
158 
160  size_t outputWidth;
161 
163  size_t inSize;
164 
166  arma::cube inputTemp;
167 
169  arma::cube outputTemp;
170 
172  OutputDataType delta;
173 
175  OutputDataType outputParameter;
176 }; // class Padding
177 
178 } // namespace ann
179 } // namespace mlpack
180 
181 // Include implementation.
182 #include "padding_impl.hpp"
183 
184 #endif
size_t & InputWidth()
Modify the input width.
Definition: padding.hpp:111
size_t InputWidth() const
Get the input width.
Definition: padding.hpp:109
size_t OutputWidth() const
Get the output width.
Definition: padding.hpp:119
size_t PadHBottom() const
Get the bottom padding width.
Definition: padding.hpp:104
Linear algebra utility functions, generally performed on matrices or vectors.
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 PadWRight() const
Get the right padding width.
Definition: padding.hpp:94
The core includes that mlpack expects; standard C++ includes and Armadillo.
size_t & PadWLeft()
Modify the left padding width.
Definition: padding.hpp:91
size_t & PadHBottom()
Modify the bottom padding width.
Definition: padding.hpp:106
Padding(const size_t padWLeft=0, const size_t padWRight=0, const size_t padHTop=0, const size_t padHBottom=0, const size_t inputWidth=0, const size_t inputHeight=0)
Create the Padding object using the specified number of output units.
size_t InputHeight() const
Get the input height.
Definition: padding.hpp:114
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: padding.hpp:79
OutputDataType const & Delta() const
Get the delta.
Definition: padding.hpp:84
size_t OutputHeight() const
Get the output height.
Definition: padding.hpp:124
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: padding.hpp:81
size_t PadHTop() const
Get the top padding width.
Definition: padding.hpp:99
size_t & OutputHeight()
Modify the output height.
Definition: padding.hpp:126
size_t & InputHeight()
Modify the input height.
Definition: padding.hpp:116
size_t PadWLeft() const
Get the left padding width.
Definition: padding.hpp:89
size_t & OutputWidth()
Modify the output width.
Definition: padding.hpp:121
size_t & PadHTop()
Modify the top padding width.
Definition: padding.hpp:101
OutputDataType & Delta()
Modify the delta.
Definition: padding.hpp:86
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
size_t & PadWRight()
Modify the right padding width.
Definition: padding.hpp:96