instance_norm.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_INSTANCE_NORM_HPP
14 #define MLPACK_METHODS_ANN_LAYER_INSTANCE_NORM_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 #include "layer_types.hpp"
18 
19 namespace mlpack {
20 namespace ann {
21 
51 template <
52  typename InputDataType = arma::mat,
53  typename OutputDataType = arma::mat
54 >
56 {
57  public:
59  InstanceNorm();
60 
71  InstanceNorm(const size_t size,
72  const size_t batchSize,
73  const double eps = 1e-5,
74  const bool average = true,
75  const double momentum = 0.1);
76 
85  template<typename eT>
86  void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
87 
95  template<typename eT>
96  void Backward(const arma::Mat<eT>& input,
97  const arma::Mat<eT>& gy,
98  arma::Mat<eT>& g);
99 
107  template<typename eT>
108  void Gradient(const arma::Mat<eT>& input,
109  const arma::Mat<eT>& error,
110  arma::Mat<eT>& gradient);
111 
113  OutputDataType const& Parameters() const { return batchNorm.Parameters(); }
115  OutputDataType& Parameters() { return batchNorm.Parameters(); }
116 
118  OutputDataType const& OutputParameter() const
119  { return batchNorm.OutputParameter(); }
120 
122  OutputDataType& OutputParameter() { return batchNorm.OutputParameter(); }
123 
125  OutputDataType const& Delta() const { return batchNorm.Delta(); }
127  OutputDataType& Delta() { return batchNorm.Delta(); }
128 
130  OutputDataType const& Gradient() const { return batchNorm.Gradient(); }
132  OutputDataType& Gradient() { return batchNorm.Gradient(); }
133 
135  bool Deterministic() const { return deterministic; }
137  bool& Deterministic() { return deterministic; }
138 
140  OutputDataType const& TrainingMean() const { return runningMean; }
142  OutputDataType& TrainingMean() { return runningMean; }
143 
145  OutputDataType const& TrainingVariance() const { return runningVariance; }
147  OutputDataType& TrainingVariance() { return runningVariance; }
148 
150  size_t InputSize() const { return size; }
152  size_t InputSize() {return size; }
153 
155  double Epsilon() const { return eps; }
157  double Epsilon() { return eps; }
158 
159 
161  double Momentum() const { return momentum; }
163  double Momentum() { return momentum; }
164 
166  bool Average() const { return average; }
168  bool Average() { return average; }
169 
171  bool Batchsize() const { return batchSize; }
173  bool Batchsize() { return batchSize; }
174 
178  template<typename Archive>
179  void serialize(Archive& ar, const uint32_t /* version */);
180 
181  private:
184 
186  bool reset;
187 
189  size_t size;
190 
192  double eps;
193 
196  bool average;
197 
199  double momentum;
200 
202  size_t batchSize;
203 
208  bool deterministic;
209 
211  OutputDataType runningMean;
212 
214  OutputDataType runningVariance;
215 }; // class InstanceNorm
216 
217 } // namespace ann
218 } // namespace mlpack
219 
220 // Include the implementation.
221 #include "instance_norm_impl.hpp"
222 
223 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Declaration of the Batch Normalization layer class.
Definition: batch_norm.hpp:54
Declaration of the Instance Normalization layer class.
double Epsilon() const
Get the epsilon value.
The core includes that mlpack expects; standard C++ includes, Armadillo, cereal, and a few basic mlpa...
OutputDataType const & Delta() const
Get the delta.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
double Momentum()
Modify the momentum value.
OutputDataType & TrainingVariance()
Modify the variance over the training data.
void Backward(const arma::Mat< eT > &input, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Backward pass through the layer.
OutputDataType const & Gradient() const
Get the gradient.
bool Deterministic() const
Get the value of deterministic parameter.
OutputDataType const & TrainingVariance() const
Get the variance over the training data.
size_t InputSize() const
Get the number of input units / channels.
OutputDataType & Delta()
Modify the delta.
bool Batchsize() const
Get the batchSize parameter.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType const & Parameters() const
Get the parameters.
double Epsilon()
Modify the epsilon value.
bool Average() const
Get the average parameter.
OutputDataType & Parameters()
Modify the parameters.
double Momentum() const
Get the momentum value.
bool Batchsize()
Modify the batchSize parameter.
OutputDataType & OutputParameter()
Modify the output parameter.
bool & Deterministic()
Modify the value of deterministic parameter.
OutputDataType const & OutputParameter() const
Get the output parameter.
OutputDataType & TrainingMean()
Modify the mean over the training data.
size_t InputSize()
Modify the input units/ channels.
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Forward pass of the Instance Normalization layer.
InstanceNorm()
Create the InstanceNorm object.
bool Average()
Modify the average parameter.
OutputDataType const & TrainingMean() const
Get the mean over the training data.