27#ifndef MAXPOOLLAYER_H_
28#define MAXPOOLLAYER_H_
58template <
typename Architecture_t>
62 using Tensor_t =
typename Architecture_t::Tensor_t;
63 using Matrix_t =
typename Architecture_t::Matrix_t;
64 using Scalar_t =
typename Architecture_t::Scalar_t;
107 TMaxPoolLayer(
size_t BatchSize,
size_t InputDepth,
size_t InputHeight,
size_t InputWidth,
size_t FilterHeight,
108 size_t FilterWidth,
size_t StrideRows,
size_t StrideCols,
Scalar_t DropoutProbability);
167template <
typename Architecture_t>
169 size_t filterHeight,
size_t filterWidth,
size_t strideRows,
170 size_t strideCols,
Scalar_t dropoutProbability)
172 batchSize, inputDepth, inputHeight, inputWidth, inputDepth,
173 TConvLayer<Architecture_t>::calculateDimension(inputHeight, filterHeight, 0, strideRows),
174 TConvLayer<Architecture_t>::calculateDimension(inputWidth, filterWidth, 0, strideCols), 0, 0, 0, 0, 0,
176 batchSize, inputDepth,
177 TConvLayer<Architecture_t>::calculateNLocalViews(inputHeight, filterHeight, 0, strideRows, inputWidth,
178 filterWidth, 0, strideCols),
180 fFilterDepth(inputDepth), fFilterHeight(filterHeight), fFilterWidth(filterWidth), fStrideRows(strideRows),
181 fStrideCols(strideCols),
182 fNLocalViews(
TConvLayer<Architecture_t>::calculateNLocalViews(inputHeight, filterHeight, 0, strideRows,
183 inputWidth, filterWidth, 0, strideCols)),
184 fDropoutProbability(dropoutProbability), fIndexTensor(batchSize, inputDepth, fNLocalViews)
191template <
typename Architecture_t>
193 :
VGeneralLayer<Architecture_t>(layer), fFilterDepth(layer->GetFilterDepth()),
194 fFilterHeight(layer->GetFilterHeight()), fFilterWidth(layer->GetFilterWidth()),
195 fStrideRows(layer->GetStrideRows()), fStrideCols(layer->GetStrideCols()), fNLocalViews(layer->GetNLocalViews()),
196 fDropoutProbability(layer->GetDropoutProbability()), fIndexTensor(layer->GetIndexTensor().GetShape())
203template <
typename Architecture_t>
205 :
VGeneralLayer<Architecture_t>(layer), fFilterDepth(layer.fFilterDepth), fFilterHeight(layer.fFilterHeight),
206 fFilterWidth(layer.fFilterWidth), fStrideRows(layer.fStrideRows), fStrideCols(layer.fStrideCols),
207 fNLocalViews(layer.fNLocalViews), fDropoutProbability(layer.fDropoutProbability),
208 fIndexTensor(layer.GetIndexTensor().GetShape())
215template <
typename Architecture_t>
219 ReleaseDescriptors();
221 fDescriptors =
nullptr;
227 fWorkspace =
nullptr;
232template <
typename Architecture_t>
235 if (applyDropout && (this->GetDropoutProbability() != 1.0)) {
236 Architecture_t::DropoutForward(
input, fDescriptors, fWorkspace, this->GetDropoutProbability());
239 Architecture_t::Downsample(
242 this->GetFilterHeight(), this->GetFilterWidth(), this->GetStrideRows(), this->GetStrideCols());
246template <
typename Architecture_t>
251 if (this->GetDropoutProbability() != 1.0) {
252 Architecture_t::DropoutBackward(this->GetActivationGradients(), fDescriptors, fWorkspace);
254 Architecture_t::MaxPoolLayerBackward(
255 gradients_backward, this->GetActivationGradients(), fIndexTensor, activations_backward, this->GetOutput(),
258 this->GetFilterHeight(), this->GetFilterWidth(), this->GetStrideRows(), this->GetStrideCols(),
259 this->GetNLocalViews());
263template <
typename Architecture_t>
266 std::cout <<
" POOL Layer: \t";
267 std::cout <<
"( W = " << this->GetWidth() <<
" , ";
268 std::cout <<
" H = " << this->GetHeight() <<
" , ";
269 std::cout <<
" D = " << this->GetDepth() <<
" ) ";
271 std::cout <<
"\t Filter ( W = " << this->GetFilterWidth() <<
" , ";
272 std::cout <<
" H = " << this->GetFilterHeight() <<
" ) ";
274 if (this->GetOutput().GetSize() > 0) {
275 std::cout <<
"\tOutput = ( " << this->GetOutput().GetFirstSize() <<
" , " << this->GetOutput().GetCSize()
276 <<
" , " << this->GetOutput().GetHSize() <<
" , " << this->GetOutput().GetWSize() <<
" ) ";
278 std::cout << std::endl;
282template <
typename Architecture_t>
296template <
typename Architecture_t>
303template <
typename Architecture_t>
305 Architecture_t::InitializePoolDescriptors(fDescriptors,
this);
308template <
typename Architecture_t>
310 Architecture_t::ReleasePoolDescriptors(fDescriptors);
314template <
typename Architecture_t>
325template <
typename Architecture_t>
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Generic Max Pooling Layer class.
typename Architecture_t::Tensor_t Tensor_t
const TWorkspace * GetWorkspace() const
void InitializeWorkspace()
TDescriptors * GetDescriptors()
typename Architecture_t::AlgorithmHelper_t AlgorithmHelper_t
Used for weight grad backward pass.
TWorkspace * GetWorkspace()
typename Architecture_t::Matrix_t Matrix_t
void ReleaseDescriptors()
Scalar_t GetDropoutProbability() const
typename Architecture_t::EmptyDescriptor_t WeightsDescriptor_t
size_t fFilterHeight
The height of the filter.
typename Architecture_t::ReduceTensorDescriptor_t ReduceTensorDescriptor_t
void Forward(Tensor_t &input, bool applyDropout=true)
Computes activation of the layer for the given input.
size_t GetStrideRows() const
TDescriptors * fDescriptors
Keeps the convolution, activations and filter descriptors.
size_t GetFilterWidth() const
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.
typename Architecture_t::AlgorithmForward_t AlgorithmForward_t
Forward layer operation.
Tensor_t fIndexTensor
Matrix of indices for the backward pass.
size_t fNLocalViewPixels
The number of pixels in one local image view.
void InitializeDescriptors()
typename Architecture_t::DropoutDescriptor_t HelperDescriptor_t
Scalar_t fDropoutProbability
Probability that an input is active.
virtual void ReadWeightsFromXML(void *parent)
Read the information and the weights about the layer from XML node.
size_t fStrideCols
The number of column pixels to slid the filter each step.
size_t fFilterWidth
The width of the filter.
typename Architecture_t::AlgorithmBackward_t AlgorithmBackward_t
Backward layer operation.
void Print() const
Prints the info about the layer.
size_t fNLocalViews
The number of local views in one image.
typename Architecture_t::Scalar_t Scalar_t
Tensor_t & GetIndexTensor()
void Backward(Tensor_t &gradients_backward, const Tensor_t &activations_backward)
Depending on the winning units determined during the Forward pass, it only forwards the derivatives t...
const Tensor_t & GetIndexTensor() const
size_t fFilterDepth
The depth of the filter.
virtual void AddWeightsXMLTo(void *parent)
Writes the information and the weights about the layer in an XML node.
typename Architecture_t::PoolingDescriptor_t LayerDescriptor_t
typename Architecture_t::AlgorithmDataType_t AlgorithmDataType_t
size_t GetFilterHeight() const
size_t GetNLocalViews() const
const TDescriptors * GetDescriptors() const
virtual ~TMaxPoolLayer()
Destructor.
size_t fStrideRows
The number of row pixels to slid the filter each step.
size_t GetStrideCols() const
size_t GetFilterDepth() const
Getters.
Generic General Layer class.
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=nullptr)
create new child element for parent node
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
create variable transformations