pooling_layer.h
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// P O O L I N G L A Y E R C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#ifndef POOLINGLAYER_H
10#define POOLINGLAYER_H
11
12// System includes
13
14#include <cmath>
15#include <cstdlib>
16#include <ctype.h>
17#include <fstream>
18#include <iostream>
19#include <string>
20#include <sstream>
21
22// OpenNN includes
23
24#include "config.h"
25#include "layer.h"
26
27#include "statistics.h"
28
29#include "perceptron_layer.h"
30#include "convolutional_layer.h"
31
32namespace OpenNN
33{
34
37
38class PoolingLayer : public Layer
39{
40
41public:
42
44
45 enum class PoolingMethod{NoPooling, MaxPooling, AveragePooling};
46
47 // Constructors
48
49 explicit PoolingLayer();
50
51 explicit PoolingLayer(const Tensor<Index, 1>&);
52
53 explicit PoolingLayer(const Tensor<Index, 1>&, const Tensor<Index, 1>&);
54
55 // Destructor
56
57 virtual ~PoolingLayer();
58
59 // Get methods
60
61
62 Tensor<Index, 1> get_outputs_dimensions() const;
63
64 Index get_inputs_number() const;
65
66 Index get_inputs_channels_number() const;
67
68 Index get_inputs_rows_number() const;
69
70 Index get_inputs_columns_number() const;
71
72 Index get_neurons_number() const;
73
74 Index get_outputs_rows_number() const;
75
76 Index get_outputs_columns_number() const;
77
78 Index get_padding_width() const;
79
80 Index get_row_stride() const;
81
82 Index get_column_stride() const;
83
84 Index get_pool_rows_number() const;
85
86 Index get_pool_columns_number() const;
87
88 Index get_parameters_number() const;
89
90 Tensor<type, 1> get_parameters() const;
91
93
94 // Set methods
95
96 void set_inputs_number(const Index&) {}
97 void set_neurons_number(const Index&) {}
98
99 void set_input_variables_dimensions(const Tensor<Index, 1>&);
100
101 void set_padding_width(const Index&);
102
103 void set_row_stride(const Index&);
104
105 void set_column_stride(const Index&);
106
107 void set_pool_size(const Index&, const Index&);
108
110
111 void set_default();
112
113 // Outputs
114
115 Tensor<type, 4> calculate_outputs(const Tensor<type, 4>&);
116
117 void calculate_activations(const Tensor<type, 4>&, Tensor<type, 4>&) {}
118
119 Tensor<type, 4> calculate_no_pooling_outputs(const Tensor<type, 4>&) const;
120
121 Tensor<type, 4> calculate_max_pooling_outputs(const Tensor<type, 4>&) const;
122
123 Tensor<type, 4> calculate_average_pooling_outputs(const Tensor<type, 4>&) const;
124
125 // Activations derivatives
126
127 Tensor<type, 2> calculate_activations_derivatives(const Tensor<type, 2>&) const;
128
129 void calculate_activations_derivatives(const Tensor<type, 2>&, Tensor<type, 2>&) const
130 {
131
132 }
133
134 // First order activations
135
136 void forward_propagate(const Tensor<type, 4>&, LayerForwardPropagation*)
137 {
138 }
139
140 // Delta methods
141
142 Tensor<type, 4> calculate_hidden_delta(Layer*, const Tensor<type, 4>&, const Tensor<type, 4>&, const Tensor<type, 4>&) const;
143
144 Tensor<type, 4> calculate_hidden_delta_convolutional(ConvolutionalLayer*, const Tensor<type, 4>&, const Tensor<type, 4>&, const Tensor<type, 4>&) const;
145 Tensor<type, 4> calculate_hidden_delta_pooling(PoolingLayer*, const Tensor<type, 4>&, const Tensor<type, 4>&, const Tensor<type, 4>&) const;
146 Tensor<type, 4> calculate_hidden_delta_perceptron(PerceptronLayer*, const Tensor<type, 4>&, const Tensor<type, 4>&, const Tensor<type, 4>&) const;
147 Tensor<type, 4> calculate_hidden_delta_probabilistic(ProbabilisticLayer*, const Tensor<type, 4>&, const Tensor<type, 4>&, const Tensor<type, 4>&) const;
148
149 // Gradient methods
150
151 Tensor<type, 1> calculate_error_gradient(const Tensor<type, 2>&, const LayerForwardPropagation&, const Tensor<type, 2>&);
152
153protected:
154
155 Tensor<Index, 1> input_variables_dimensions;
156
157 Index pool_rows_number = 2;
158
159 Index pool_columns_number = 2;
160
161 Index padding_width = 0;
162
163 Index row_stride = 1;
164
165 Index column_stride = 1;
166
167 PoolingMethod pooling_method = PoolingMethod::AveragePooling;
168
169#ifdef OPENNN_CUDA
170 #include "../../opennn-cuda/opennn-cuda/pooling_layer_cuda.h"
171#endif
172
173};
174}
175
176#endif // POOLING_LAYER_H
177
This abstract class represents the concept of layer of neurons in OpenNN.
Definition: layer.h:53
void set_input_variables_dimensions(const Tensor< Index, 1 > &)
virtual ~PoolingLayer()
Destructor.
Tensor< type, 4 > calculate_max_pooling_outputs(const Tensor< type, 4 > &) const
Tensor< type, 4 > calculate_average_pooling_outputs(const Tensor< type, 4 > &) const
Index get_column_stride() const
Returns the pooling filter's column stride.
Index get_inputs_number() const
Returns the number of inputs of the layer.
Tensor< type, 4 > calculate_outputs(const Tensor< type, 4 > &)
Index get_outputs_rows_number() const
Returns the number of rows of the layer's output.
void set_pooling_method(const PoolingMethod &)
void set_default()
Sets the layer type to Layer::Pooling.
Index get_inputs_channels_number() const
Returns the number of channels of the layers' input.
Tensor< type, 4 > calculate_no_pooling_outputs(const Tensor< type, 4 > &) const
Index get_pool_rows_number() const
Returns the number of rows of the pooling filter.
Index get_inputs_rows_number() const
Returns the number of rows of the layer's input.
Index get_inputs_columns_number() const
Returns the number of columns of the layer's input.
void set_row_stride(const Index &)
Index get_outputs_columns_number() const
Returns the number of columns of the layer's output.
void set_pool_size(const Index &, const Index &)
void set_column_stride(const Index &)
PoolingMethod
Enumeration of available methods for pooling data.
Definition: pooling_layer.h:45
Index get_padding_width() const
Returns the padding width.
Index get_neurons_number() const
Returns the number of neurons the layer applies to an image.
void set_padding_width(const Index &)
Tensor< Index, 1 > get_outputs_dimensions() const
Returns the layer's outputs dimensions.
Index get_row_stride() const
Returns the pooling filter's row stride.
PoolingMethod get_pooling_method() const
Returns the pooling method.
Index get_parameters_number() const
Returns the number of parameters of the layer.
Index get_pool_columns_number() const
Returns the number of columns of the pooling filter.
Tensor< type, 1 > get_parameters() const
Returns the layer's parameters.