# Self-Attention Generative Adversarial Networks

Self-attention lets GAN generators model long-range image structure across distant regions

Han Zhang, Ian Goodfellow, Dimitris Metaxas, Augustus Odena · arXiv · 2018-5-21

- **Problem** Convolutional GANs struggle with some ImageNet classes because convolution only combines nearby locations, so distant dependencies must pass through many layers. Details in one region cannot easily use cues from far away.
- **Method** SAGAN adds a self-attention block to the generator and discriminator, so each position draws on all feature locations. It also applies spectral normalization to both networks and uses TTUR to stabilize training.
- **Results** SAGAN reaches an Inception score of 52.52 and an FID of 18.65 on class-conditional ImageNet at 128×128. That beats SNGAN-projection, which scored 36.8 and 27.62.

## Why convolution alone struggles with global structure

Convolutional GANs produce some image classes well and others poorly when they are trained on a multi-class dataset such as ImageNet. The strongest ImageNet GAN of the time handled classes defined mainly by texture, such as ocean and landscape, but drew dogs with realistic fur and no clearly separated feet. The authors trace this to convolution: its receptive field is local, so a dependency between distant regions has to pass through several layers before it can be used.

The authors list three obstacles to learning such long-term dependencies: a small model may lack the capacity, optimization may fail to coordinate several layers, and the learned parameterizations may break on inputs not seen in training. Enlarging convolution kernels adds capacity but gives up the computational and statistical efficiency of local convolution.

Self-attention offers a different balance, because each output is computed from all positions at a modest computational cost.

## How the self-attention block computes its output

The block takes the feature map of the previous hidden layer, a tensor of C channels over N feature locations. Two learned 1×1 projections map this input into two feature spaces, f(x) = W\_f x and g(x) = W\_g x, and the pairwise score between locations i and j is \\\\(s\_{ij} = f(x\_i)^{T} g(x\_j)\\\\). For each target position j, a softmax over all source positions i gives the weights \\\\(\\\\beta\_{j,i} = \\\\exp(s\_{ij}) / \\\\sum\_{i=1}^{N} \\\\exp(s\_{ij})\\\\), so each row of weights sums to one.

A third projection h(x) = W\_h x produces the values that are mixed by these weights, and the output at position j is \\\\(o\_j = v\\\\left(\\\\sum\_{i=1}^{N} \\\\beta\_{j,i}\\\\, h(x\_i)\\\\right)\\\\), where v(x) = W\_v x maps the result back to C channels. The projections W\_f, W\_g and W\_h reduce the channel count to \\\\(\\\\bar{C}\\\\), and the authors set \\\\(\\\\bar{C} = C/8\\\\) (k = 8) in all experiments, saying that they saw no notable loss at smaller reductions.

The attention output is multiplied by a learnable scalar γ, which is initialized to 0, and the input is added back, so \\\\(y\_i = \\\\gamma o\_i + x\_i\\\\). Because γ starts at zero, the block initially passes its input through unchanged, and the network can use local cues first and gradually give more weight to non-local evidence, which the authors describe as an easier task learned before a harder one.

## Training the generator and discriminator together

The generator and discriminator are trained in alternation with the hinge version of the adversarial loss. The discriminator loss is \\\\(L\_D = -\\\\mathbb{E}\_{(x,y)\\\\sim p\_{data}}\[\\\\min(0,-1+D(x,y))\] - \\\\mathbb{E}\_{z\\\\sim p\_z,\\\\,y\\\\sim p\_{data}}\[\\\\min(0,-1-D(G(z),y))\]\\\\), so real and generated scores are each clipped at zero before they enter the loss.

The generator loss is \\\\(L\_G = -\\\\mathbb{E}\_{z\\\\sim p\_z,\\\\,y\\\\sim p\_{data}} D(G(z),y)\\\\), which pushes the discriminator score on generated samples upward.

Spectral normalization is applied to the weights of both networks, where the earlier work by Miyato et al. had used it only in the discriminator to bound its Lipschitz constant. The authors extend it to the generator because of evidence that generator conditioning affects GAN performance, and they report that it prevents parameter magnitudes from growing and reduces unusual gradients.

With spectral normalization on both networks, the authors found that fewer discriminator updates per generator update are needed, which lowers the training cost.

Regularized discriminators usually need several discriminator steps for each generator step, and TTUR gives the two networks separate learning rates to offset the slow learning this causes. The default learning rate is 0.0004 for the discriminator and 0.0001 for the generator, with the Adam optimizer using β1 = 0 and β2 = 0.9.

## Evaluation protocol and default settings

Experiments use the LSVRC2012 (ImageNet) dataset, which has 1000 classes, and the models generate 128×128 images. Each model is scored with the Inception score, FID and intra FID, computed from 50k generated samples per model. Intra FID applies the same computation within each class, so it captures how well each class is modeled.

The Inception score is kept because it is widely used, which allows comparison with earlier work, but the authors stress that it mainly checks class recognizability and class coverage rather than realism of detail or diversity within a class. SAGAN uses conditional batch normalization in the generator and a projection-based discriminator, and spectral normalization is applied to the layers of both networks by default.

## Effect of spectral normalization and TTUR on training

The baseline, which applies spectral normalization only in the discriminator, becomes unstable when updates are balanced 1:1, and it collapses to a few modes early in training. Its samples at the 10k-th iteration are shown in Figure 4, and its FID at that point is 181.84. The original work avoided this by using 5:1 updates for the discriminator and generator, which the authors contrast with the faster convergence that stable 1:1 training would allow.

Adding spectral normalization to both networks makes 1:1 training stable, with an FID of 33.39 at the 160k-th iteration for SN on G/D. Without TTUR, though, sample quality does not improve monotonically, and FID and Inception score begin to drop around the 260k-th iteration, where FID reaches 72.41.

Adding TTUR to the spectrally normalized model, SN on G/D+TTUR, makes sample quality improve steadily through training, with the reported FID at 1M iterations being 22.96. Across the training curves, the authors observe no notable decline in FID, Inception score or sample quality over one million iterations, and they conclude that the two techniques are at least partly additive.

## Where the attention block helps

Without attention, the model reaches an FID of 22.96 and an Inception score of 42.87 after one million iterations. Attention at the middle-to-high resolutions therefore gives the best results in Table 1, while attention at 8×8 changes FID very little from the no-attention model.

In the residual-block control, which has the same number of parameters, the 8×8 variant does not train stably, and its FID rises from 22.98 to 42.13. Even where training is stable, the residual variant is worse, for example with FID 27.33 against 18.28 at 32×32. The authors conclude that the gain from SAGAN is not simply the result of a deeper or larger model.

The authors explain the placement effect by arguing that self-attention can use larger feature maps more freely and complements convolution there, whereas on 8×8 maps it acts much like a local convolution.

## What the learned attention maps attend to

The authors visualize the attention of the last generator layer that uses attention, since that layer is closest to the output pixels. For query points chosen in each example, attention follows similarity of color and texture rather than spatial adjacency alone, and two nearby query points can attend to very different regions. In one example the attention around a blue query point helps the model draw dogs with clearly separated legs, which the authors take as evidence that attention helps shape the joint area.

These maps are qualitative examples; the paper reports no quantitative measure of attention behavior.

## Comparison with SNGAN-projection and AC-GAN

AC-GAN reaches an Inception score of 28.5 and an intra FID of 260.0, with no FID value reported. SNGAN-projection reaches an Inception score of 36.8, an intra FID of 92.4 and an FID of 27.62, where the FID was calculated from officially released weights. SAGAN reaches an Inception score of 52.52, an intra FID of 83.7 and an FID of 18.65 in the same table.

The authors read the lower FID and intra FID as evidence that SAGAN approximates the real image distribution better, which they attribute to modeling long-range dependencies between regions. On classes defined mainly by texture, such as valley, stone wall and coral fungus, the advantage over the baseline model is smaller, and the authors explain this by attention playing a role similar to local convolution for simple textures.

## Limitations

The class-level advantage narrows on texture-dominated classes, so the overall gain should not be read as uniform across ImageNet classes. The Inception score checks whether samples are confidently recognized as a class and whether many classes are covered, and it does not directly assess detail realism or intra-class diversity.

All reported experiments use ImageNet at 128×128 with class-conditional generation. The comparison in Table 2 is against two prior models, AC-GAN and SNGAN-projection. Table 1 and Table 2 report single values per model, with no variance across runs shown.

## Paper info

- **Authors**: Han Zhang, Ian Goodfellow, Dimitris Metaxas, Augustus Odena
- **Venue**: arXiv · Preprint
- **First published**: 2018-5-21
- **Added**: 2026-11-12
- **Updated**: 2019-6-14
- **Version**: v2
- **arXiv**: 1805.08318
- **Category**: stat.ML · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1805.08318v2) · [PDF ↗](https://arxiv.org/pdf/1805.08318v2)

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

Han Zhang, Ian Goodfellow, Dimitris Metaxas, Augustus Odena (2018). Self-Attention Generative Adversarial Networks. arXiv:1805.08318v2. https://arxiv.org/abs/1805.08318v2

**BibTeX**

```
@misc{zhang2018self,
  title = {{Self-Attention Generative Adversarial Networks}},
  author = {Han Zhang and Ian Goodfellow and Dimitris Metaxas and Augustus Odena},
  year = {2018},
  eprint = {1805.08318},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1805.08318v2}
}
```

## Other paper commentary

- [GLIDE: Towards Photorealistic Image Generation and Editing with Text-Guided Diffusion Models](https://refivu.com/en/papers/85a30c3b-b6e0-4eaf-8fb4-fe6a473a1c05-glide-towards-photorealistic-image-generation-and-editing.md)
- [Variational Quantum Algorithms](https://refivu.com/en/papers/6d58f3e0-2a35-428c-950f-93a8daccb221-variational-quantum-algorithms.md)
- [StarGAN: Unified Generative Adversarial Networks for Multi-Domain Image-to-Image Translation](https://refivu.com/en/papers/b61e89a8-05ef-4482-bc67-b5bed59283d8-stargan-unified-generative-adversarial-networks-for-multi.md)
- [Variational Graph Auto-Encoders](https://refivu.com/en/papers/68c3cbf9-0251-40aa-bdb7-85593b91a6b5-variational-graph-auto-encoders.md)
- [Variational Inference: A Review for Statisticians](https://refivu.com/en/papers/9499b5e2-6ec4-4fcc-8d8e-4709801c41a4-variational-inference-a-review-for-statisticians.md)
- [High-Resolution Image Synthesis and Semantic Manipulation with Conditional GANs](https://refivu.com/en/papers/ad89d7a4-6049-4da7-8901-5fe971c7ff30-high-resolution-image-synthesis-and-semantic-manipulation.md)
- [What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision?](https://refivu.com/en/papers/6f981a48-48a7-46de-b89d-79c37884de4f-what-uncertainties-do-we-need-in-bayesian-deep.md)
- [MiniGPT-4: Enhancing Vision-Language Understanding with Advanced Large Language Models](https://refivu.com/en/papers/f07e6e3f-3ab5-42dc-98c8-a32fe7d8820d-minigpt-4-enhancing-vision-language-understanding-with.md)
- [Multi-view Convolutional Neural Networks for 3D Shape Recognition](https://refivu.com/en/papers/80b8aedd-6f52-4a73-bc81-a80322e5e37c-multi-view-convolutional-neural-networks-for-3d-shape.md)
- [FaceForensics++: Learning to Detect Manipulated Facial Images](https://refivu.com/en/papers/715249f5-5289-4880-bf0c-b3dbd3630c47-faceforensics-learning-to-detect-manipulated-facial-images.md)
- [Efficient Multi-Scale 3D CNN with Fully Connected CRF for Accurate Brain Lesion Segmentation](https://refivu.com/en/papers/5fa28c90-a21c-4b80-9a3e-409a47ddd061-efficient-multi-scale-3d-cnn-with-fully-connected.md)
- [Deep learning for time series classification: a review](https://refivu.com/en/papers/29b2a81b-5835-4366-b268-5617285bb0b9-deep-learning-for-time-series-classification-a-review.md)

## Terms in this paper

- [ImageNet](https://refivu.com/en/terms/5eadad128667-imagenet)
- [self-attention](https://refivu.com/en/terms/426589b81077-self-attention)
- [FID](https://refivu.com/en/terms/e110afe65f86-fid)
- [Adam optimizer](https://refivu.com/en/terms/aff9e901333e-adam-optimizer)
- [inception score](https://refivu.com/en/terms/25dbfbd4fd96-inception-score)
- [residual block](https://refivu.com/en/terms/bb4b0de94056-residual-block)
- [spectral normalization](https://refivu.com/en/terms/bf3f626bf932-spectral-normalization)
- [baseline model](https://refivu.com/en/terms/c86edbf4762a-baseline-model)
- [Conditional Batch Normalization](https://refivu.com/en/terms/5ec4bcf33093-conditional-batch-normalization)
- [Lipschitz constant](https://refivu.com/en/terms/0ebdfcbc7934-lipschitz-constant)
- [TTUR](https://refivu.com/en/terms/03e059c51165-ttur)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/819d5b11-1213-4c83-93af-58db3c44b12f-self-attention-generative-adversarial-networks)
