A standard convolutional layer is oddly egalitarian. It stacks dozens — sometimes hundreds — of feature detectors, then treats every single one with the same respect. A channel that has learned to spot diagonal edges gets the same vote as one that detects blue sky pixels. A channel firing on fur texture in a cat photo is broadcast forward with the same weight as one activated by background noise. That uniformity is the weakness. Not every channel matters equally for every image, and deep networks have historically lacked a mechanism to say so.
Squeeze-and-Excitation, introduced by Hu and colleagues, fixes this with a remarkably small addition. It attaches a learnable gating mechanism to any convolution block so the network can dynamically recalibrate how much each channel contributes, and it does this fresh for every input. The extra cost is trivial — roughly 2.5 percent more parameters when bolted onto ResNet-50 — but the gain in representational power is substantial enough that SE blocks helped win ILSVRC 2017 and now sit inside production architectures like MobileNetV3 and EfficientNet.
The idea is simple enough to build from scratch in three stages.
Squeeze: Giving the Network a Wide-Angle Lens
Convolution is local by design. A 3×3 kernel slides across the image and only ever sees its immediate neighborhood. Stack enough layers and the receptive field grows, yet no single operation looks at an entire feature map in one glance. That means a channel might be strongly activated across the whole spatial extent of a dog or a car, but the next layer never receives an explicit summary saying, “This detector fired everywhere.”
The squeeze step closes that gap with global average pooling. For each channel, every value in the H×W spatial grid is averaged down to a single number. If you have 512 channels, you now have 512 scalars. Each scalar encodes the global presence of whatever that channel has learned to detect — be it a wheel rim, a strip of grass, or a patch of skin tone. It is a channel-wise summary of the whole scene.
This matters because context changes meaning. A horizontal-line detector is useful in one image because it identifies a horizon, and useless in another because it is picking up noise in a forest canopy. Without spatial aggregation, the network lacks a clean signal to make that distinction.
Excite: A Bottleneck That Forces Cooperation
Once the squeeze step has produced a vector of global channel descriptors, the excite step learns what to do with them. This is a tiny two-layer MLP. It takes the vector, compresses it down to a bottleneck, and then expands it back to the original channel dimension.
Typical implementations use a reduction ratio of 16. If the input has 512 channels, the first linear layer projects the 512 scalars down to 32, a ReLU sits in between, and the second layer maps the 32 back up to 512. That compression is intentional. It works like a funnel: the network cannot simply pass the original values through unchanged. It must learn a compressed, shared representation of how channels relate to one another. The bottleneck forces cross-channel dependencies to emerge. The model might learn, for instance, that when a “bark texture” channel is strong, a “tree trunk” contour channel should also be emphasized, while a “water reflection” channel should be muted.
The final activation here is crucial, and it is a common place where intuition slips. Many people instinctively reach for softmax, because it feels like attention should be a probability distribution. Softmax would force all channels to compete against each other until their weights sum to one. If one channel goes up, others must come down. That is exactly wrong for this task. A photograph of a sunset may need both an orange-glow channel and a cloud-texture channel operating at full strength simultaneously. The gates should act like independent dimmer switches, not a zero-sum budget.
Sigmoid solves this. It squashes each scalar to a value between zero and one, but every channel is free to move independently. The model can turn any subset up, leave others neutral, and suppress the rest, all without artificial competition.
Scale: Apply the Gates and Move On
ขั้นตอนสุดท้ายนั้นเกือบจะดูเรียบง่ายจนน่าประหลาดใจ ซึ่งนั่นคือส่วนหนึ่งของความสง่างามของมัน feature map ต้นฉบับแต่ละอันจะถูกคูณด้วยค่า gate ที่ผ่านการกระตุ้นด้วย sigmoid ที่สอดคล้องกัน หากค่า gate เข้าใกล้หนึ่ง ช่องสัญญาณ (channel) นั้นจะผ่านไปโดยไม่มีการเปลี่ยนแปลง หากค่า gate เข้าใกล้ศูนย์ feature map ทั้งหมดนั้นจะถูกลดเสียงลง (muted) จนค่อยๆ เลือนหายไป ผลลัพธ์ที่ได้จะถูกส่งต่อไปยังเลเยอร์ถัดไปของเครือข่าย
เนื่องจากนี่คือการคูณกันโดยตรงผ่าน spatial maps จึงทำให้เกิดภาระในการคำนวณ (compute overhead) เพิ่มขึ้นเพียงเล็กน้อยในขั้นตอน inference งานหนักส่วนใหญ่ถูกจัดการโดย global pooling และการทำ projection ขนาดเล็กสองตัว ซึ่งถือว่าน้อยมากเมื่อเทียบกับ 3×3 convolutions ที่อยู่รอบๆ
ทำไมการออกแบบนี้จึงยังคงอยู่
นอกเหนือจากคณิตศาสตร์ที่สะอาดตาแล้ว Squeeze-and-Excitation ยังคงยืนหยัดอยู่ได้เพราะมันเคารพต่อข้อจำกัดทางวิศวกรรม
พารามิเตอร์ราคาถูก (Cheap parameters). การเพิ่ม SE blocks เข้าไปใน ResNet-50 ใช้พารามิเตอร์เพิ่มขึ้นเพียงประมาณ 2.5 เปอร์เซ็นต์เท่านั้น เลเยอร์ MLP มีขนาดเล็กและไม่ทำให้โมเดลบวมขึ้น ในยุคที่ความแม่นยำที่เพิ่มขึ้นมักมาจากการเพิ่มขนาดโมเดลเป็นสองเท่า SE มอบสิ่งที่เรียกได้ว่าเป็น "ของฟรี" (free lunch) ที่หาได้ยาก
ความเป็นโมดูล (Modularity). SE ไม่ใช่สถาปัตยกรรม backbone ใหม่ที่บังคับให้คุณต้องออกแบบ pipeline ใหม่ทั้งหมด แต่มันคือโมดูลแบบ drop-in คุณสามารถแทรกมันไว้หลัง convolution block ใดก็ได้ใน ResNet, DenseNet หรือ stack ที่ปรับแต่งเอง โดยไม่ต้องเขียนตรรกะรอบข้างใหม่ ความยืดหยุ่นนี้ทำให้เกิดการนำไปใช้อย่างรวดเร็ว เริ่มจากการวิจัยและต่อมาในเครือข่ายที่ปรับแต่งมาเพื่ออุปกรณ์เคลื่อนที่ (mobile-optimized networks)
พฤติกรรมที่ปรับตามอินพุต (Input-adaptive behavior). ต่างจากน้ำหนักของ channel แบบคงที่ (static) ที่เรียนรู้ระหว่างการฝึกและถูกแช่แข็งไว้ (frozen) ค่า SE gates จะถูกคำนวณแบบ on the fly สำหรับทุกๆ forward pass หากป้อนภาพท้องฟ้าที่ราบเรียบและไม่มีลักษณะเด่นให้กับเครือข่าย ช่องสัญญาณที่เกี่ยวข้องก็จะยังคงอยู่ในระดับต่ำ แต่หากแสดงภาพถนนที่วุ่นวายซึ่งมีทั้งคนเดินเท้า ป้าย และยานพาหนะ ค่า gates จะปรับเทียบใหม่เพื่อเพิ่มความสำคัญให้กับตัวตรวจจับ (detectors) ที่สำคัญสำหรับภาพนั้นๆ เครือข่ายเดียวกันนี้สามารถปรับความไว (sensitivity) ของตัวเองได้ตามแต่ละฉากที่เห็น
จากผู้ชนะการแข่งขันสู่การใช้งานจริงในทุกวัน
SE blocks เคยคว้าตำแหน่งสูงสุดในการแข่งขัน ILSVRC 2017 แต่การพิสูจน์ความสามารถที่แท้จริงเกิดขึ้นหลังจากนั้น พวกมันถูกรวมเข้ากับ MobileNetV3 ซึ่งช่วยให้โมเดลขนาดเล็ก (lightweight models) มีประสิทธิภาพสูงเกินตัวโดยไม่สิ้นเปลืองแบตเตอรี่มือถือ นอกจากนี้ยังปรากฏอยู่ในสูตรการทำ compound scaling ของ EfficientNet ซึ่งพิสูจน์ให้เห็นว่า channel attention ไม่ใช่เรื่องฟุ่มเฟือยสำหรับเซิร์ฟเวอร์ขนาดใหญ่เท่านั้น แต่เป็นเครื่องมือที่ใช้งานได้จริงสำหรับการออกแบบที่มีประสิทธิภาพ
หากคุณต้องการเห็นว่าสิ่งนี้ใช้โค้ดเพียงเล็กน้อยแค่ไหน ตัวอย่างการสาธิตแบบสด (live demo) จะแยกย่อยการทำงานของ block ออกมาทีละบรรทัด:
- Live demo: https://dev48v.infy.uk/dl/day40-squeeze-excitation.html
- Full build walkthrough: https://dev.to/dev48v/squeeze-and-excitation-from-scratch-cheap-channel-attention-that-learns-which-feature-maps-matter-1hic
และหากคุณต้องการสร้างไปพร้อมกับชุมชน: https://t.me/GyaanSetuAi
บทสรุปที่แท้จริง
โมเดล vision ที่ดีขึ้นไม่จำเป็นต้องมี stack ที่ลึกขึ้นหรือ filter ที่กว้างขึ้นเสมอไป บางครั้งพวกมันแค่ต้องการช่วงเวลาสั้นๆ เพื่อถามว่า channel ไหนที่มีความสำคัญจริงๆ สำหรับภาพที่อยู่ตรงหน้า Squeeze-and-Excitation มอบช่วงเวลานั้นให้โดยใช้เพียงแค่ pooled average, MLP ที่ถูกบีบอัด และ sigmoid gate ผลลัพธ์ที่ได้คือเครือข่ายที่หยุดตะโกนบอกทุก feature ด้วยระดับเสียงที่เท่ากัน แต่เรียนรู้ที่จะกระซิบ เน้นย้ำ หรือทำให้แต่ละ channel เงียบลง ในเวลาที่ฉากนั้นๆ ต้องการพอดี
