{"notes":[{"id":"lightweight/cbam","category":"lightweight","legacyPath":"","legacySlug":"","legacyPaths":[],"title":"CBAM","subtitle":"Where Are You Looking?","author":"Z. Yuan","paperDate":"2018-07-17","publishedOn":"2024-07-31","world":"external/cbam","paperTitle":"CBAM: Convolutional Block Attention Module","paperUrl":"https://arxiv.org/abs/1807.06521","bibliography":{"title":"CBAM: Convolutional Block Attention Module","authors":["Sanghyun Woo","Jongchan Park","Joon-Young Lee","In So Kweon"],"url":"https://arxiv.org/abs/1807.06521","pdfUrl":"https://arxiv.org/pdf/1807.06521v2","codeUrl":null,"preprint":{"id":"1807.06521","submittedOn":"2018-07-17","url":"https://arxiv.org/abs/1807.06521"},"publication":{"venue":"ECCV","year":2018,"kind":"conference","url":"https://openaccess.thecvf.com/content_ECCV_2018/html/Sanghyun_Woo_Convolutional_Block_Attention_ECCV_2018_paper.html"},"citation":"@misc{lightweightcbam2018,\n  title = {{CBAM: Convolutional Block Attention Module}},\n  author = {Sanghyun Woo and Jongchan Park and Joon-Young Lee and In So Kweon},\n  year = {2018},\n  eprint = {1807.06521},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1807.06521}\n}\n","citationPath":"/content/papers/citations/lightweight/cbam.bf1587b50fdf.bib"},"thumbnail":{"src":"/content/papers/assets/c62baa4fde1b39b59d98582de01b1a1303f006289a91791c235dfc69e88ec40b.png","width":1395,"height":713},"locale":"en","path":"/content/papers/en/lightweight/cbam.c88eb06a1c99.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"overall-structure","text":"Overall Structure","depth":3},{"id":"channel-attention","text":"Channel Attention","depth":3},{"id":"spatial-attention","text":"Spatial Attention","depth":3},{"id":"putting-it-together","text":"Putting It Together","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"how-the-design-took-shape","text":"How the Design Took Shape","depth":3},{"id":"results-across-networks","text":"Results Across Networks","depth":3},{"id":"detection","text":"Detection","depth":3},{"id":"where-the-model-looks","text":"Where the Model Looks","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"lightweight/senet","relation":"referenced","topic":""},{"id":"classic-cnns/wide-resnet","relation":"referenced","topic":""},{"id":"classic-cnns/xception","relation":"referenced","topic":""}]},{"id":"lightweight/senet","category":"lightweight","legacyPath":"lightweight/1709-senet","legacySlug":"1709-senet","legacyPaths":[],"title":"SENet","subtitle":"Squeeze and Excitation Network","author":"Z. Yuan","paperDate":"2017-09-05","publishedOn":"2024-06-28","paperTitle":"Squeeze-and-Excitation Networks","paperUrl":"https://arxiv.org/abs/1709.01507","bibliography":{"title":"Squeeze-and-Excitation Networks","authors":["Jie Hu","Li Shen","Samuel Albanie","Gang Sun","Enhua Wu"],"url":"https://arxiv.org/abs/1709.01507","pdfUrl":"https://arxiv.org/pdf/1709.01507","codeUrl":null,"preprint":{"id":"1709.01507","submittedOn":"2017-09-05","url":"https://arxiv.org/abs/1709.01507"},"publication":{"venue":"CVPR","year":2018,"kind":"conference","url":"https://arxiv.org/abs/1709.01507"},"citation":"@misc{lightweightsenet2017,\n  title = {{Squeeze-and-Excitation Networks}},\n  author = {Jie Hu and Li Shen and Samuel Albanie and Gang Sun and Enhua Wu},\n  year = {2017},\n  eprint = {1709.01507},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1709.01507}\n}\n","citationPath":"/content/papers/citations/lightweight/senet.1766a7978dde.bib"},"thumbnail":{"src":"/content/papers/assets/322f16ed8c782ffbdd7d7db3e8292c991908e3543dc69e1addd9238e22484363.jpg","width":1688,"height":394},"locale":"en","path":"/content/papers/en/lightweight/senet.20270339ffe6.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"image-classification-results","text":"Image Classification Results","depth":3},{"id":"results-on-lightweight-models","text":"Results on Lightweight Models","depth":3},{"id":"importance-of-squeeze","text":"Importance of Squeeze","depth":3},{"id":"importance-of-excitation","text":"Importance of Excitation","depth":3},{"id":"other-experimental-results","text":"Other Experimental Results","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"lightweight/mobilenet-v3","relation":"comparison","topic":"Channel attention in lightweight networks"},{"id":"lightweight/pp-lcnet","relation":"comparison","topic":"Channel attention in lightweight networks"}]},{"id":"classic-cnns/wide-resnet","category":"classic-cnns","legacyPath":"","legacySlug":"","legacyPaths":[],"title":"Wide ResNet","subtitle":"Wider, Not Deeper","author":"Z. Yuan","paperDate":"2016-05-23","publishedOn":"2024-02-14","world":"external/wide-resnet","paperTitle":"Wide Residual Networks","paperUrl":"https://arxiv.org/abs/1605.07146","bibliography":{"title":"Wide Residual Networks","authors":["Sergey Zagoruyko","Nikos Komodakis"],"url":"https://arxiv.org/abs/1605.07146","pdfUrl":"https://arxiv.org/pdf/1605.07146v4","codeUrl":null,"preprint":{"id":"1605.07146","submittedOn":"2016-05-23","url":"https://arxiv.org/abs/1605.07146"},"publication":{"venue":"BMVC","year":2016,"kind":"conference","url":"https://doi.org/10.5244/C.30.87"},"citation":"@misc{classiccnnswideresnet2016,\n  title = {{Wide Residual Networks}},\n  author = {Sergey Zagoruyko and Nikos Komodakis},\n  year = {2016},\n  eprint = {1605.07146},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1605.07146}\n}\n","citationPath":"/content/papers/citations/classic-cnns/wide-resnet.2e42de74f658.bib"},"thumbnail":{"src":"/content/papers/assets/eb123078c88654918b04d17b5ebccd1009fc7fbc33305ebd9ba853f2ad2cc024.png","width":1400,"height":500},"locale":"en","path":"/content/papers/en/classic-cnns/wide-resnet.5ef1b2569375.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"resnets-keep-getting-thinner","text":"ResNets Keep Getting Thinner","depth":3},{"id":"the-shortcut-is-too-easy","text":"The Shortcut Is Too Easy","depth":3},{"id":"thin-networks-arent-fast-either","text":"Thin Networks Aren't Fast Either","depth":3},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"what-can-be-changed","text":"What Can Be Changed","depth":3},{"id":"wrn-n-k","text":"WRN-n-k","depth":3},{"id":"what-goes-inside-a-block","text":"What Goes Inside a Block","depth":3},{"id":"putting-dropout-inside-the-block","text":"Putting Dropout Inside the Block","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"splitting-between-width-and-depth","text":"Splitting Between Width and Depth","depth":3},{"id":"taking-on-the-thousand-layer-resnet","text":"Taking On the Thousand-Layer ResNet","depth":3},{"id":"wide-networks-run-faster","text":"Wide Networks Run Faster","depth":3},{"id":"the-effect-of-dropout","text":"The Effect of Dropout","depth":3},{"id":"on-imagenet-widen-the-middle-layer","text":"On ImageNet, Widen the Middle Layer","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"classic-cnns/resnet-v2","relation":"referenced","topic":""},{"id":"classic-cnns/stochastic-depth","relation":"referenced","topic":""}]},{"id":"classic-cnns/xception","category":"classic-cnns","legacyPath":"","legacySlug":"","legacyPaths":[],"title":"Xception","subtitle":"Where Inception Ends","author":"Z. Yuan","paperDate":"2016-10-07","publishedOn":"2024-03-20","world":"external/xception","paperTitle":"Xception: Deep Learning with Depthwise Separable Convolutions","paperUrl":"https://arxiv.org/abs/1610.02357","bibliography":{"title":"Xception: Deep Learning with Depthwise Separable Convolutions","authors":["François Chollet"],"url":"https://arxiv.org/abs/1610.02357","pdfUrl":"https://arxiv.org/pdf/1610.02357v3","codeUrl":null,"preprint":{"id":"1610.02357","submittedOn":"2016-10-07","url":"https://arxiv.org/abs/1610.02357"},"publication":{"venue":"CVPR","year":2017,"kind":"conference","url":"https://openaccess.thecvf.com/content_cvpr_2017/html/Chollet_Xception_Deep_Learning_CVPR_2017_paper.html"},"citation":"@misc{classiccnnsxception2016,\n  title = {{Xception: Deep Learning with Depthwise Separable Convolutions}},\n  author = {François Chollet},\n  year = {2016},\n  eprint = {1610.02357},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1610.02357}\n}\n","citationPath":"/content/papers/citations/classic-cnns/xception.3a6fa7188c36.bib"},"thumbnail":{"src":"/content/papers/assets/b56e8b540dd5a4cb9856460b3e47a6e3e624df308ab08b70809438075caf5f0a.png","width":917,"height":538},"locale":"en","path":"/content/papers/en/classic-cnns/xception.b83ea41802e4.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"inception-from-another-angle","text":"Inception from Another Angle","depth":3},{"id":"splitting-all-the-way","text":"Splitting All the Way","depth":3},{"id":"the-other-end-of-the-spectrum","text":"The Other End of the Spectrum","depth":3},{"id":"xception","text":"Xception","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"imagenet","text":"ImageNet","depth":3},{"id":"jft","text":"JFT","depth":3},{"id":"similar-parameters-a-bit-slower","text":"Similar Parameters, a Bit Slower","depth":3},{"id":"residual-connections","text":"Residual Connections","depth":3},{"id":"an-activation-in-between","text":"An Activation in Between?","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"classic-cnns/inception-v1","relation":"referenced","topic":""},{"id":"classic-cnns/inception-v3","relation":"referenced","topic":""},{"id":"lightweight/mobilenet-v1","relation":"referenced","topic":""}]}],"text":"In 2017, SENet won the classification task at the last ILSVRC. It adds a tiny module after each convolutional block, which first averages each channel down to a single number, then uses two fully connected layers to compute a weight for each channel and multiplies those weights back onto the original feature map. A few more parameters brought a sizable gain in accuracy.\n\n\n> [!TIP]\n> \n> For SENet, you can start with our note:\n> \n> - **[[17.09] SENet: Squeeze and Excitation Network](/blog/papers/lightweight/senet)**\n\n\nSanghyun Woo and colleagues from KAIST and Lunit in Korea and Adobe Research in the US took SENet as their starting point and pressed further. Is the average alone enough to set the channel weights? Besides “which channels to look at,” shouldn't the network also decide “which positions to look at”?\n\n## Defining the Problem\n\nThe authors start from the directions network design had taken. A network can go deeper, like VGG and ResNet; wider, like Wide ResNet; or increase its cardinality, like Xception and ResNeXt. We've written notes on all three directions; see [Wide ResNet](/blog/papers/classic-cnns/wide-resnet), [Xception](/blog/papers/classic-cnns/xception), and [ResNeXt](/blog/papers/classic-cnns/resnext).\n\nThe authors wanted to work from a different direction, attention, letting the network emphasize important features and suppress unnecessary ones.\n\nConvolution already blends channel and spatial information together, so the authors have attention follow those same two directions. Channel attention decides “what” to look at, since each channel can be seen as a feature detector; spatial attention decides “where” to look.\n\nSENet does only the channel half, and it gathers information with average pooling alone. The authors see room for improvement on both counts, and they also want the module to stay lightweight enough to plug straight into any convolutional network.\n\n## Solving the Problem\n\n### Overall Structure\n\n[![The overall structure of CBAM: the Input Feature first goes into the Channel Attention Module, and the resulting channel attention is multiplied with the input; the result then goes into the Spatial Attention Module, and the resulting spatial attention is multiplied in once more, giving the Refined Feature](/content/papers/assets/6bb23fb7d2af72e07e37ef41762e65dd79a4f36a6b6309ea002c27127650f5bd.png)](/content/papers/assets/6bb23fb7d2af72e07e37ef41762e65dd79a4f36a6b6309ea002c27127650f5bd.png)\n\n*Fig. 1 from the paper, excerpted from [**page 2 of the v2 PDF**](https://arxiv.org/pdf/1807.06521v2#page=2). CBAM consists of a channel submodule and a spatial submodule in sequence.*\n\nGiven an intermediate feature map $\\mathbf{F}\\in\\mathbb{R}^{C\\times H\\times W}$, CBAM first computes a 1D channel attention map $\\mathbf{M_c}\\in\\mathbb{R}^{C\\times1\\times1}$, then a 2D spatial attention map $\\mathbf{M_s}\\in\\mathbb{R}^{1\\times H\\times W}$:\n\n$$\n\\mathbf{F}'=\\mathbf{M_c}(\\mathbf{F})\\otimes\\mathbf{F},\\qquad\n\\mathbf{F}''=\\mathbf{M_s}(\\mathbf{F}')\\otimes\\mathbf{F}'.\n$$\n\n$\\otimes$ is element-wise multiplication, with broadcasting filling in wherever the shapes differ. Channel attention has one number per channel, copied across the whole plane when multiplied; spatial attention has one number per position, copied across all channels.\n\n[![Details of the two submodules. The green box at the top is the Channel Attention Module: Input feature F goes through MaxPool and AvgPool to give two vectors, each fed into the same Shared MLP; the two outputs are added and passed through a sigmoid to give Channel Attention Mc. The purple box at the bottom is the Spatial Attention Module: Channel-refined feature F' is max-pooled and average-pooled along the channel axis, stacked into two maps, and passed through a conv layer and a sigmoid to give Spatial Attention Ms](/content/papers/assets/c62baa4fde1b39b59d98582de01b1a1303f006289a91791c235dfc69e88ec40b.png)](/content/papers/assets/c62baa4fde1b39b59d98582de01b1a1303f006289a91791c235dfc69e88ec40b.png)\n\n*Fig. 2 from the paper, excerpted from [**page 5 of the v2 PDF**](https://arxiv.org/pdf/1807.06521v2#page=5). The channel attention and spatial attention submodules.*\n\nThe two submodules work symmetrically. Each first applies average pooling and max pooling along one direction to compress the information, then uses a small network to compute the attention. Let's take them one at a time.\n\n### Channel Attention\n\nChannel attention has to compress each channel's $H\\times W$ values into a single number. SENet uses average pooling; the authors argue that max pooling should be added as well.\n\nWhy? Let's look at an extreme example. Suppose there are two channels, one that's 0.1 everywhere on a $10\\times10$ map, and another that's 10 at a single position and 0 everywhere else:\n\n```python\nimport torch\n\nflat = torch.full((10, 10), 0.1)                   # channel A: 0.1 everywhere\npeak = torch.zeros(10, 10); peak[3, 6] = 10.0       # channel B: bright at just one position\nF = torch.stack([flat, peak])                      # [C=2, H=10, W=10]\n\nprint(\"Average pooling:\", [round(v, 4) for v in F.mean(dim=(1, 2)).tolist()])\nprint(\"Max pooling:\", [round(v, 4) for v in F.amax(dim=(1, 2)).tolist()])\n```\n\n```text\nAverage pooling: [0.1, 0.1]\nMax pooling: [0.1, 10.0]\n```\n\nGoing by the average alone, the two channels are identical; the maximum shows that the second channel responds strongly somewhere. As the authors put it, average pooling gives a soft global statistic, while max pooling records how strong the most salient part is, so the two complement each other.\n\nThe two pooled results go into **the same** MLP, and the outputs are added and passed through a sigmoid:\n\n$$\n\\mathbf{M_c}(\\mathbf{F})=\\sigma\\big(\\mathrm{MLP}(\\mathrm{AvgPool}(\\mathbf{F}))+\\mathrm{MLP}(\\mathrm{MaxPool}(\\mathbf{F}))\\big).\n$$\n\nThe MLP has a single hidden layer of size $C/r$, where $r$ is the reduction ratio, set to 16 as in SENet. Because the MLP is shared, the parameter count is the same as SENet's.\n\n### Spatial Attention\n\nSpatial attention goes the other way, applying average pooling and max pooling along the **channel** axis. Each position's $C$ values are compressed into two numbers, turning the whole map into two $H\\times W$ descriptor maps. These are stacked and passed through a $7\\times7$ convolution and then a sigmoid:\n\n$$\n\\mathbf{M_s}(\\mathbf{F})=\\sigma\\big(f^{7\\times7}([\\mathrm{AvgPool}(\\mathbf{F});\\mathrm{MaxPool}(\\mathbf{F})])\\big).\n$$\n\n### Putting It Together\n\nLet's write out the two submodules and run a 256-channel, $14\\times14$ feature map through them:\n\n```python\nimport torch\nimport torch.nn as nn\n\nclass ChannelAttention(nn.Module):\n    def __init__(self, C, r=16):\n        super().__init__()\n        self.mlp = nn.Sequential(nn.Linear(C, C // r), nn.ReLU(), nn.Linear(C // r, C))   # shared MLP\n\n    def forward(self, F):\n        avg = F.mean(dim=(2, 3))                  # [B, C]\n        mx = F.amax(dim=(2, 3))                   # [B, C]\n        Mc = torch.sigmoid(self.mlp(avg) + self.mlp(mx))\n        print(\"  Channel attention Mc:\", tuple(Mc[:, :, None, None].shape))\n        return Mc[:, :, None, None]               # [B, C, 1, 1]\n\nclass SpatialAttention(nn.Module):\n    def __init__(self, k=7):\n        super().__init__()\n        self.conv = nn.Conv2d(2, 1, k, padding=k // 2)\n\n    def forward(self, F):\n        avg = F.mean(dim=1, keepdim=True)         # [B, 1, H, W]\n        mx = F.amax(dim=1, keepdim=True)          # [B, 1, H, W]\n        desc = torch.cat([avg, mx], dim=1)        # [B, 2, H, W]\n        Ms = torch.sigmoid(self.conv(desc))\n        print(\"  Spatial descriptor:\", tuple(desc.shape), \"→ spatial attention Ms:\", tuple(Ms.shape))\n        return Ms\n\nclass CBAM(nn.Module):\n    def __init__(self, C, r=16):\n        super().__init__()\n        self.channel, self.spatial = ChannelAttention(C, r), SpatialAttention()\n\n    def forward(self, F):\n        F1 = self.channel(F) * F                  # Eq. (1): multiply by channel attention first\n        F2 = self.spatial(F1) * F1                # then by spatial attention\n        return F2\n\nF = torch.randn(2, 256, 14, 14)\ncbam = CBAM(256)\nout = cbam(F)\nprint(\"Output:\", tuple(out.shape))\nprint(f\"Channel part parameters {sum(p.numel() for p in cbam.channel.parameters()):,}, spatial part parameters {sum(p.numel() for p in cbam.spatial.parameters()):,}\")\n```\n\n```text\n  Channel attention Mc: (2, 256, 1, 1)\n  Spatial descriptor: (2, 2, 14, 14) → spatial attention Ms: (2, 1, 14, 14)\nOutput: (2, 256, 14, 14)\nChannel part parameters 8,464, spatial part parameters 99\n```\n\nThe output has the same shape as the input, so CBAM can be inserted anywhere. Nearly all the parameters are in the channel part's MLP ($256\\to16\\to256$); the spatial part is just one $2\\to1$ $7\\times7$ convolution, with 99 parameters.\n\nIn a ResNet, CBAM is applied to the convolution output of each residual block, and the result is then added to the shortcut, in the same position as SENet. timm also has a ready-made version; `timm.layers.create_attn(\"cbam\", channels)` returns a `CbamModule`.\n\n## Discussion\n\nUnless otherwise noted, the experiments are on ImageNet-1K, reporting single-crop error on the validation set. The authors retrained every network themselves in PyTorch, SENet included, so the SE numbers in the tables are their reproductions and differ somewhat from those reported in the SENet paper.\n\n### How the Design Took Shape\n\nHolding ResNet-50 fixed, the authors decide in turn how to compute channel attention, how to compute spatial attention, and how to combine the two.\n\n**Which pooling for channel attention.** This set uses channel attention only, with $r=16$:\n\n| Setting | Top-1 error | Top-5 error |\n| --- | ---: | ---: |\n| ResNet-50 | 24.56% | 7.50% |\n| + average pooling (i.e., SE) | 23.14% | 6.70% |\n| + max pooling | 23.20% | 6.83% |\n| + average and max pooling | **22.80%** | **6.52%** |\n\n*Table: Excerpted from Table 1 of the paper.*\n\nMax pooling alone works about as well as average pooling; using both is best, 0.34 percentage points lower than SE, with no added parameters.\n\n**How to compute spatial attention.** Placed after the channel attention from the previous step, this set compares two ways of producing the descriptor maps, the authors' pooling along the channel axis and a $1\\times1$ convolution that compresses the channels into one, as well as kernel sizes of 3 and 7:\n\n| Setting | Top-1 error | Top-5 error |\n| --- | ---: | ---: |\n| Channel attention only | 22.80% | 6.52% |\n| + spatial ($1\\times1$ conv, $k=3$) | 22.96% | 6.64% |\n| + spatial ($1\\times1$ conv, $k=7$) | 22.90% | 6.47% |\n| + spatial (average and max pooling, $k=3$) | 22.68% | 6.41% |\n| + spatial (average and max pooling, $k=7$) | **22.66%** | **6.31%** |\n\n*Table: Excerpted from Table 2 of the paper.*\n\nThe two versions that produce the descriptor with a $1\\times1$ convolution actually have worse top-1 error than channel attention alone; only pooling along the channel axis brings an improvement. The larger kernel is better, which the authors explain by saying that judging which regions matter needs a wider view.\n\n**How to arrange the two submodules.**\n\n| Arrangement | Top-1 error | Top-5 error |\n| --- | ---: | ---: |\n| Channel only (SE) | 23.14% | 6.70% |\n| Channel first, then spatial | **22.66%** | **6.31%** |\n| Spatial first, then channel | 22.78% | 6.42% |\n| In parallel, summed then passed through a sigmoid | 22.95% | 6.59% |\n\n*Table: Excerpted from Table 3 of the paper.*\n\nSequential beats parallel, and channel first is slightly better still; that's the final CBAM.\n\nReading the three tables together, going from SE's 23.14% to CBAM's 22.66% is a total gain of 0.48 percentage points. Of that, 0.34 comes from the max pooling added to channel attention, and spatial attention contributes another 0.14.\n\n### Results Across Networks\n\nNext, CBAM is plugged into a range of networks and compared with the originals and with the SE versions:\n\n| Network | Original | + SE | + CBAM | Parameters (original → with module) |\n| --- | ---: | ---: | ---: | ---: |\n| ResNet-18 | 29.60% | 29.41% | **29.27%** | 11.69M → 11.78M |\n| ResNet-34 | 26.69% | 26.13% | **25.99%** | 21.80M → 21.96M |\n| ResNet-50 | 24.56% | 23.14% | **22.66%** | 25.56M → 28.09M |\n| ResNet-101 | 23.38% | 22.35% | **21.51%** | 44.55M → 49.33M |\n| WideResNet-18 (1.5× wide) | 26.85% | 26.21% | **26.10%** | 25.88M → 26.08M |\n| WideResNet-18 (2× wide) | 25.63% | 24.93% | **24.84%** | 45.62M → 45.97M |\n| ResNeXt-50 (32×4d) | 22.85% | **21.91%** | 21.92% | 25.03M → 27.56M |\n| ResNeXt-101 (32×4d) | 21.54% | 21.17% | **21.07%** | 44.18M → 48.96M |\n\n*Table: Excerpted from Table 4 of the paper, ImageNet-1K top-1 error. SE and CBAM have almost identical parameter counts; CBAM's are listed here.*\n\nCBAM beats the original on every network and beats SE on most, with the largest margin on ResNet-101 (0.84 percentage points below SE). On ResNeXt-50, it ties with SE. The extra computation is tiny; ResNet-50 goes from 3.858 GFLOPs to 3.864.\n\nThe authors also tried the lightweight MobileNet. The original MobileNet has a top-1 error of 31.39%, 29.97% with SE, and 29.01% with CBAM; for the version with its width scaled to 0.7, the three are 34.86%, 32.50%, and 31.51%.\n\n### Detection\n\nOn COCO, using Faster R-CNN with CBAM added to the backbone, mAP@[.5:.95] goes from 27.0 to 28.1 for ResNet-50 and from 29.1 to 30.8 for ResNet-101.\n\nOn VOC 2007, the authors instead put CBAM inside the detector, adding one before every classifier of the SSD-based StairNet. With a VGG16 backbone, mAP@0.5 goes from 78.9 to 79.3 (79.1 with SE); with a MobileNet backbone, from 70.1 to 70.5 (70.0 with SE). The gains in detection range from about 0.4 to 1.7 percentage points.\n\n### Where the Model Looks\n\nThe authors use Grad-CAM to show the regions the network looks at when making its decision. Grad-CAM generalizes CAM, using gradients to compute how important each position is for a given class, and it doesn't require the network to end in global average pooling.\n\n\n> [!TIP]\n> \n> For CAM, see our note:\n> \n> - **[[15.12] CAM: Where Is the Model Looking?](/blog/papers/classic-cnns/cam)**\n\n\n[![Grad-CAM visualizations in six columns, for the classes Tailed frog, Toilet tissue, Loudspeaker, Spider web, American egret, and Tank. The first row is the input images, and the three rows below are heatmaps for ResNet50, ResNet50 + SE, and ResNet50 + CBAM, each labeled underneath with that network's softmax score P for the correct class. In the CBAM row, the red regions mostly cover the whole object and the scores are the highest; for Tank, for example, the score rises from 0.14763 and 0.15367 to 0.53005](/content/papers/assets/80d662363e321efb620082338d5820d7ffec1bee0ef0cb792b3b69e58a759f43.png)](/content/papers/assets/80d662363e321efb620082338d5820d7ffec1bee0ef0cb792b3b69e58a759f43.png)\n\n*Fig. 5 from the paper (first six columns of the top half), excerpted from [**page 12 of the v2 PDF**](https://arxiv.org/pdf/1807.06521v2#page=12). The P under each image is the network's softmax score for the correct class.*\n\nFrom top to bottom, each column shows the original image and then the heatmaps for ResNet-50, with SE, and with CBAM. In the American egret column, for example, the original ResNet-50's red region is concentrated around the head, while CBAM's extends along the whole body, and the score for the correct class rises from 0.64 to 0.87. The tank column is even more striking, with the score jumping from about 0.15 to 0.53.\n\nFrom this, the authors conjecture that CBAM's gains come from more accurate attention, with the interference from cluttered backgrounds suppressed. These are hand-picked examples; they show what the module is doing, but to quantify it, you still have to go back to the tables above.\n\n## Conclusion\n\nCBAM's channel attention looks at max pooling as well as average pooling, and a spatial attention step afterward decides which positions to look at. The two submodules sit in sequence on the residual branch, with almost the same parameter count as SE.\n\nBroken down, most of the extra 0.48 percentage points over SE on ResNet-50 come from max pooling; spatial attention, which handles the other half of the work, contributes only 0.14 and keeps a pretty low profile. If you only want to make a small change, switching SE's average pooling to “average plus max” gets you most of the benefit.\n\nAs for the Grad-CAM images, CBAM is the most on target in every column, and its scores are the highest, too. Of course the examples the authors picked for the paper look good. To judge whether the module actually helps, you still have to go back to those tables.\n","imageSizes":{"/content/papers/assets/6bb23fb7d2af72e07e37ef41762e65dd79a4f36a6b6309ea002c27127650f5bd.png":{"width":1446,"height":437},"/content/papers/assets/c62baa4fde1b39b59d98582de01b1a1303f006289a91791c235dfc69e88ec40b.png":{"width":1395,"height":713},"/content/papers/assets/80d662363e321efb620082338d5820d7ffec1bee0ef0cb792b3b69e58a759f43.png":{"width":960,"height":713}}}
