Convolutional layers are the fundamental building blocks of a convolutional neural network, utilized for computer vision applications like image recognition. A convolutional layer applies a filter to an image and extracts features, producing a feature map that may be given to the next convolutional layer, which extracts higher-level information. As a result of layering many convolutional layers, CNNs can distinguish increasingly complex structures and objects in images.
As CNN's are very important, there are some drawbacks or underperformance as well. In this blog, we will be discussing what their drawbacks are and how the concept of pooling comes to the rescue.
Content of this blog:
- What is Pooling?
- Why is Pooling Needed?
- How does pooling work?
- Type of Pooling Layers-
What is Pooling?
A pooling layer is an additional layer that is inserted after the convolutional layer. After a nonlinearity (e.g. ReLU) has been added to the feature maps generated by a convolutional layer, the layers in a model may look like this:
Input Image -> Convolutional Layer -> Nonlinearity -> Pooling Layer
The insertion of a pooling layer after the convolutional layer is a frequent pattern for layer ordering inside a convolutional neural network that may be repeated one or more times in a particular model. The pooling layer works individually on each feature map to generate a new set of the same number of pooled feature maps.
Why is Pooling needed?
The feature map created by the filter is location-dependent, which is a vital issue with convolutional layers. This implies that convolutional neural networks learn to correlate the existence of a particular feature with a specific position in the input picture during training. This might have a negative impact on performance. We prefer that the feature map and network be translation invariant (a fancy expression that means that the location of the feature should not matter).
Focusing on higher-level structures reduces the network's reliance on finer data related to feature position. Pooling is another method for directing the network's attention to higher-level elements. Pooling is often used on the feature map created by a previous convolutional layer and a non-linear activation function in a convolutional neural network.
The feature maps' size is reduced by pooling layers. As a result, it decreases the number of parameters to learn as well as the amount of computation done in the network. The pooling layer summarizes the characteristics in an area of the feature map produced by a convolution layer.
Subsequent operations are carried out on summarized features rather than precisely positioned features created by the convolution layer. As a result, the model is more resistant to changes in the location of the features in the input picture.
In general, pooling is very useful when doing image classification tasks when you only need to identify the existence of a certain item in an image and don't care where it is placed. The fact that pooling filters employ a wider stride than convolutional filters and produce smaller outputs contributes to the network's efficiency and leads to faster training. In other words, location invariance can considerably increase the network's statistical efficiency.
How Does Pooling Work?
The pooling procedure entails sliding a two-dimensional filter across each channel of the feature map and summarizing the features that fall inside the filter's coverage zone. It is fundamentally comparable to the convolution technique. You choose a filter and drag it over the previous convolutional layer's output feature map. The most typical filter size is 22, which is slid across the input with a stride of 2. The pooling filter calculates an output on the receptive field based on the type of pooling operation you've chosen (the part of the feature map under the filter).
The dimensions of output received after a pooling layer for a feature map with dimensions nh x nw x nc are
nh - the height of the feature map
nw - width of the feature map
nc - number of channels in the feature map
f - the size of the filter
s - stride length
Types of Pooling Layers?
Pooling layers can be categorized into three different types discussed below.
Max Pooling: Pooling that chooses the maximum element from the region of the feature map covered by the filter is known as max pooling. As a result, the output of the max-pooling layer would be a feature map that contained the most prominent features of the prior feature map. Max pooling is sensitive to the more conspicuous features and edges in the receptive field because of its emphasis on high values. In practice, max pooling is used more frequently since it is superior at recognizing salient features.
Average Pooling: Average pooling computes the average of the items contained in the filter's feature map area. Thus, while max pooling returns the most prominent feature in a given patch of the feature map, average pooling returns the average of all features in that patch. Average pooling, on the other hand, gives a smoother feature map since it selects averages rather than extreme values. In practice, average pooling is only used to shrink feature maps to a specific size.
Global Pooling: Each channel in the feature map is reduced to a single value via global pooling. As a result, an nh x nw x nc feature map is reduced to 1 x 1 x nc. This is identical to employing a filter with dimensions nh x nw, i.e. the feature map's dimensions. Global pooling down samples the entire feature map to a single value rather than downsampling sections of the input feature map. This is equivalent to setting the pool size to the size of the input feature map. In a model, global pooling may be used to aggressively summarize the existence of a feature in an image. It is also used in models as an alternative to employing a fully linked layer to transition from feature maps to a model's output prediction.
By using pooling, we can extract the features into a smaller, more generic map that merely tells whether or not a feature is present in that particular quadrant. The map decreases with each succeeding layer, maintaining just the crucial information about the existence of the features of interest. As the map shrinks, it becomes less dependent on the position of the feature. As long as the feature was identified within a reasonable distance of the original site, it should be reflected in the map created by the pooling layers.
Pooling, because of its capacity to compress feature maps, can also aid in the classification of pictures of varied sizes. A neural network's classification layer expects inputs in the same format. As a result, we often feed photos of the same standard size. We may summarize various-sized pictures while producing comparable-sized feature maps by adjusting the offsets throughout the pooling step.