Paper commentary
Paying More Attention to Attention: Improving the Performance of Convolutional Neural Networks via Attention Transfer
- Problem Small CNN students usually learn from a teacher's outputs or full hidden features, but it was unclear whether the teacher's spatial attention is a better training signal.
- Method Attention transfer adds a loss that pulls the student's spatial attention maps toward the teacher's, alongside the usual cross-entropy loss.
- Results On CIFAR-10, activation-based attention transfer lowers a WRN-16-1 student's median test error from 8.77 to 7.93, with a WRN-16-2 teacher.
Why transfer attention rather than features
Knowledge distillation trains a small network to match a larger teacher's outputs, and FitNets extends this to intermediate layers by using the teacher's features as hints. Hints built from full activation tensors are the baseline this study compares against, because they transfer everything the teacher computes at a layer. The study asks a narrower question: whether a teacher's spatial attention, meaning where it concentrates its response, can improve a student more than matching the full features does.
The authors argue that deeper residual networks gain mostly from more parameters once they pass a certain depth, so a thin deep student is harder to parallelize than a wider one. Rather than making the student deeper as FitNets does, the approach trains less deep students.
Attention is defined here as a set of spatial maps over the input, computed at chosen layers so that low-, mid- and high-level information can be captured. Two kinds of maps are defined, activation-based and gradient-based, and both are passed to the student as a loss rather than as new weights.
Building activation-based attention maps
For a layer with activation tensor \(A\in\mathbb{R}^{C\times H\times W}\), an activation-based mapping \(F:\mathbb{R}^{C\times H\times W}\rightarrow\mathbb{R}^{H\times W}\) collapses the channel dimension and returns one two-dimensional map.
The method assumes that the absolute value of a hidden activation indicates how much that neuron matters for a given input. Statistics of these absolute values taken across the channels then give the spatial map.
The sum variant is \(F_{sum}(A)=\sum_{i=1}^{C}|A_i|\), where \(A_i=A(i,:,:)\). The power sum is \(F^p_{sum}(A)=\sum_{i=1}^{C}|A_i|^p\) and the power max is \(F^p_{max}(A)=\max_{i=1,\dots,C}|A_i|^p\), with \(p>1\) in both cases.
Raising to a power \(p>1\) shifts weight toward locations where the largest activations occur, and the larger \(p\) is, the stronger that shift. The max variant gives each spatial location a value from only its strongest channel, whereas the power sum lets several strong channels at one location add up.
In the first layers the map follows low-level image structure, in middle layers it highlights discriminative parts, and in the top layers it reflects whole objects. For a face recognition network, mid-level sum maps concentrate on eyes, nose and lips, while the top layer covers the whole face.
Adding an attention loss to training
With the same depth, a transfer loss can follow every residual block; with a deeper teacher, the loss sits on the output of each group of residual blocks. Student and teacher maps are assumed to share spatial resolution, and when they do not, the maps can be interpolated to match.
The total objective adds the cross-entropy loss of the student to a weighted sum of distances between paired attention maps, as in the following form. \[ L_{AT}=L(W_S,x)+\frac{\beta}{2}\sum_{j\in I}\left\|\frac{Q_S^j}{\|Q_S^j\|_2}-\frac{Q_T^j}{\|Q_T^j\|_2}\right\|_p \] Here \(I\) indexes the teacher-student layer pairs, \(Q_S^j\) and \(Q_T^j\) are the vectorized student and teacher maps for pair \(j\), and the experiments use \(p=2\).
Each vectorized map is divided by its own l2 norm before the distance is taken, and the authors stress that this normalization matters for training the student; an l1 normalization is also possible.
Attention transfer can be combined with knowledge distillation by adding the cross-entropy between softened teacher and student label distributions to the loss. The teacher's attention maps come from the same forward pass that distillation already needs, so the added cost is small. The weight \(\beta\) usually sits near 0.1 in the experiments, and it is decayed during training when attention transfer is combined with knowledge distillation.
Gradient maps and a second backward pass
In the gradient-based variant, attention is the derivative of the loss with respect to the input, which tells how strongly a small change at each pixel moves the output. \[ J_S=\frac{\partial}{\partial x}L(W_S,x),\qquad J_T=\frac{\partial}{\partial x}L(W_T,x) \] The gradient-based transfer loss is \(L_{AT}(W_S,W_T,x)=L(W_S,x)+\frac{\beta}{2}\|J_S-J_T\|_2\), so the student's input gradients are pulled toward the teacher's.
Training needs a forward and backward pass to obtain both gradients, followed by a second backward pass that differentiates the penalty with respect to the student's weights. This second pass is close to the double backpropagation technique of Drucker and LeCun, and it costs about as much as the first backward pass, excluding the forward pass.
The symmetry variant also runs flipped images through the network, flips the resulting gradient maps back, and penalizes the difference between the two gradient maps. \[ L_{sym}(W,x)=L(W,x)+\frac{\beta}{2}\left\|\frac{\partial}{\partial x}L(W,x)-\mathrm{flip}\left(\frac{\partial}{\partial x}L(W,\mathrm{flip}(x))\right)\right\|_2 \] The penalty is a soft constraint rather than a hard one, and the authors report that it has a regularizing effect.
Activation transfer on CIFAR-10
The CIFAR-10 images are 32×32, with horizontal flips and random crops as augmentation and batch normalization in all networks.
Full-activation transfer reaches 8.51 for the same pair, so most of the benefit from transferring attention does not appear when the full tensors are matched. The authors also report that attention transfer speeds convergence much more than full-activation transfer and ends with a better final accuracy, and they read this as evidence that attention maps carry more useful transfer information than full activations.
Across the other pairs in the same table, AT lowers the error of the NIN-thin student from 9.38 to 8.93, of the WRN-16-1 student with a WRN-40-1 teacher from 8.77 to 8.25, and of the WRN-16-2 student with a WRN-40-2 teacher from 6.31 to 5.85. For the WRN-16-1 and WRN-16-2 pair, combining AT with knowledge distillation gives 7.51, slightly above the 7.41 of knowledge distillation alone, while in the other listed pairs the combination is lower than distillation alone.
Training a separate loss per group of the WRN student gives 8.11, 7.96 and 7.97 for group1, group2 and group3, while the combined three-loss setting gives 7.93.
Which mapping function works best
With the same pair, the no-transfer error is 8.77, and the sum, squared sum, fourth-power sum and max variants reach 7.99, 7.93, 8.09 and 8.08 respectively. The squared sum is the lowest of these, and the table reports medians of 5 runs.
The sum-based functions perform similarly and both beat the max-based variant, so the squared sum is used for the rest of the activation experiments.
Gradient-based results on CIFAR-10
The setting uses horizontal flips only, no random crops, deterministic training with a fixed seed, single runs, and weight decay turned off, because the network already struggles to fit the training data.
The baseline error is 13.5, and minimizing the l2 norm of the input gradient reduces it to 12.5, which is the double backpropagation baseline. Gradient-based attention transfer reaches 12.1, knowledge distillation also reaches 12.1, and the symmetry norm reaches 11.8, all lower error than the baseline.
Activation-based attention transfer reaches 11.2, the lowest error in the table, within the same training conditions.
Fine-tuning on CUB and Scenes
Batch normalization layers stay fixed during fine-tuning, and the first group of residual blocks is frozen; on CUB the images are cropped to bounding boxes and rescaled before a random crop. The fine-tuned ResNet-34 serves as teacher for a ResNet-18 student with attention losses on its last two groups.
On CUB the student error is 28.5, the teacher error is 26.5, and both knowledge distillation and attention transfer reach 27. On Scenes the student error is 28.2 and the teacher error is 26, with attention transfer at 27.1 and knowledge distillation at 28.1.
The authors say attention transfer closes the gap to ResNet-34 in both cases, and they read its CUB advantage as coming from the importance of intermediate attention for fine-grained recognition. The CUB row of the table gives the same error, 27, for attention transfer and knowledge distillation, although the text describes attention transfer as working much better on CUB; the two values are reported as they appear.
The authors also note that after fine-tuning, the student's attention maps look more similar to the teacher's.
ImageNet with ResNet-18
ImageNet images are 224×224, and the setup uses a ResNet-34 teacher and a ResNet-18 student with two attention losses on the last two groups of residual blocks and squared sum attention maps. The hyperparameters were carried over from the fine-tuning experiments and not tuned.
ResNet-18 with attention transfer reaches 1.1% higher top-1 and 0.8% higher top-5 validation accuracy than without transfer.
Knowledge distillation did not help on ImageNet with ResNet-18 and ResNet-34 under the hyperparameters used on CIFAR, and it hurt convergence. With the same architecture for teacher and student, distillation converged much more slowly on ImageNet, and the authors did not train it to the end for lack of compute. The authors conclude that their activation-based transfer is the first knowledge transfer method they know of to be applied successfully on ImageNet, since they could not find other such applications.
Limitations
The gradient-based experiments use only a thin Network-In-Network without batch normalization on CIFAR-10, and the authors leave open how batch normalization should behave during the second backward pass. The symmetry norm was tested only on CIFAR-10, and the authors plan to check it on other datasets.
The ImageNet transfer uses losses on only two groups of residual blocks, and its hyperparameters were not tuned; the authors plan to add losses on all four groups. Distillation failed to give positive ImageNet results under the reused hyperparameters.
The CIFAR images are small, so the top activations have very low resolution and leave little room for attention transfer. Tasks where spatial information matters more, such as object detection or weakly-supervised localization, were not tested.
Paper info
- Authors
- Sergey Zagoruyko, Nikos Komodakis
- Venue
- arXiv · Preprint
- First published
- 2016-12-12
- Added
- 2026-11-12
- Updated
- 2017-2-12
- Version
- v3
- arXiv
- 1612.03928
- Category
- cs.CV
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Sergey Zagoruyko, Nikos Komodakis (2016). Paying More Attention to Attention: Improving the Performance of Convolutional Neural Networks via Attention Transfer. arXiv:1612.03928v3. https://arxiv.org/abs/1612.03928v3
BibTeX
@misc{zagoruyko2016paying,
title = {{Paying More Attention to Attention: Improving the Performance of Convolutional Neural Networks via Attention Transfer}},
author = {Sergey Zagoruyko and Nikos Komodakis},
year = {2016},
eprint = {1612.03928},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1612.03928v3}
}