Pooling layers
Pooling layers are used in CNNs to reduce the number of parameters in the model and therefore they reduce overfitting. They can be thought of as a type of dimensionality reduction. Similar to convolutional layers, a pooling layer moves over the previous layer but the operation and return value are different. It returns a single value and the operation is usually the maximum value of the cells in that patch, hence the name max-pooling. You can also perform other operations, for example, average pooling, but this is less common. Here is an example of max-pooling using a 2 x 2 block. The first block has the values 7, 0, 6, 6 and the maximum value of these is 7, so the output is 7. Note that padding is not normally used with max-pooling and that it usually applies a stride parameter to move the block. Here, the stride is 2, so once we get the max of the first block, we move across, 2 cells to the right:
We can see that max-pooling reduces the output by a factor of 4; the input was 6 x 6 and the output is 3 x 3. If you have not seen this before, your first reaction is probably disbelief. Why are we throwing away data? Why do we use max-pooling at all? There are three parts to this answer:
- Pooling: It is normally applied after a convolutional layer, so instead of executing over pixels, we execute over matched patterns. Downsizing after convolutional layers does not discard 75% of the input data; there is still enough signal there to find the pattern if it exists.
- Regularization: If you have studied machine learning, you will know that many models have problems with correlated features and that you are generally advised to remove correlated features. In image data, features are highly correlated with the spatial pattern around them. Applying max-pooling reduces the data while maintaining the features.
- Execution speed: When we consider the two earlier reasons, we can see that max-pooling greatly reduces the size of the network without removing too much of the signal. This makes training the model much quicker.
It is important to note the difference in the parameters used in the convolutional layer compared to the pooling layer. In general, a convolutional block is bigger (3 x 3) than the pooling block (2 x 2) and they should not overlap. For example, do not use a 4 x 4 convolutional block and a 2 x 2 pooling block. If they did overlap, the pooling block would just operate over the same convolutional blocks and the model would not train correctly.