Transformer-based Image Compression

Ming Lu, Peiyao Guo, Huiqing Shi, Chuntong Cao, Zhan Ma

TL;DR

The authors introduce a Transformer-based Image Compression (TIC) model that combines Swin Transformers and convolutional layers to capture both long-range and short-range image dependencies. By replacing standard CNN-heavy architectures with hybrid Neural Transformation Units (NTUs) and a novel Causal Attention Module (CAM), TIC achieves state-of-the-art compression rates comparable to the VVC Intra standard, but with up to 45% fewer parameters than leading deep learning methods.

What Problem Does This Paper Address?

In recent years, deep learning-based Learnt Image Coding (LIC) has started to outperform traditional handcrafted image compression standards like JPEG, JPEG2000, and HEVC. Most of these LIC systems rely heavily on Convolutional Neural Networks (CNNs) within a Variational Autoencoder (VAE) framework.

However, CNNs have inherent limitations for compression:

  1. Locality: They only capture short-range spatial correlations restricted by their receptive field.
  2. Rigidity: Offline-trained CNNs use fixed parameters, making it hard to adapt to images with vastly different content distributions without caching multiple models.
  3. Inefficiency: To capture long-range dependencies, researchers often bolt handcrafted attention mechanisms onto CNNs. This bloats the model with excessive parameters, making them impractical for real-world deployment on consumer devices.

The authors tackle this by asking: Can we leverage the global reach of Vision Transformers (specifically Swin Transformers) alongside the local precision of CNNs to create a leaner, more efficient compression algorithm?

Methods

The paper builds on the canonical VAE architecture (main and hyper encoder-decoders) but fundamentally changes the building blocks used to process the image.

  • Neural Transformation Unit (NTU): Instead of stacking standard convolutional layers, the authors introduce the NTU. Each NTU pairs a Swin Transformer Block (STB) with a Convolutional layer (Conv). The Conv layer handles short-range spatial information and resolution scaling (downsampling/upsampling), while the STB aggregates long-range dependencies.
  • Early Convolution: Rather than immediately chopping the input image into Transformer tokens (which can cause training instability), the model first passes the image through standard convolutions for early visual processing before feeding it into the NTUs.
  • Causal Attention Module (CAM): At the bottleneck (where the actual compression happens), the model needs to predict the context of the data to encode it efficiently. Existing methods use masked CNNs for this. The authors replace this with a CAM, which unfolds quantized features into patches and applies masked self-attention to autoregressive neighbors. This ensures causality (only looking at previously decoded data) and fuses the data with hyper priors using a Multi-Layer Perceptron (MLP).
  • TIC+: An extended variant of the model that places additional Swin Transformer Blocks in the layers closest to the bottleneck to further boost performance.

Datasets

  • Training: Flicker 2W dataset. Images were randomly cropped into fixed $256 \times 256 \times 3$ patches.
  • Evaluation: Kodak dataset, a standard benchmark for image compression. Performance was measured using Peak Signal-to-Noise Ratio (PSNR) for quality and bits per pixel (bpp) for bit rate.

Key Insights and Ideas

  • The Best of Both Worlds: Convolutions are excellent at understanding local neighborhoods, while Transformers excel at global context. By interleaving them, the network doesn't have to "guess" long-range structures through deep stacks of convolutions, leading to a highly efficient feature extraction process.
  • Visualizing Compactness: The authors visualized the gradient maps of the latent features to see how compactly the model represents input pixels. The TIC model produces a significantly more concentrated and compact latent representation compared to state-of-the-art CNN-only models. This compactness is the direct driver of its superior coding efficiency.
  • Parameter Efficiency via Swin: Because Swin Transformers compute self-attention within shifted local windows rather than across the entire image globally, they drastically reduce computational complexity while still capturing non-local data.

Key Results

  • Massive Parameter Reduction: The base TIC model achieves competitive rate-distortion performance against the state-of-the-art CNN method (Cheng et al.) but requires up to 45% fewer model parameters, making it much more viable for real-world applications.
  • Beating the Standard: The enhanced TIC+ model surpasses the highly optimized Versatile Video Coding (VVC) Intra standard (VTM 12.1) by 2.6% in BD-Rate (Bjøntegaard Delta Rate), with only a slight increase in parameters over the base TIC model.
  • Qualitative Quality: Visually, TIC produces reconstructions with sharper textures and less noise at similar or lower bitrates compared to HEVC (BPG) and VVC Intra.

Limitations and Future Work

  • Limitations: While the paper heavily emphasizes parameter reduction, it does not explicitly benchmark the real-time inference speed (computational runtime) against CNNs. Transformers, even windowed ones, can sometimes introduce latency bottlenecks on hardware optimized primarily for convolutions.
  • Future Work: The authors note that adding more STBs (as seen in TIC+) improves coding gains. A key direction for future research is an ablation study to determine exactly how many STBs are optimal for maximizing coding efficiency without hitting diminishing returns on compute and parameter size.

Summary updated

BibTeX
@inproceedings{lu2022transformer,
  author = {Ming Lu and Peiyao Guo and Huiqing Shi and Chuntong Cao and Zhan Ma},
  title = {{Transformer-based Image Compression}},
  booktitle = {DCC},
  year = {2022},
  doi = {10.1109/dcc52660.2022.00080},
}
Figure