技术指南

挤压和激励网络

挤压-激励(SE)模块是卷积神经网络的一个小型附加组件,它对整个图像中的每个特征通道进行汇总,然后为每个通道学习一个 0 到 1 之间的权重,并相应地重新缩放这些通道。

听听这个指南AI叙述 · ~8 min

在本页阅读时间 9 分钟
  1. 概述
  2. 主要要点
  3. 深入探讨
  4. 在极小的特征图上手动计算 SE 模块
  5. 现实世界的实施
  6. 挤压和激励网络的未来
  7. 付诸实践
  8. 资料来源与延伸阅读
  9. 不断探索
  10. 常见问题

概述

SE 网络由 Jie Hu 及其同事于 2017 年提出,赢得了 ILSVRC 2017 图像分类挑战赛,并成为高效视觉模型的标准组件。

主要要点

  1. SE 模块对图像中的每个通道取平均值,将结果通过一个带有 sigmoid 函数的小型瓶颈网络,然后重新缩放通道。
  2. SENets 在 ILSVRC 2017 分类挑战赛中获胜,在 ImageNet 测试集上的 top-5 错误率为 2.251%。
  3. SE-ResNet-50 仅比 ResNet-50 多 0.26% 的 FLOPs,就将 top-5 错误率从 7.48% 降低到了 6.62%。
  4. SE 模块为 ResNet-50 增加了约 10% 的参数,主要集中在通道数最多的最后阶段。
  5. EfficientNet 和 MobileNetV3 都将挤压-激励机制构建在其主要的移动卷积块中。
  6. 在论文的消融实验中,用 ReLU 替换 SE 中的 sigmoid 函数导致 SE-ResNet-50 的表现不如原始 ResNet-50。

深入探讨

A convolutional neural network (CNN) builds up an image representation in layers. Each layer produces a stack of feature maps, one per channel, where each channel responds to some learned pattern such as an edge, a texture or, deeper in the network, part of an object. A standard convolution mixes information across channels only within a small neighborhood of pixels. A squeeze-and-excitation block adds a cheap step that looks at every channel across the whole image and decides how much each channel should matter for this particular input. It then multiplies each channel by that weight. The authors call this feature recalibration, and it is a form of attention applied to channels rather than to positions or tokens.

The block has three steps. Squeeze: global average pooling collapses each channel's height by width map into a single number, the channel's average activation, producing a vector with one value per channel. Excitation: that vector passes through a small two-layer network. The first fully connected layer shrinks it by a reduction ratio r, 16 by default, followed by a ReLU; the second expands it back to the original number of channels, followed by a sigmoid that maps each value to between 0 and 1. Scale: each channel of the original feature map is multiplied by its weight. The sigmoid was chosen deliberately so that several channels can be emphasized at once, rather than forcing a single winner as a softmax would.

The block is meant to be dropped into existing architectures. In a residual network such as ResNet, it is applied to the output of the residual branch just before that branch is added back to the identity shortcut. The same pattern works for ResNeXt and Inception-style modules. Because the block only needs a feature map as input, it can be placed after almost any convolutional stage, which is a large part of why it spread so quickly.

The work came from Jie Hu, Li Shen and Gang Sun, with Samuel Albanie and Enhua Wu on the extended paper, affiliated with Momenta and the University of Oxford according to the official repository, which implements the networks in the Caffe framework. The paper was first posted to arXiv in September 2017 and published at CVPR 2018. SENets formed the basis of the team's winning entry in the ILSVRC 2017 classification competition: a small ensemble reached a 2.251% top-5 error on the test set, roughly a 25% relative improvement over the 2016 winner's 2.991%. A single SENet-154 model, built on a modified ResNeXt, reached 18.68% top-1 and 4.47% top-5 error with a 224 by 224 center crop.

The gains were consistent across networks. SE-ResNet-50 reached a 6.62% top-5 validation error, against 7.48% for ResNet-50 and 6.52% for ResNet-101, which needs 7.58 GFLOPs. SE-ResNet-101 at 6.07% beat ResNet-152 at 6.34%. SE-ResNeXt-50 at 5.49% beat ResNeXt-101 at 5.57%, and an SE version of Inception-ResNet-v2 improved from 5.21% to 4.79%. Outside classification, SE-ResNet-50 improved COCO object detection average precision by 2.4 points and SE-ResNet-152 lowered Places365 scene-classification top-5 error from 11.61% to 11.01%. The authors also observed that early SE blocks behave in a class-agnostic way, strengthening shared low-level features, while later blocks become increasingly class-specific.

The idea spread into efficient mobile models and inspired many variants. According to the MobileNetV3 paper, MnasNet added lightweight SE-based attention to the MobileNetV2 bottleneck, and MobileNetV3 kept it with a fixed bottleneck size and a hard sigmoid. EfficientNet-B0, published in 2019, uses the same SE-augmented mobile block. CBAM (Convolutional Block Attention Module, 2018) extended the idea by computing channel attention followed by spatial attention, a map over image positions. ECA-Net (2019) argued that the dimensionality reduction in SE's excitation step hurts, and replaced the two fully connected layers with a single 1D convolution across neighboring channels, adding only 80 parameters to ResNet-50 against SE's roughly 2.5 million, while reporting a 2.28-point top-1 gain over the plain ResNet-50.

Compared with alternatives, SE's appeal is its cost-to-benefit ratio. Making a network deeper, such as going from ResNet-50 to ResNet-101, roughly doubles compute; adding SE blocks to ResNet-50 adds 0.26% more FLOPs for a similar accuracy gain. Spatial attention methods such as CBAM's second stage, or the trunk-and-mask attention of earlier residual attention networks, can capture where to look but cost more. Self-attention as used in vision transformers models relationships between all positions, which SE does not attempt; SE only models relationships between channels, using one global summary per channel.

The limitations are worth knowing. The parameter cost is not negligible: SE adds about 2.5 million parameters to ResNet-50's 25 million, a 10% increase, most of it in the last stage, which the authors show can be removed with less than 0.1% top-5 error cost, cutting the increase to 4%. Global average pooling throws away all spatial information, so SE cannot tell where in the image a feature fired. The excitation design is sensitive: replacing the sigmoid with ReLU made SE-ResNet-50 worse than the baseline ResNet-50. FLOPs understate real cost on some hardware, because the pooling and channel-wise multiplication add memory traffic; the official repository notes that the authors re-implemented global average pooling on GPU because the stock version was inefficient, and MobileNetV3 replaced the sigmoid partly for efficiency on phones.

04工作示例

在极小的特征图上手动计算 SE 模块

  1. 取一个具有 4 个通道、每个通道 2×2 像素的特征图,其中通道均值为 z = [2.0, 0.5, 1.0, 0.0]。

  2. 选择降维比 r = 2,则第一全连接层将 4 个数映射为 2 个,第二层再将 2 个映射回 4 个。

  3. 应用第一层并使用 ReLU;示例权重下隐藏向量可能为 [1.5, 0.0],因为所有负值都会被截断为零。

  4. 应用第二层并使用 sigmoid;示例的前激活值 [2.0, -1.0, 0.5, -2.0] 会转化为约 [0.88, 0.27, 0.62, 0.12] 的权重。

  5. 将通道 1 的每个像素乘以 0.88,通道 2 乘以 0.27,通道 3 乘以 0.62,通道 4 乘以 0.12。

  6. 计算新增参数:4×2 加上 2×4 等于 16 个权重,符合公式 2C² / r。

它显示了什么

重新校准后的特征图中,通道 1 基本保持不变,通道 4 在该输入下被强烈抑制。可通过在 PyTorch 中使用 nn.AdaptiveAvgPool2d、两个 nn.Linear 层、ReLU 和 sigmoid,实现相同块,加载相同权重并确认输出一致来验证。

现实世界的实施

SENet 集成在 ILSVRC 2017 分类任务中取得了 2.251% 的 top-5 错误率,约比 2016 年冠军的 2.991% 低 25%。

在 ResNet-50 上加入 SE 块后,ImageNet top-5 验证错误率从 7.48% 降至 6.62%,而计算量从 3.86 GFLOPs 上升至 3.87 GFLOPs,接近更深的 ResNet-101。

Google 的 EfficientNet 系列使用移动倒置瓶颈块,并在其基线 EfficientNet-B0 网络中加入 squeeze-and-excitation 作为主要构建块。

MobileNetV3 在深度可分离卷积后放置 SE 模块,将其瓶颈固定为扩展通道的四分之一,并将 sigmoid 替换为更省电的硬 sigmoid,以适配手机。

在 Faster R-CNN 检测器中使用 SE-ResNet-50 代替 ResNet-50 作为骨干网络,使 COCO 平均精度提升了 2.4 点,约 6.3% 的相对提升,这在 SE 论文的实验中得到验证。

挤压和激励网络的未来

Channel attention has become a routine design option rather than an active frontier, and most research since 2018 has refined the SE recipe. CBAM (2018) added a spatial attention stage, ECA-Net (2019) removed the dimensionality reduction to cut parameters to a handful, and mobile architectures such as MobileNetV3 and EfficientNet (both 2019) tuned the block's placement, width and activation for real hardware latency. Open questions remain practical. The SE authors suggested that a single reduction ratio throughout a network may not be optimal, and that more sophisticated squeeze operators than average pooling could help. Measured speed on specific devices often differs from FLOP counts, so architecture searches increasingly optimize latency directly, as the MobileNetV3 paper did. As vision transformers and hybrid convolution-attention models spread, the role of a separate channel-attention block in those designs is still being evaluated, and published ablations on standard benchmarks such as ImageNet and COCO remain the reliable way to judge whether SE-style blocks still pay for their cost in a given architecture.

付诸实践

为什么这很重要

  • 成本与预算. 多年来,架构决策决定着性能和运营成本。
  • 更清晰的判决. 技术教育帮助团队选择正确的堆栈,而不仅仅是最新的堆栈。
  • 质量控制. 更好的工程选择可以减少生产中的可靠性事故。

留意

  • 优化一项基准测试可以隐藏更广泛的系统弱点。
  • 基础设施和维护成本常常被低估。
  • 随着系统变得更加复杂,安全性和可观察性差距可能会扩大。

后续步骤

  1. 在实施之前定义延迟、质量和成本目标。
  2. 在实际负载和数据条件下进行基准测试。
  3. 仪器监控错误、漂移和用户影响。
  4. 在扩展之前准备回滚和事件响应路径。

资料来源与延伸阅读

  1. arXiv (CVPR 2018)挤压和激励网络
  2. GitHub (hujie-frank)SENet:Squeeze-and-Excitation Networks(官方 Caffe 实现)
  3. arXiv (Google)搜索 MobileNetV3
  4. arXiv (Google)EfficientNet:重新思考卷积神经网络的模型缩放
  5. arXiv (KAIST, Lunit, Adobe Research)CBAM:卷积块注意力模块
  6. arXivECA-Net:高效通道注意力用于深度卷积神经网络

不断探索

免费通讯

获取每日AI简报

每个工作日早晨提供三条经过验证的AI故事,使用简明英文撰写。永久免费,无广告。

每个工作日发送一封邮件。一键退订。我们永不出售或分享您的地址。

测试一下自己

参加 Squeeze-and-Excitation Networks 测验

每个答案即时反馈,课程通过后可获得可验证ID的可分享证书。

开始测验

支持免费AI教育。AI Understanding是一家501(c)(3)非营利组织——无广告,无付费墙,永不收费。 捐款

常见问题

什么是挤压和激励网络?

Squeeze-and-Excitation(SE)块是卷积神经网络的一个小型附加模块,它对整个图像的每个特征通道进行汇总,然后学习一个介于 0 到 1 之间的权重并相应地重新缩放通道。该模块由胡杰等人在 2017 年提出,SE 网络在 ILSVRC 2017 图像分类挑战中获胜,并成为高效视觉模型的标准组件。

SE 块中的“挤压”步骤有什么作用?

挤压应用全局平均池化,将每个特征图折叠成每个通道的单个描述符。

“激励”步骤输出什么?

激励将压缩矢量传递通过两个以 s 形曲线结尾的 FC 层,产生每个通道的缩放权重。

激励权重如何应用于原始特征图?

每个通道的特征图乘以其学习的权重,放大或抑制该通道。

为什么激励使用具有减速比(通常为16)的瓶颈?

瓶颈缩小然后恢复通道尺寸,因此 SE 块的成本仅增加几个百分点。

SENet 在 2017 年赢得了哪些比赛?

SENet 赢得了 ILSVRC 2017 图像分类挑战赛,将 top-5 错误率推至约 2.25%。