Pooling layer explained

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.[1] It has several uses. It removes redundant information, reducing the amount of computation and memory required, makes the model more robust to small variations in the input, and 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\in\RH

, where

H

is height,

W

is width, and

C

is the number of channels. A pooling layer outputs a tensor

y\in\RH'

.

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.

Define\mathrm(x | f, s)_ = \max(x_)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 is\mathrm(x | f, s)_ = \max(x_)and so on. The receptive field of

yi,

is

xis

, so in general,\mathrm(x | f, s)_ = \mathrm(x_)If the horizontal and vertical filter size and strides differ, then in general,\mathrm(x | f, s)_ = \mathrm(x_)More succinctly, we can write

yk=max(\{xk'|k'inthereceptivefieldofk\})

. 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,

. 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 defined\mathrm(x | f, s)_ = \mathrm(x_) = \frac \sum_\sum_ x_Global Average Pooling (GAP) is defined similarly to GMP. It was first proposed in Network-in-Network.[2] 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 maxpooling and average pooling.[3] That is,

\mathrm(x | f, s, w) = w \mathrm(x | f, s) + (1-w)\mathrm(x | f, s)where

w\in[0,1]

is either a hyperparameter, a learnable parameter, or randomly sampled anew every time.

Lp Pooling is like average pooling, but uses Lp norm average instead of average:y_k = \left(\frac 1N \sum_ |x_|^p\right)^where

N

is the size of receptive field, and

p\geq1

is a hyperparameter. If all activations are non-negative, then average pooling is the case of

p=1

, and maxpooling is the case of

p\toinfty

. Square-root pooling is the case of

p=2

.[4]

Stochastic pooling samples a random activation

xk'

from the receptive field with probability
xk'
\sumk''xk''
. It is the same as average pooling in expectation.[5]

Softmax pooling is like maxpooling, but uses softmax, i.e.

\sum
\betaxk'
e
xk'
k'
\sum
\betaxk''
e
k''
where

\beta>0

. Average pooling is the case of

\beta\downarrow0

, and maxpooling is the case of

\beta\uparrowinfty

Local Importance-based Pooling generalizes softmax pooling by

\sum
g(xk')
e
xk'
k'
\sum
g(xk'')
e
k''
where

g

is a learnable function.[6]

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.[7]

Region of Interest Pooling (also known as RoI pooling) is a variant of max pooling used in R-CNNs for object detection.[8] 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 \_which is then flattened to a

C2

-dimensional vector
y
i,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.[9] [10]

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

).[11]

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[12] and Masked Autoencoder.[13]

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 multiheaded 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 multiheaded attention, resulting in

MultiheadedAttention(Q,V,V)

, where

Q

is a matrix of trainable parameters. This was first proposed in the Set Transformer architecture.[14]

Later papers demonstrated that GAP and MAP both perform better than BERT-like pooling.[15] [16]

Graph neural network pooling

In graph neural networks (GNN), there are also two forms of pooling: global and local. Global pooling can be reduced to a local pooling where the receptive field is the entire output.

  1. Local pooling: a local pooling layer coarsens the graph via downsampling. Local pooling is used to increase the receptive field of a GNN, in a similar fashion to pooling layers in convolutional neural networks. Examples include k-nearest neighbours pooling, top-k pooling,[17] and self-attention pooling.
  2. Global pooling: a global pooling layer, also known as readout layer, provides fixed-size representation of the whole graph. The global pooling layer must be permutation invariant, such that permutations in the ordering of graph nodes and edges do not alter the final output. Examples include element-wise sum, mean or maximum.

Local pooling layers coarsen the graph via downsampling. We present here several learnable local pooling strategies that have been proposed.[18] For each cases, the input is the initial graph is represented by a matrix

X

of node features, and the graph adjacency matrix

A

. The output is the new matrix

X'

of node features, and the new graph adjacency matrix

A'

.

Top-k pooling

We first set

y=

Xp
\Vertp\Vert

where

p

is a learnable projection vector. The projection vector

p

computes a scalar projection value for each graph node.

The top-k pooling layer can then be formalised as follows:

X'=(X\odotsigmoid(y))i

A'=Ai,

where

i=topk(y)

is the subset of nodes with the top-k highest projection scores,

\odot

denotes element-wise matrix multiplication, and

sigmoid( ⋅ )

is the sigmoid function. In other words, the nodes with the top-k highest projection scores are retained in the new adjacency matrix

A'

. The

sigmoid( ⋅ )

operation makes the projection vector

p

trainable by backpropagation, which otherwise would produce discrete outputs.

Self-attention pooling

We first set

y=GNN(X,A)

where

GNN

is a generic permutation equivariant GNN layer (e.g., GCN, GAT, MPNN).

The Self-attention pooling layer[19] can then be formalised as follows:

X'=(X\odoty)i

A'=Ai,

where

i=topk(y)

is the subset of nodes with the top-k highest projection scores,

\odot

denotes element-wise matrix multiplication.

The self-attention pooling layer can be seen as an extension of the top-k pooling layer. Differently from top-k pooling, the self-attention scores computed in self-attention pooling account both for the graph features and the graph topology.

History

In early 20th century, neuroanatomists noticed a certain motif where multiple neurons synapse to the same neuron. This was given a functional explanation as "local pooling", which makes vision translation-invariant. (Hartline, 1940)[20] gave supporting evidence for the theory by electrophysiological experiments on the receptive fields of retinal ganglion cells. The Hubel and Wiesel experiments showed that the vision system in cats is similar to a convolutional neural network, with some cells summing over inputs from the lower layer.[21] See (Westheimer, 1965)[22] for citations to these early literature.

During the 1970s, to explain the effects of depth perception, some such as (Julesz and Chang, 1976)[23] proposed that the vision system implements a disparity-selective mechanism by global pooling, where the outputs from matching pairs of retinal regions in the two eyes are pooled in higher order cells. See [24] for citations to these early literature.

In artificial neural networks, max pooling was used in 1990 for speech processing (1-dimensional convolution),[25] and for image processing, was first used in the Cresceptron of 1992.[26]

See also

References

  1. Book: Zhang . Aston . Dive into deep learning . Lipton . Zachary . Li . Mu . Smola . Alexander J. . 2024 . Cambridge University Press . 978-1-009-38943-3 . Cambridge New York Port Melbourne New Delhi Singapore . 7.5. Pooling . https://d2l.ai/chapter_convolutional-neural-networks/pooling.html.
  2. 1312.4400 . cs.NE . Min . Lin . Qiang . Chen . Network In Network . 2013 . Yan . Shuicheng.
  3. Book: Yu . Dingjun . Rough Sets and Knowledge Technology . Wang . Hanli . Chen . Peiqiu . Wei . Zhihua . 2014 . Springer International Publishing . 978-3-319-11740-9 . Miao . Duoqian . Lecture Notes in Computer Science . 8818 . Cham . 364–375 . Mixed Pooling for Convolutional Neural Networks . 10.1007/978-3-319-11740-9_34 . Pedrycz . Witold . Ślȩzak . Dominik . Peters . Georg . Hu . Qinghua . Wang . Ruizhi . https://link.springer.com/chapter/10.1007/978-3-319-11740-9_34.
  4. Boureau . Y-Lan . Ponce . Jean . LeCun . Yann . 2010-06-21 . A theoretical analysis of feature pooling in visual recognition . Proceedings of the 27th International Conference on International Conference on Machine Learning . ICML'10 . Madison, WI, USA . Omnipress . 111–118 . 978-1-60558-907-7.
  5. Zeiler . Matthew D. . Stochastic Pooling for Regularization of Deep Convolutional Neural Networks . 2013-01-15 . 1301.3557 . Fergus . Rob. cs.LG .
  6. Gao . Ziteng . Wang . Limin . Wu . Gangshan . 2019 . LIP: Local Importance-Based Pooling . 3355–3364. 1908.04156 .
  7. He . Kaiming . Zhang . Xiangyu . Ren . Shaoqing . Sun . Jian . 2015-09-01 . Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition . IEEE Transactions on Pattern Analysis and Machine Intelligence . 37 . 9 . 1904–1916 . 1406.4729 . 10.1109/TPAMI.2015.2389824 . 0162-8828 . 26353135 . 2015ITPAM..37.1904H .
  8. Book: Zhang . Aston . Dive into deep learning . Lipton . Zachary . Li . Mu . Smola . Alexander J. . 2024 . Cambridge University Press . 978-1-009-38943-3 . Cambridge New York Port Melbourne New Delhi Singapore . 14.8. Region-based CNNs (R-CNNs) . https://d2l.ai/chapter_computer-vision/rcnn.html.
  9. Book: Tuzel . Oncel . Region Covariance: A Fast Descriptor for Detection and Classification . 2006 . Computer Vision – ECCV 2006 . 3952 . 589–600 . Leonardis . Aleš . http://link.springer.com/10.1007/11744047_45 . 2024-09-09 . Berlin, Heidelberg . Springer Berlin Heidelberg . 10.1007/11744047_45 . 978-3-540-33834-5 . Porikli . Fatih . Meer . Peter . Bischof . Horst . Pinz . Axel.
  10. Wang . Qilong . Xie . Jiangtao . Zuo . Wangmeng . Zhang . Lei . Li . Peihua . 2020 . Deep CNNs Meet Global Covariance Pooling: Better Representation and Generalization . IEEE Transactions on Pattern Analysis and Machine Intelligence . 43 . 8 . 2582–2597 . 10.1109/TPAMI.2020.2974833 . 32086198 . 0162-8828. 1904.06836 .
  11. Zhang . Richard . 2018-09-27 . Making Convolutional Networks Shift-Invariant Again . 1904.11486 .
  12. 2010.11929 . cs.CV . Alexey . Dosovitskiy . Lucas . Beyer . An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale . 2021-06-03 . Kolesnikov . Alexander . Weissenborn . Dirk . Zhai . Xiaohua . Unterthiner . Thomas . Dehghani . Mostafa . Minderer . Matthias . Heigold . Georg . Gelly . Sylvain . Uszkoreit . Jakob.
  13. Book: He . Kaiming . Chen . Xinlei . Xie . Saining . Li . Yanghao . Dollar . Piotr . Girshick . Ross . Masked Autoencoders Are Scalable Vision Learners . June 2022 . 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) . http://dx.doi.org/10.1109/cvpr52688.2022.01553 . 15979–15988 . IEEE . 10.1109/cvpr52688.2022.01553. 2111.06377 . 978-1-6654-6946-3 .
  14. Lee . Juho . Lee . Yoonho . Kim . Jungtaek . Kosiorek . Adam . Choi . Seungjin . Teh . Yee Whye . 2019-05-24 . Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks . Proceedings of the 36th International Conference on Machine Learning . PMLR . 3744–3753. 1810.00825 .
  15. Book: Zhai . Xiaohua . Kolesnikov . Alexander . Houlsby . Neil . Beyer . Lucas . Scaling Vision Transformers . June 2022 . 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) . http://dx.doi.org/10.1109/cvpr52688.2022.01179 . 1204–1213 . IEEE . 10.1109/cvpr52688.2022.01179. 2106.04560 . 978-1-6654-6946-3 .
  16. Karamcheti . Siddharth . Language-Driven Representation Learning for Robotics . 2023-02-24 . 2302.12766 . Nair . Suraj . Chen . Annie S. . Kollar . Thomas . Finn . Chelsea . Sadigh . Dorsa . Liang . Percy. cs.RO .
  17. Gao . Hongyang . Ji . Shuiwang Ji . Graph U-Nets . 2019 . cs.LG . 1905.05178.
  18. Liu . Chuang . Zhan . Yibing . Li . Chang . Du . Bo . Wu . Jia . Hu . Wenbin . Liu . Tongliang . Tao . Dacheng . Graph Pooling for Graph Neural Networks: Progress, Challenges, and Opportunities . 2022 . cs.LG . 2204.07321.
  19. Lee . Junhyun . Lee . Inyeop . Kang . Jaewoo . Self-Attention Graph Pooling . 2019 . cs.LG . 1904.08082.
  20. Hartline . H. K. . 1940-09-30 . The Receptive Fields of Optic Nerve Fibers . American Journal of Physiology. Legacy Content . 130 . 4 . 690–699 . 10.1152/ajplegacy.1940.130.4.690 . 0002-9513. subscription .
  21. Hubel . D. H. . Wiesel . T. N. . January 1962 . Receptive fields, binocular interaction and functional architecture in the cat's visual cortex . The Journal of Physiology . 160 . 1 . 106–154.2 . 10.1113/jphysiol.1962.sp006837 . 0022-3751 . 1359523 . 14449617.
  22. Westheimer . G . December 1965 . Spatial interaction in the human retina during scotopic vision. . The Journal of Physiology . 181 . 4 . 881–894 . 10.1113/jphysiol.1965.sp007803 . 0022-3751 . 1357689 . 5881260.
  23. Julesz . Bela . Chang . Jih Jie . March 1976 . Interaction between pools of binocular disparity detectors tuned to different disparities . Biological Cybernetics . 22 . 2 . 107–119 . 10.1007/BF00320135 . 1276243 . 0340-1200. subscription .
  24. Schumer . Robert . Ganz . Leo . 1979-01-01 . Independent stereoscopic channels for different extents of spatial pooling . Vision Research . 19 . 12 . 1303–1314 . 10.1016/0042-6989(79)90202-5 . 532098 . 0042-6989. subscription .
  25. Yamaguchi . Kouichi . Sakamoto . Kenji . Akabane . Toshio . Fujimoto . Yoshiji . November 1990 . A Neural Network for Speaker-Independent Isolated Word Recognition . First International Conference on Spoken Language Processing (ICSLP 90) . Kobe, Japan . https://web.archive.org/web/20210307233750/https://www.isca-speech.org/archive/icslp_1990/i90_1077.html . 2021-03-07 . 2019-09-04 . dead.
  26. Book: Weng . J. . Ahuja . N. . Huang . T.S. . Cresceptron: A self-organizing neural network which grows adaptively . 1992 . [Proceedings 1992] IJCNN International Joint Conference on Neural Networks . IEEE . 1 . 576–581 . 10.1109/IJCNN.1992.287150 . 978-0-7803-0559-5.