Positional Encoding As Spatial Inductive Bias in GANs

Rui Xu, Xintao Wang, Kai Chen, Bolei Zhou, Chen Change Loy

Abstract

Generative Adversarial Networks (GANs) with fully convolutional architectures are theoretically translation-invariant, yet they successfully generate images with global spatial structures. This paper identifies that standard zero padding in convolutional layers acts as an unintentional positional anchor. By replacing this accidental bias with explicit positional encodings—such as Cartesian Spatial Grids (CSG) and Sinusoidal Positional Encodings (SPE)—the authors demonstrate improved image consistency and the ability to train single models for multi-resolution synthesis.

Introduction: The Translation Invariance Paradox

In a standard convolutional generator, spatially independent noise (i.i.d.) is processed through layers that should, in theory, be translation-invariant. This implies the network should not distinguish between different spatial locations, such as the top-left corner versus the center. However, state-of-the-art models like StyleGAN2 and SinGAN consistently produce images with coherent global structures (e.g., sky at the top, ground at the bottom). This research investigates how these networks "learn" absolute position and proposes more robust methods for providing spatial inductive bias.

The "Lighthouse" Effect of Zero Padding

The authors reveal that zero padding is the hidden source of spatial information. As a convolution kernel slides over the edges of a feature map, the "zeros" injected by padding provide a unique signal. This signal is strongest at the borders and corners, acting like a "lighthouse" that allows the network to determine its absolute position.

Comparison of SinGAN results with and without padding. Removing padding leads to a loss of global structure, resulting in position-agnostic textures.

As shown in the figure above, when padding is removed, the GAN's ability to generate coherent objects collapses. Instead of structured scenes like hot air balloons or schools of fish, the model produces repetitive, unstructured textures. This confirms that GANs rely on the accidental positional information provided by padding to function.

Explicit Positional Encodings

To move beyond the limitations of accidental padding bias, the authors propose explicit spatial inductive biases:

  1. Cartesian Spatial Grid (CSG): A fixed, normalized coordinate map providing absolute anchors.
  2. Sinusoidal Positional Encoding (SPE): Using sine and cosine functions of varying frequencies. SPE is particularly effective because it is scale-invariant, allowing for better "texture recurrence."

Multi-Scale Training (MS-PIE)

Leveraging these encodings, the authors introduce MS-PIE (Multi-Scale training with PositIon Encodings). By resizing explicit positional encodings during training, a single StyleGAN2 generator can synthesize high-fidelity images across multiple resolutions (e.g., from 256x256 to 1024x1024), a task that previously required separate models for each scale.

Key Results and Insights

  • Enhanced Diversity: Explicit encodings (CSG/SPE) improved the "recall" of StyleGAN2, reducing overfitting to the rigid spatial structures imposed by standard padding.
  • SinGAN Versatility: Replacing padding with SPE in SinGAN allowed for more natural image manipulations. When expanding a scene, the SPE-based model distributed elements (like people in a crowd) naturally across the new space, whereas the original SinGAN often struggled with unstructured centers.
  • The Anchor-Texture Trade-off: The study notes that Cartesian grids are superior for anchoring global features (like facial landmarks), while Sinusoidal encodings excel at maintaining consistent textures.

Conclusion

This work highlights a fundamental yet overlooked aspect of convolutional architectures: the role of boundary conditions in providing spatial context. By transitioning from accidental padding-based signals to explicit positional encodings, researchers can build GANs that are more flexible, diverse, and capable of high-quality multi-scale synthesis. Future work may explore the implications of these findings for other popular architectures, such as Vision Transformers and Diffusion Models.

Summary updated

BibTeX
@inproceedings{xu2021positional,
  author = {Rui Xu and Xintao Wang and Kai Chen and Bolei Zhou and Chen Change Loy},
  title = {{Positional Encoding As Spatial Inductive Bias in GANs}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2021},
  doi = {10.1109/cvpr46437.2021.01336},
}
Figure