23 #ifndef SRC_MLNN_POOLING_HPP_
24 #define SRC_MLNN_POOLING_HPP_
30 namespace convolution {
38 template <
typename eT=
float>
51 MaxPooling(
size_t input_height_,
size_t input_width_,
size_t depth_,
53 std::string name_ =
"MaxPooling") :
54 Layer<eT>::
Layer(input_height_, input_width_, depth_,
55 (input_height_ /window_size_), (input_width_ / window_size_), depth_,
83 LOG(LTRACE) <<
"MaxPooling::forward\n";
86 mic::types::MatrixPtr<eT> batch_x =
s[
'x'];
91 mic::types::MatrixPtr<eT> batch_y =
s[
'y'];
96 mic::types::MatrixPtr<eT> pooling_map =
m[
"pooling_map"];
97 pooling_map->setZero();
106 #pragma omp parallel for
123 size_t maxRow, maxCol;
130 size_t ia = (ib *
Layer<eT>::inputSize()) + ic * input_height * input_width + (iw + maxCol) * input_height + (ih + maxRow);
136 (*pooling_map)[oa] = ia;
139 (*batch_y)[oa] = max_val;
146 LOG(LTRACE) <<
"MaxPooling::forward end\n";
153 LOG(LTRACE) <<
"MaxPooling::backward\n";
156 mic::types::MatrixPtr<eT> batch_dy =
g[
'y'];
159 mic::types::MatrixPtr<eT> batch_dx =
g[
'x'];
162 mic::types::MatrixPtr<eT> pooling_map =
m[
"pooling_map"];
165 #pragma omp parallel for
166 for (
size_t oi = 0; oi < batch_size * Layer<eT>::outputSize(); oi++) {
170 (*batch_dx)[(size_t)(*pooling_map)[oi]] = (*batch_dy)[oi];
174 LOG(LTRACE) <<
"MaxPooling::backward end\n";
183 void update(eT alpha_, eT decay_ = 0.0f) { }
size_t inputSize()
Returns size (length) of inputs.
mic::types::MatrixPtr< eT > lazyReturnInputChannel(mic::types::MatrixPtr< eT > sample_ptr_, size_t sample_number_, size_t channel_number_)
Layer performing max pooling.
size_t input_depth
Number of channels of the input (e.g. 3 for RGB images).
void update(eT alpha_, eT decay_=0.0f)
size_t batch_size
Size (length) of (mini)batch.
size_t outputSize()
Returns size (length) of outputs.
void forward(bool test_=false)
virtual void resizeBatch(size_t batch_size_)
size_t input_height
Height of the input (e.g. 28 for MNIST).
Class representing a multi-layer neural network.
LayerTypes
Enumeration of possible layer types.
mic::types::MatrixArray< eT > s
States - contains input [x] and output [y] matrices.
mic::types::MatrixArray< eT > g
Gradients - contains input [x] and output [y] matrices.
virtual void resizeBatch(size_t batch_size_)
mic::types::MatrixPtr< eT > lazyReturnInputSample(mic::types::MatrixPtr< eT > batch_ptr_, size_t sample_number_)
size_t input_width
Width of the input (e.g. 28 for MNIST).
size_t output_height
Number of receptive fields in a single channel - vertical direction.
MaxPooling(size_t input_height_, size_t input_width_, size_t depth_, size_t window_size_, std::string name_="MaxPooling")
size_t output_width
Number of receptive fields in a single channel - horizontal direction.
Contains a template class representing a layer.
mic::types::MatrixArray< eT > m
Memory - a list of temporal parameters, to be used by the derived classes.