Efficient Contextformer: Spatio-Channel Window Attention for Fast Context Modeling in Learned Image Compression

A. Burakhan Koyuncu, Panqi Jia, Atanas Boev, Elena Alshina, Eckehard Steinbach

TL;DR

eContextformer is a high-performance, low-complexity entropy model that brings transformer-level compression efficiency to practical speeds. By fusing multiple parallelization strategies and optimizing attention mechanisms through caching and tensor rearrangement, it achieves up to 17% bitrate savings over the VVC standard while running over 200x faster than its predecessor.

What Problem Does This Paper Address?

In learned image compression (LIC), entropy models are used to estimate the probability distribution of "latent" representations of an image. The more accurate this estimate, the better the compression.

The most powerful models are autoregressive, meaning they predict the next element based on previously decoded ones. While effective, this creates a massive serial bottleneck: you can't decode the 100th pixel until you've finished the first 99. Transformer-based models (like the authors' previous Contextformer) capture long-range dependencies brilliantly but suffer from quadratic computational complexity and extremely slow decoding times, making them impractical for real-world deployment on GPUs or NPUs.

Methods

The authors introduce several architectural and algorithmic optimizations to create the Efficient Contextformer (eContextformer):

  • Spatio-Channel Window Attention: Inspired by the Swin Transformer, this mechanism limits attention to local "windows" but extends the concept across both spatial and channel dimensions.
  • Parallelization Fusion: The model combines three grouping techniques—patch-wise, checkered, and channel-wise—to allow many latent elements to be processed simultaneously without sacrificing the benefits of autoregression.
  • EGR & SFG:
    • Efficient coding Group Rearrangement (EGR): A tensor-level optimization that reshapes data to minimize unnecessary attention map calculations.
  • Skipping First coding Group (SFG): Reduces the total number of autoregressive steps by relying solely on the "hyperprior" for the initial data group.
  • Key-Value (KV) Caching: During decoding, the model caches previous attention computations. This transforms the complexity of the growing attention span from $O(N^2)$ to $O(N)$, drastically speeding up the process.

Datasets

  • Training: The model was trained on the Vimeo-90K dataset and fine-tuned using COCO 2017 (with crops up to 384x384) to improve performance on high-resolution images.
  • Evaluation: Performance was benchmarked against standard datasets: Kodak, CLIC2020 (Professional and Mobile), and Tecnick.

Key Insights and Ideas

  • The "Expanding" Attention Span: By using KV caching with shifted windows, the model's receptive field effectively grows with each decoding step in both spatial and channel dimensions, providing a "global-like" context at a fraction of the cost.
  • Parallelization vs. Performance: The authors demonstrate that fusing grouping techniques can reduce decoding time by orders of magnitude with only a negligible (~3%) drop in compression performance.
  • Enabling Online RDO: Because the eContextformer is so computationally light, it becomes feasible to use online Rate-Distortion Optimization (oRDO). This allows the encoder to iteratively "fine-tune" the latent representation for a specific image during the encoding process, reclaiming and even surpassing the performance lost to parallelization.

Key Results

  • Speed & Complexity: Compared to the original Contextformer, eContextformer achieves a 145x reduction in model complexity (MACs) and a 210x speedup in decoding time.
  • Compression Efficiency:
    • Achieves average bitrate savings of 10.9% to 13.2% over the VVC (VTM 16.2) intra-coding standard across various datasets.
  • With oRDO enabled, bitrate savings reach up to 17% over VTM 16.2.
  • Qualitative: Visual comparisons show the model preserves contours and high-frequency details better than VTM 16.2, which often suffers from aliasing and blurring at low bitrates.

Limitations and Future Work

The authors acknowledge that while their context model is highly optimized, the underlying analysis and synthesis transforms (the autoencoder part) are relatively standard. They suggest that future work could focus on developing more advanced non-linear transforms to provide even better energy-compacted latent spaces. Additionally, they noted that sliding window attention can become less stable when training with extremely high-resolution images, suggesting a need for further refinement in training stability for ultra-HD content.

Summary updated

BibTeX
@article{koyuncu2024efficient,
  author = {A. Burakhan Koyuncu and Panqi Jia and Atanas Boev and Elena Alshina and Eckehard Steinbach},
  title = {{Efficient Contextformer: Spatio-Channel Window Attention for Fast Context Modeling in Learned Image Compression}},
  journal = {IEEE Transactions on Circuits and Systems for Video Technology},
  year = {2024},
  doi = {10.1109/tcsvt.2024.3371686},
}
Figure