Lably
Skip to content

Pooling layer

Architectural motif in neural networks for aggregating information

  • 7 min read
  • 4 chapters

Related on Lably

Through Neural network (machine learning), Convolutional neural network and Expected value

Convolutional neural network pooling

Pooling is most commonly used in convolutional neural networks (CNN). Below is a description of pooling in 2-dimensional CNNs. The generalization to n-dimensions is immediate.

As notation, we consider a tensor x∈RH×W×C, where H is height, W is width, and C is the number of channels. A pooling layer outputs a tensor y∈RH′×W′×C′.

We define two variables f,s called "filter size" (aka "kernel size") and "stride". Sometimes, it is necessary to use a different filter size and stride for horizontal and vertical directions. In such cases, we define 4 variables:fH,fW,sH,sW.

The receptive field of an entry in the output tensor, y, are all the entries in x that can affect that entry.

Max pooling

Max Pooling (MaxPool) is commonly used in CNNs to reduce the spatial dimensions of feature maps.

DefineMaxPool(x|f,s)0,0,0=max(x0:f−1,0:f−1,0)where 0:f−1 means the range 0,1,…,f−1. Note that we need to avoid the off-by-one error. The next input isMaxPool(x|f,s)1,0,0=max(xs:s+f−1,0:f−1,0)and so on. The receptive field of yi,j,c is xis+f−1,js+f−1,c, so in general,MaxPool(x|f,s)i,j,c=max(xis:is+f−1,js:js+f−1,c)If the horizontal and vertical filter size and strides differ, then in general,MaxPool(x|f,s)i,j,c=max(xisH:isH+fH−1,jsW:jsW+fW−1,c)More succinctly, we can write yk=max({xk′|k′ in the receptive field of k}).

If H is not expressible as ks+f where k is an integer, then for computing the entries of the output tensor on the boundaries, max pooling would attempt to take as inputs variables off the tensor. In this case, how those non-existent variables are handled depends on the padding conditions, illustrated on the right.

Global Max Pooling (GMP) is a specific kind of max pooling where the output tensor has shape RC and the receptive field of yc is all of x0:H,0:W,c. That is, it takes the maximum over each entire channel. It is often used just before the final fully connected layers in a CNN classification head.

Average pooling

Average pooling (AvgPool) is similarly definedAvgPool(x|f,s)i,j,c=average(xis:is+f−1,js:js+f−1,c)=1f2∑k∈is:is+f−1∑l∈js:js+f−1xk,l,cGlobal Average Pooling (GAP) is defined similarly to GMP. It was first proposed in Network-in-Network. Similarly to GMP, it is often used just before the final fully connected layers in a CNN classification head.

Interpolations

There are some interpolations of max pooling and average pooling.

Mixed Pooling is a linear sum of max pooling and average pooling. That is,MixedPool(x|f,s,w)=wMaxPool(x|f,s)+(1−w)AvgPool(x|f,s)where w∈[0,1] is either a hyperparameter, a learnable parameter, or randomly sampled anew every time.

Lp Pooling is similar to average pooling, but uses Lp norm average instead of average:yk=(1N∑k′ in the receptive field of k|xk′|p)1/pwhere N is the size of receptive field, and p≥1 is a hyperparameter. If all activations are non-negative, then average pooling is the case of p=1, and max pooling is the case of p→∞. Square-root pooling is the case of p=2.

Stochastic pooling samples a random activation xk′ from the receptive field with probability xk′∑k″xk″. It is the same as average pooling in expectation.

Softmax pooling is like max pooling, but uses softmax, i.e. ∑k′eβxk′xk′∑k″eβxk″ where β>0. Average pooling is the case of β↓0, and max pooling is the case of β↑∞

Local Importance-based Pooling generalizes softmax pooling by ∑k′eg(xk′)xk′∑k″eg(xk″) where g is a learnable function.

Other poolings

Spatial pyramidal pooling applies max pooling (or any other form of pooling) in a pyramid structure. That is, it applies global max pooling, then applies max pooling to the image divided into 4 equal parts, then 16, etc. The results are then concatenated. It is a hierarchical form of global pooling, and similar to global pooling, it is often used just before a classification head.

Region of Interest Pooling (also known as RoI pooling) is a variant of max pooling used in R-CNNs for object detection. It is designed to take an arbitrarily-sized input matrix, and output a fixed-sized output matrix.

Covariance pooling computes the covariance matrix of the vectors {xk,l,0:C−1}k∈is:is+f−1,l∈js:js+f−1which is then flattened to a C2-dimensional vector yi,j,0:C2−1. Global covariance pooling is used similarly to global max pooling. As average pooling computes the average, which is a first-degree statistic, and covariance is a second-degree statistic, covariance pooling is also called "second-order pooling". It can be generalized to higher-order poolings.

Blur Pooling means applying a blurring method before downsampling. For example, the Rect-2 blur pooling means taking an average pooling at f=2,s=1, then taking every second pixel (identity with s=2).

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Neuroscience