27#ifndef MAXPOOLLAYER_H_
28#define MAXPOOLLAYER_H_
56template <
typename Architecture_t>
60 using Matrix_t =
typename Architecture_t::Matrix_t;
61 using Scalar_t =
typename Architecture_t::Scalar_t;
68 TMaxPoolLayer(
size_t BatchSize,
size_t InputDepth,
size_t InputHeight,
size_t InputWidth,
size_t FilterHeight,
69 size_t FilterWidth,
size_t StrideRows,
size_t StrideCols,
Scalar_t DropoutProbability);
84 void Forward(std::vector<Matrix_t> &input,
bool applyDropout =
false);
90 void Backward(std::vector<Matrix_t> &gradients_backward,
const std::vector<Matrix_t> &activations_backward,
91 std::vector<Matrix_t> &inp1, std::vector<Matrix_t> &inp2);
109template <
typename Architecture_t>
111 size_t filterHeight,
size_t filterWidth,
size_t strideRows,
112 size_t strideCols,
Scalar_t dropoutProbability)
115 filterHeight, filterWidth, strideRows, strideCols, 0, 0, dropoutProbability,
125template <
typename Architecture_t>
127 :
TConvLayer<Architecture_t>(layer), indexMatrix()
135template <
typename Architecture_t>
137 :
TConvLayer<Architecture_t>(layer), indexMatrix()
139 for (
size_t i = 0; i < layer.
fBatchSize; i++) {
145template <
typename Architecture_t>
151template <
typename Architecture_t>
154 for (
size_t i = 0; i < this->GetBatchSize(); i++) {
156 if (applyDropout && (this->GetDropoutProbability() != 1.0)) {
157 Architecture_t::Dropout(input[i], this->GetDropoutProbability());
160 Architecture_t::Downsample(this->GetOutputAt(i), indexMatrix[i], input[i], this->GetInputHeight(),
161 this->GetInputWidth(), this->GetFilterHeight(), this->GetFilterWidth(),
162 this->GetStrideRows(), this->GetStrideCols());
167template <
typename Architecture_t>
169 const std::vector<Matrix_t> & ,
170 std::vector<Matrix_t> & , std::vector<Matrix_t> &
173 for (
size_t i = 0; i < this->GetBatchSize(); i++) {
174 Architecture_t::MaxPoolLayerBackward(gradients_backward[i], this->GetActivationGradients()[i],
175 this->GetIndexMatrix()[i],
176 this->GetInputHeight(), this->GetInputWidth(),
177 this->GetFilterHeight(), this->GetFilterWidth(),
178 this->GetStrideRows(), this->GetStrideCols(), this->GetNLocalViews());
183template <
typename Architecture_t>
186 std::cout <<
" POOL Layer: \t";
187 std::cout <<
"( W = " << this->GetWidth() <<
" , ";
188 std::cout <<
" H = " << this->GetHeight() <<
" , ";
189 std::cout <<
" D = " << this->GetDepth() <<
" ) ";
191 std::cout <<
"\t Filter ( W = " << this->GetFilterWidth() <<
" , ";
192 std::cout <<
" H = " << this->GetFilterHeight() <<
" ) ";
194 if (this->GetOutput().size() > 0) {
195 std::cout <<
"\tOutput = ( " << this->GetOutput().size() <<
" , " << this->GetOutput()[0].GetNrows() <<
" , " << this->GetOutput()[0].GetNcols() <<
" ) ";
197 std::cout << std::endl;
201template <
typename Architecture_t>
215template <
typename Architecture_t>
size_t fNLocalViews
The number of local views in one image.
size_t GetNLocalViews() const
typename Architecture_t::Scalar_t Scalar_t
Generic Max Pooling Layer class.
std::vector< Matrix_t > & GetIndexMatrix()
void Backward(std::vector< Matrix_t > &gradients_backward, const std::vector< Matrix_t > &activations_backward, std::vector< Matrix_t > &inp1, std::vector< Matrix_t > &inp2)
Depending on the winning units determined during the Forward pass, it only forwards the derivatives t...
typename Architecture_t::Matrix_t Matrix_t
TMaxPoolLayer(size_t BatchSize, size_t InputDepth, size_t InputHeight, size_t InputWidth, size_t FilterHeight, size_t FilterWidth, size_t StrideRows, size_t StrideCols, Scalar_t DropoutProbability)
Constructor.
virtual void ReadWeightsFromXML(void *parent)
Read the information and the weights about the layer from XML node.
void Print() const
Prints the info about the layer.
std::vector< Matrix_t > indexMatrix
Matrix of indices for the backward pass.
virtual void AddWeightsXMLTo(void *parent)
Writes the information and the weights about the layer in an XML node.
void Forward(std::vector< Matrix_t > &input, bool applyDropout=false)
Computes activation of the layer for the given input.
const std::vector< Matrix_t > & GetIndexMatrix() const
Getters.
~TMaxPoolLayer()
Destructor.
size_t fBatchSize
Batch size used for training and evaluation.
size_t fDepth
The depth of the layer.
size_t GetBatchSize() const
Getters.
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=0)
create new child element for parent node
ERegularization
Enum representing the regularization type applied for a given layer.
EActivationFunction
Enum that represents layer activation functions.
create variable transformations