Image Compression using only Attention based Neural Networks

Natacha Luka, Romain Negrel, David PicardarXiv 2023 · DOI

Abstract

QPressFormer is a novel, convolution-free image compression model built entirely on attention mechanisms. By replacing traditional convolutional layers with "image queries" that aggregate information via cross-attention, the researchers demonstrate that attention-only architectures can match or exceed the perceptual quality of state-of-the-art CNN-based codecs and traditional standards like BPG. This work proves that the inductive biases of convolutions are not mandatory for effective image compression and that attention can learn complex spatial relationships from scratch.

Introduction

For decades, image compression relied on handcrafted mathematical transforms like the Discrete Cosine Transform used in JPEG. Recently, Learned Image Compression using Convolutional Neural Networks (CNNs) has taken the lead, offering superior performance by learning transforms directly from data. However, while Vision Transformers (ViTs) have revolutionized other areas of computer vision by capturing long-range dependencies, they have primarily served as auxiliary components in compression architectures. This paper investigates whether an effective image compression pipeline can be built using only attention, eliminating convolutional biases to see if the flexibility of the attention mechanism can more efficiently represent visual data.

Methods: The QPressFormer Architecture

The authors introduce QPressFormer, an architecture that replaces convolutions with a transformer-only pipeline consisting of four primary stages:

  1. Analysis (Encoder): The input image is divided into patches. A set of $N=64$ learned vectors, called Image Queries, interact with these patches through a series of cross-attention layers. These queries aggregate the most critical information from the image, acting as the compressed latent representation.
  2. Bottleneck: These queries are quantized and compressed into a bitstream using a standard factorized prior model to estimate the probability distribution of the data for efficient coding.
  3. Synthesis (Decoder): To reconstruct the image, the model uses learned "patch prototypes" as queries. These prototypes use cross-attention to pull the necessary information back out of the compressed latent queries, progressively rebuilding the image patches.
  4. Perceptual Optimization: Unlike models that optimize for Mean-Squared Error (MSE)—which often results in blurry images—QPressFormer is trained using LPIPS (Learned Perceptual Image Patch Similarity). This loss function prioritizes visual "realism" over exact pixel-by-pixel matching.
The QPressFormer architecture, featuring an attention-only pipeline with Analysis (Encoder) and Synthesis (Decoder) modules.

Key Insights

  • Emergent Spatial Specialization: A fascinating finding was that the "Image Queries" naturally learned to specialize. Despite no explicit spatial instruction, individual queries evolved to focus on specific spatial regions, such as the top-left corner of an image.
  • Semantic vs. Spatial Encoding: PCA visualization revealed that the decoder extracts different information at different depths. Early layers focus on spatial layout and color transitions, while deeper layers perform internal segmentation, extracting semantic information about objects.
  • The PSNR Paradox: The model often achieves lower PSNR (Peak Signal-to-Noise Ratio) than CNN-based models but looks significantly better to the human eye. This highlights the gap between mathematical error and perceived quality.

Results and Evaluation

QPressFormer was evaluated on standard benchmarks including Kodak, CLIC, and DIV2K. It demonstrated superior performance in perceptual metrics compared to both traditional codecs (BPG) and equivalent CNN-based models.

  • Perceptual Quality: On the Kodak dataset, QPressFormer achieved an LPIPS score of 0.2126, significantly outperforming BPG (0.2872) and CNN-based models (0.3386) at similar bitrates.
  • Realism: It also led in FID (Fréchet Inception Distance). On the CLIC dataset, it scored 9.63, while the CNN equivalent scored 51.85.
  • Visual Fidelity: Qualitative results show that while CNNs tend to blur fine textures (like penguin fur) at low bitrates, QPressFormer maintains these textures much more effectively.
Qualitative comparison of QPressFormer ('Our') against CNN-based (Conv+MSE) and traditional (BPG) codecs. Note the preservation of texture in the penguin's feathers despite lower PSNR.

Limitations and Future Work

While QPressFormer proves the feasibility of attention-only compression, it currently uses a relatively simple "factorized prior" for entropy coding. Integrating more complex "hyper-priors" or autoregressive models into the transformer architecture is a clear next step for improving compression ratios. Additionally, the computational complexity of transformers remains a challenge; future work could explore more efficient attention mechanisms, such as windowed attention, to handle high-resolution images more effectively.

Summary updated

BibTeX
@misc{luka2023image,
  author = {Natacha Luka and Romain Negrel and David Picard},
  title = {{Image Compression using only Attention based Neural Networks}},
  year = {2023},
  eprint = {2310.11265},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.11265},
}
Figure