mlpack 3.4.2
spatial_dropout.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_METHODS_ANN_LAYER_SPATIAL_DROPOUT_HPP
13#define MLPACK_METHODS_ANN_LAYER_SPATIAL_DROPOUT_HPP
14
15#include <mlpack/prereqs.hpp>
17
18namespace mlpack {
19namespace ann {
20
44template <
45 typename InputDataType = arma::mat,
46 typename OutputDataType = arma::mat
47>
49{
50 public:
59 SpatialDropout(const size_t size, const double ratio = 0.5);
60
67 template<typename eT>
68 void Forward(const arma::Mat<eT>& input, arma::Mat<eT>& output);
69
77 template<typename eT>
78 void Backward(const arma::Mat<eT>& input,
79 const arma::Mat<eT>& gy,
80 arma::Mat<eT>& g);
81
83 OutputDataType const& OutputParameter() const { return outputParameter; }
85 OutputDataType& OutputParameter() { return outputParameter; }
86
88 OutputDataType const& Delta() const { return delta; }
90 OutputDataType& Delta() { return delta; }
91
93 size_t Size() const { return size; }
94
96 size_t& Size() { return size; }
97
99 bool Deterministic() const { return deterministic; }
101 bool& Deterministic() { return deterministic; }
102
104 double Ratio() const { return ratio; }
105
107 void Ratio(const double r)
108 {
109 ratio = r;
110 scale = 1.0 / (1.0 - ratio);
111 }
112
116 template<typename Archive>
117 void serialize(Archive& ar, const unsigned int /* version */);
118
119 private:
121 OutputDataType delta;
122
124 OutputDataType outputParameter;
125
127 OutputDataType mask;
128
130 size_t size;
131
133 double ratio;
134
136 double scale;
137
139 bool reset;
140
142 size_t batchSize;
143
145 size_t inputSize;
146
148 bool deterministic;
149}; // class SpatialDropout
150
151} // namespace ann
152} // namespace mlpack
153
154// Include implementation.
155#include "spatial_dropout_impl.hpp"
156
157#endif
Implementation of the SpatialDropout layer.
double Ratio() const
Get the probability value.
OutputDataType const & Delta() const
Get the delta.
SpatialDropout(const size_t size, const double ratio=0.5)
Create the SpatialDropout object using the specified parameters.
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of the SpatialDropout layer.
size_t & Size()
Modify the number of channels.
OutputDataType const & OutputParameter() const
Get the output parameter.
size_t Size() const
Get the number of channels.
void Backward(const arma::Mat< eT > &input, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of the SpatialDropout layer.
SpatialDropout()
Create the SpatialDropout object.
void Ratio(const double r)
Modify the probability value.
bool & Deterministic()
Modify the value of the deterministic parameter.
bool Deterministic() const
Get the value of the deterministic parameter.
OutputDataType & OutputParameter()
Modify the output parameter.
void serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Delta()
Modify 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.