ArticleslgStudy

computer science

Pooling layer

Pooling layer is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Pooling layer rather than just read about it. In short: In neural networks, a pooling layer is a kind of network layer that downsamples and aggregates information that is dispersed among many vectors into fewer vectors. It has several uses.

Pooling layer — main illustration
Pooling layer — illustration

Key takeaways

  • Pooling layer belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Pooling layer to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Pooling layer from memory before moving on to harder problems.

Reference excerpt

In neural networks, a pooling layer is a kind of network layer that downsamples and aggregates information that is dispersed among many vectors into fewer vectors. It has several uses. It removes redundant information, thus reducing the amount of computation and memory required, which makes the model more robust to small variations in the input; and it increases the receptive field of neurons in later layers in the network.

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∈ℝH×W×C, where H is height, W is width, and C is the number of channels. A pooling layer outputs a tensor y∈ℝH′×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 ℝC 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).

Vision Transformer pooling In Vision Transformers (ViT), there are the following common kinds of poolings. BERT-like pooling uses a dummy [CLS] token, "classification". For classification, the output at [CLS] is the classification token, which is then processed by a LayerNorm-feedforward-softmax module into a probability distribution, which is the network's prediction of class probability distribution. This is the one used by the original ViT and Masked Autoencoder. Global average pooling (GAP) does not use the dummy token, but simply takes the average of all output tokens as the classification token. It was mentioned in the original ViT as being equally good. Multihead attention pooling (MAP) applies a multi headed attention block to pooling. Specifically, it takes as input a list of vectors x1,x2,…,xn, which might be thought of as the output vectors of a layer of a ViT. It then applies a feedforward layer FFN on each vector, resulting in a matrix V=[FFN(v1),…,FFN(vn)]. This is then sent to a multi-headed attention, resulting in MultiheadedAttention(Q,V,V), where Q is a matrix of trainable parameters. This was first proposed in the Set Transformer architecture. Later papers demonstrated that GAP and MAP both perform better than BERT-like pooling.

… excerpt ends here. Continue reading the full article.

Illustrations

Pooling layer: Three example padding conditions. Replication condition means that the pixel outside is padded with the closest pixel inside. The reflection padding is where the pixel outside is padded with the pixel inside, reflected across the boundary of the image. The circular padding is where the pixel outside wraps around to the other side of the image.
Three example padding conditions. Replication condition means that the pixel outside is padded with the closest pixel inside. The reflection padding is where the pixel outside is padded with the pixel inside, reflected across the boundary of the image. The circular padding is where the pixel outside wraps around to the other side of the image.
Pooling layer: RoI pooling to size 2x2. In this example, the RoI proposal has size 7x5. It is divided into 4 rectangles. Because 7 is not divisible by 2, it is divided to the nearest integers, as 7 = 3 + 4. Similarly, 5 is divided to 2 + 3. This gives 4 sub-rectangles. The maximum of each sub-rectangle is taken. This is the output of the RoI pooling.
RoI pooling to size 2x2. In this example, the RoI proposal has size 7x5. It is divided into 4 rectangles. Because 7 is not divisible by 2, it is divided to the nearest integers, as 7 = 3 + 4. Similarly, 5 is divided to 2 + 3. This gives 4 sub-rectangles. The maximum of each sub-rectangle is taken. This is the output of the RoI pooling.

Worked examples

Example 1 — a first encounter with Pooling layer

Start with the simplest possible case. Write down what Pooling layer claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Pooling layer before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Pooling layer ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Pooling layer

In research
Pooling layer appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Pooling layer in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Pooling layer is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computational neuroscience, Computer vision, Neural network architectures, so understanding it makes those chapters shorter.
In everyday life
Look for Pooling layer outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Pooling layer” →

How to study Pooling layer in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Pooling layer means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Pooling layer out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Pooling layer in simple terms?

In neural networks, a pooling layer is a kind of network layer that downsamples and aggregates information that is dispersed among many vectors into fewer vectors. It has several uses.

Why does Pooling layer matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Pooling layer?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Pooling layer.

Tags

  • Computational neuroscience
  • Computer vision
  • Neural network architectures

Keep exploring