Generating images with sparse representations

Charlie Nash, Jacob Menick, Sander Dieleman, Peter W. Battaglia

Introduction

Likelihood-based generative models, such as Autoregressive Transformers, are powerful tools for image synthesis because they learn the full distribution of data, effectively avoiding the "mode collapse" often seen in Generative Adversarial Networks (GANs). However, they face a massive "curse of dimensionality." A standard 256x256 image contains nearly 200,000 individual color values; modeling these sequentially is computationally ruinous for standard attention mechanisms.

Previous solutions, like VQ-VAE, use deep neural networks to compress images into smaller, dense "latent" grids. While effective, this requires training a complex, lossy autoencoder before generative modeling can even begin. This paper introduces a compelling alternative: the DCTransformer. By abandoning raw pixels and learned latents in favor of sparse, quantized Discrete Cosine Transform (DCT) representations—the same classical mathematics powering JPEG compression—the authors enable Transformer-based models to scale to high-resolution imagery with high diversity and competitive quality.

Visualizing image sparsity: Original images alongside their sparse frequency representations.

Methodology: The DCTransformer

The core innovation of the DCTransformer is operating in the frequency domain rather than pixel space, leveraging the natural sparsity of visual data.

  1. Sparse DCT Representation: The input image is converted to the YCbCr color space and split into 8x8 pixel blocks. A 2D Discrete Cosine Transform (DCT) is applied to each block, separating low-frequency "structure" from high-frequency "detail." These coefficients are then quantized (rounded), which naturally forces many of the less important high-frequency values to zero.
  2. Coordinate Lists: Instead of maintaining a dense grid, the image is flattened into a sequence of "content triples": (DCT channel, spatial location, coefficient value). Because only non-zero elements are kept, the sequence length is drastically reduced for most images.
  3. Stacked Decoders: To model these triples autoregressively, the authors introduce a novel architecture utilizing three stacked Transformer decoders. The first predicts the channel, the second predicts the position (where to add the content), and the final decoder predicts the actual value.
  4. Chunked Training: Even with sparsity, sequences can reach over 100,000 elements for high-resolution images. The model is trained on fixed-size "chunks" (e.g., 896 elements) using a Transformer encoder to summarize all previous chunks as context. This keeps memory usage constant regardless of the total sequence length.
The DCTransformer pipeline: from pixel blocks to quantized DCT coordinate lists and coarse-to-fine decoding.

Key Insights and Capabilities

By representing images as sparse coordinates, the DCTransformer fundamentally changes how an autoregressive model "draws" an image:

  • Predicting "Where," Not Just "What": Unlike standard autoregressive models that move pixel-by-pixel across a rigid grid, the DCTransformer learns to predict where the next salient piece of information belongs. This mimics human sketching—establishing broad strokes before adding important details where they are needed most.
  • Frequency as an Inductive Bias: By sorting DCT coefficients from low to high frequency, the model naturally learns a "coarse-to-fine" generation strategy. It establishes global structure and lighting first, then iteratively fills in fine textures.
  • Resolution Independence: Because the model works on 8x8 blocks and spatial coordinates, the exact same architecture can be applied to images of varying resolutions without changing the underlying "vocabulary" of the model.
  • Classical vs. Learned Compression: The paper demonstrates that "black box" neural compressors are not strictly necessary for high-quality generation. The fixed, mathematical foundations of DCT provide a robust, interpretable sparsity that Transformers can easily exploit.

Datasets and Results

The model was rigorously evaluated across standard vision datasets (ImageNet, LSUN Bedrooms/Churches, FFHQ) and specialized high-resolution datasets (Plant Leaves at 2048x2048, Diabetic Retinopathy, and CLEVR).

  • Unprecedented Resolution: The authors demonstrated successful unconditional generation at 2048x2048 resolution on the Plant Leaves dataset. At this scale, traditional dense autoregressive models would crash due to memory constraints.
  • Superior Diversity: On ImageNet and LSUN, the DCTransformer achieved "Recall" scores (a metric for sample diversity) that frequently outperformed state-of-the-art GANs, confirming that likelihood-based models excel at covering the entire data distribution.
  • Competitive Quality: While GANs like BigGAN-deep still hold a slight edge in "Precision" (pure visual fidelity), the DCTransformer is highly competitive, particularly when measured by spatial-aware metrics like sFID.
  • Zero-Shot Multitasking: By simply altering the order of the input sequence (e.g., providing grayscale data before color data), the model performs excellently at downstream tasks like 8x super-resolution and image colorization without specialized retraining.

Limitations and Future Work

Despite its scalability, the DCTransformer inherits the primary drawback of autoregressive models: sampling speed. Generation is slow because the model must predict thousands of triples sequentially. For instance, sampling a batch of 24 images on a TPUv3 takes 20–30 minutes.

Additionally, while the model excels at local textures and coarse-to-fine rendering, maintaining perfect global coherence over very long-range dependencies (e.g., ensuring perfect symmetry across a massive architectural image) remains a challenge for chunk-based Transformers.

Looking forward, the authors suggest this sparse, coordinate-based approach is not limited to images. It could be naturally extended to other domains exhibiting inherent sparsity in the frequency domain, such as audio spectrograms or video.

Summary updated

BibTeX
@inproceedings{nash2021generating,
  author = {Charlie Nash and Jacob Menick and Sander Dieleman and Peter W. Battaglia},
  title = {{Generating images with sparse representations}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
}
Figure