Efficient Image Compression Using Advanced State Space Models
Bouzid Arezki Anissa Mokraoui Fangchen Feng









Efficient Image Compression Using Advanced State Space Models
    Bouzid Arezki
L2TI Laboratory 

University Sorbonne Paris Nord

Villetaneuse, France 

bouzid.arezki@edu.univ-paris13.fr
Anissa Mokraoui
L2TI Laboratory 

University Sorbonne Paris Nord

Villetaneuse, France 

anissa.mokraoui@univ-paris13.fr
Fangchen Feng
L2TI Laboratory 

University Sorbonne Paris Nord

Villetaneuse, France 

fangchen.feng@univ-paris13.fr


    September 4, 2024
============================================================================================================================================================================================================================================================================================================================================================================



§ ABSTRACT 
Transformers have led to learning-based image compression methods that outperform traditional approaches. However, these methods often suffer from high complexity, limiting their practical application. To address this, various strategies such as knowledge distillation and lightweight architectures have been explored, aiming to enhance efficiency without significantly sacrificing performance. This paper proposes a State Space Model-based Image Compression (SSMIC) architecture. This novel architecture balances performance and computational efficiency, making it suitable for real-world applications. Experimental evaluations confirm the effectiveness of our model in achieving a superior BD-rate while significantly reducing computational complexity and latency compared to competitive learning-based image compression methods.




Image Compression, State Space Models, Computational Complexity, Rate-Distortion




§ INTRODUCTION

Visual compression represents a fundamental challenge in multimedia processing. Over the past few decades, classical standards have predominantly been employed including BPG, JPEG, JPEG2000, H.265/HEVC, and H.266/VVC. With the introduction of deep neural network architectures such as Convolutional Neural Networks (CNNs) <cit.> and Transformers <cit.>, learning-based compression methods have emerged, demonstrating continuously improving performance and garnering interest over traditional approaches. These architectures typically include a two-level hierarchical variational autoencoder with a hyper-prior as the entropy model. They consist of two sets of encoders and decoders: one for the generative model and another for the hyper-prior model. However, deep learning-based compression approaches often suffer from high complexity, which limits their practicality in real-world applications. Although it is common practice to propose scaled-down models by choosing a relatively smaller model size, these models, while less complex and faster, often significantly sacrifice the compression performance <cit.>. Other approaches have been deployed to accelerate these models while maintaining their performance. Knowledge distillation is one effective method for accelerating neural networks across various computer vision tasks <cit.>. In this context, EVC <cit.> used a mask decay method based on teacher-student training. Another promising direction involves the development of lightweight  architectures <cit.>. Recent advancements in lightweight attention mechanisms have resulted in architectures with improved inference times for image compression <cit.>. Other noteworthy contributions include <cit.>, where the authors focus on reducing decoding complexity through the proposal of shallow decoding transforms. Additionally, the work in <cit.> focuses on improving the efficiency of the entropy model.



Recently, the State Space model and its variant, the Mamba model, have garnered significant attention in the field of computer vision. State Space Models (SSMs) were initially introduced in deep neural networks for sequence modeling <cit.>, unifying the strengths of previous sequence models, including Continuous-Time Models (CTMs), Recurrent Neural Networks (RNNs), and CNNs. Despite their potential, SSMs have not seen widespread use due to their high computational and memory requirements, which stem the latent state representation connecting the input and output. Mamba <cit.> addresses these limitations by integrating a selection mechanism into the structured variants of SSMs, enhancing their context-based reasoning ability. In this paper, we propose a State Space Model-based Image Compression (SSMIC) architecture focusing on rate-distortion performance, computational complexity, and latency. The contributions of this paper are as follows: 


  * SSMIC balances compression efficiency, computational complexity, and latency for practical multimedia processing applications. 

  * SSMIC integrates SSMs from the Mamba model into the image compression pipeline, enhancing contextual reasoning while managing computational and memory requirements.

  * SSMIC is a lightweight architecture designed for efficient real-time image compression on resource-constrained devices.

  * Extensive experiments across benchmark datasets show that SSMIC achieves competitive compression performance with reduced computational complexity and latency compared to existing methods. Fig. <ref>, depicting the trade-off between BD-rate and computational complexity on the Kodak dataset, validates the standing of SSMIC among competitive state-of-the-art methods.








§ RELATED WORKS




 §.§ Deep Learning-based Image Compression


Among the early works, the authors of <cit.> introduced a CNN-based two-level hierarchical architecture. The authors of <cit.> incorporated an attention mechanism into the image compression framework by introducing self-attention in the hyper-prior model. A more sophisticated approach, the Swin block <cit.>, has been proposed for use in both the generative and hyper-prior models <cit.>. Additionally, the authors of <cit.> proposed a Transformer-CNN Mixture (TCM) block, which leverages the strengths of both transformers and CNNs by splitting the feature dimension into separate branches for each. Although TCM improves compression performance compared to transformer-only architectures, it does not reduce encoding or decoding time.




 §.§ Lightweight Attention


Ever since the attention mechanism for visual tasks was proposed and achieved impressive results, efforts to reduce its complexity have been underway. The Swin Transformer, for instance, introduced window-based self-attention to limit computational cost <cit.>. Mobile-Former <cit.> leverages the advantages of MobileNet <cit.> for local processing and the strengths of transformers for global interaction. Similarly, EdgeViT <cit.> and EdgeNeXt <cit.> combine local interaction (convolution) with global self-attention. MobileViT <cit.>, another lightweight, general-purpose vision transformer for mobile devices, uses a multi-scale sampler for efficient training. Additionally, LVT <cit.> develops enhanced self-attention mechanisms to improve computational efficiency. A ladder self-attention and progressive shift mechanism was proposed in <cit.> for lightweight transformers. In <cit.>, an efficient long-range attention network was designed for image super-resolution tasks, which inspired <cit.> for image compression. Other works  focused on image compression as well, such as <cit.>, which proposed a Swin-like block without positional encoding, thereby reducing the number of trainable parameters. 




 §.§ Mamba for Visual Compression


The most closely related work to our approach is the recently proposed MambaVC <cit.>, which incorporates the Mamba block into the image compression architecture to achieve promising results. Despite this similarity, our design differs significantly from theirs. While MambaVC focuses on improving compression performance, our approach is distinct in that it emphasizes designing a computationally efficient compression model. This difference in motivation results in unique design choices throughout the architecture, which will be detailed in the following section.





§ NOVEL STATE SPACE MODEL-BASED IMAGE COMPRESSION (SSMIC)











 §.§ Preliminaries

Before presenting our SSMIC architecture, we introduce some useful information hereafter.

The SSM transformation in S4 <cit.> originates from the classical state space model, which maps a one dimensional input signal x(t) ∈ℝ to a one dimensional output signal y(t) ∈ℝ through a latent state h(t) ∈ℝ^N of dimension N:

    h'(t) = 𝐀h(t)+ 𝐁x(t), 
       y(t) = 𝐂h(t),

where 𝐀∈ℝ^N × N, 𝐁∈ℝ^N × 1,
𝐂∈ℝ^1 × N are parameters of neural networks in deep learning.
To deal with the discrete input sequence x= [x_0,x_1, …, x_L-1] ∈ℝ^L, the parameters in equation (<ref>) are discretized using a step size Δ, which represents the resolution of the continuous input x(t) <cit.>. In particular, the continuous parameters 𝐀 and 𝐁 are converted into discretization parameters 𝐀 and 𝐁 by the zero-order hold (ZOH) technique, defined as:

    𝐀 = exp(Δ𝐀), 
       𝐁 = (Δ𝐀)^-1 (exp(Δ𝐀)-𝐈).Δ𝐁.

After discretizing 𝐀 and 𝐁 to 𝐀 and 𝐁,  equation (<ref>) can be reformulated as: 

    h_t = 𝐀h_t-1 + 𝐁x_t, 
       y_t = 𝐂h_t.


SSMs can be efficiently computed using RNNs. This recursive process can  be reformulated and computed as a convolution:

    𝐊 = (𝐂𝐁, 𝐂𝐀𝐁,…, 𝐂𝐀^L-1𝐁), 
       y=x*𝐊,

where L denotes the length of the input sequence x;  and 𝐊∈ℝ^L is the SSM convolution kernel.

Mamba <cit.> further incorporates data-dependence to capture contextual information in equation (<ref>) by proposing a novel parameterization method for SSMs that integrates an input-dependent selection mechanism, referred to as S6. Although the recurrent nature of SSMs restricts full parallelization, Mamba employs structural reparameterization tricks and a hardware-efficient parallel scanning algorithm to boost overall efficiency. As a result, many works have adapted Mamba from Natural Language Processing (NLP) to the vision domain <cit.>.




 §.§ Proposed SSMIC architecture


The proposed SSMIC architecture follows a general two-level architecture. Specifically, the input image x is first encoded by the generative encoder y=g_a(x), and the hyper-latent z=h_a(y) is obtained through the encoder of the hyper-prior network. The quantized version of the hyper-latent ẑ is modeled and entropy-coded using a learned factorized model before being passed through h_s(ẑ). The output of h_s, along with the output of the context model, enters the entropy parameters network <cit.>, which generates the mean μ and scale σ parameters for a conditional Gaussian entropy model P(y|ẑ)= 𝒩(μ, σ^2) to model y. The quantized latent ŷ=Q(y) is finally entropy-coded (Arithmetic encoding/decoding AE/AD) and sent to x̂=g_a(ŷ) for reconstructing the image x̂. A detailed illustration is shown in Fig. <ref>. 


We propose using the context model from <cit.>, which draws inspiration by traditional coding techniques that predict the probability of unknown codes based on previously decoded latents. Unlike the architecture in <cit.>, our choice is driven by the goal of developing a computationally efficient architecture. While more sophisticated channel-wise autoregressive models <cit.> can enhance performance, they are significantly more time-consuming <cit.>. We use the classical strategy of adding uniform noise to simulate the quantization operation (Q) which makes the operation differentiable <cit.>.

The generative and the hyper-prior encoder, g_a and h_a, are built with the patch merge block and the Visual State Space (VSS) block illustrated in Fig. <ref>. The patch merge block contains the Depth-to-Space operation <cit.> for down-sampling, a normalization layer, and a linear layer to project the input to a certain depth C_i. In g_a, the depth C_i of the latent representation increases as the network gets deeper, allowing for a more abstract representation of the image. The size of the latent representation decreases accordingly. In each stage, we down-sample the input feature by 2. Compared to the convolutional layer used in MambaVC <cit.> for a similar purpose, the chosen patch merge block is easier to implement and is also computationally friendly. 

VSS block, which was originally proposed in <cit.>,  consists of a single network branch with two residual modules, mimicking the architecture of the vanilla Transformer block <cit.>.  Specifically, each stage in our SSMIC consists of a sequence of VSS blocks and the number of blocks in  stage i is denoted as d_i (see in Fig. <ref>). Given an input feature maps 𝐟∈ℝ^H× W × C, we get 𝐟” from a first residual module:

    𝐟” = 𝐟+𝐟',


where f' is obtained through multiple layers as follows:

    𝐟' = MLP_2(LN_2(SS2D(
        
    σ( 
        DWConv(MLP_1(LN_1((f)))))))).

As illustrated in Fig. <ref> (see (a) and (b)), the output of the VSS block is given by:

    𝐟_out =  MLP_3(LN_3(𝐟”)) + 𝐟”,

where LN represents the normalization layer; SS2D is the 2D selective scan module; σ is the SiLU activation <cit.>; DWConv is the depthwise convolution; and MLP is the learnable linear projection. Unlike VSS block in <cit.>, we use RMSNorm <cit.> instead of LN LayerNorm since we found empirically that the RMSnorm significantly improves the convergence speed during training.

We adhere to the selective scan approach proposed in <cit.> that adapts input-dependent selection mechanism <cit.> to vision data without reducing its advantages. SS2D involves three steps as shown in Fig. <ref> (c).
Cross-scan: unfolds input features into sequences along four distinct traversal paths; Selective scan: processes each path with a distinct S6 in parallel; Cross-merge: subsequently reshapes and merges the resultant sequences to form the output feature, enabling effectively integrating information from other pixels in different directions relative to each current pixel. This facilitates the establishment of global receptive fields in the 2D space.






§ EVALUATION AND ANALYSIS


To evaluate the compression efficiency of SSMIC, we propose a performance study across three aspects: rate-distortion (RD), BD-rate, computational complexity and latency.








 §.§ Configuration Setup


The SSMIC model was trained on the CLIC20 training set <cit.>. The loss function used is L = D + λ R, where R represents the bitrate and D denotes the distortion. The Mean Squared Error
(MSE) in the RGB color space is used as the distortion metric. The Lagrangian multiplier λ governs the Rate-Distortion (RD) trade-off. We trained SSMIC with λ∈{100, 50, 30, 10}. Each training batch contains 8 random crops of size 256×256. We performed 1 million (1M) iterations using the ADAM optimizer, with the learning rate set to 10^-4. Our SSMIC architecture was implemented in Pytorch using CompressAI library <cit.>. 



We evaluate the performance of the model on three datasets: Kodak <cit.>, JPEG-AI <cit.>, and the test set of CLIC20 <cit.> including both mobile and professional categories. During inference, all images were padded with zeros if their size is not a multiple of 256. We compare the proposed SSMIC against the following models: SwinT <cit.>, MambaVC <cit.>, LightweightLIC <cit.>, LIC_TCM <cit.>, SwinNPE <cit.>, MLIC+ <cit.> and ELIC <cit.>. These models are selected because they are either competitive in terms of compression performance or competitive in terms of the computational efficiency. We also show the compression performance of BPG444 <cit.> as a baseline. For LightweightLIC <cit.>, LIC_TCM <cit.>, SwinNPE <cit.>, and ELIC <cit.>, we evaluated their compression performance and complexity efficiency using their provided pre-trained models under the same configuration as SSMIC. For SwinT <cit.>, MambaVC <cit.>, and MLIC+ <cit.>, as pre-trained models were not available, we assessed their computational complexity using their untrained models and referenced the RD-curves from their respective papers to evaluate compression performance. The experiments were carried out on an A100 80 Go GPU and an Intel Xeon Gold 6330 3.10 GHz CPU.









 §.§ Performance Comparison


We summarize in Table <ref>, the BD-rate of SSMIC and the competitive state-of-the-art models across three datasets. The BD-rate was calculated covering approximately 0.4 to 1.2 bits per pixel (bpp), using VTM-15.0 <cit.> as a reference. 

On average, SSMIC achieves a -21.75% BD-rate performance compared to VTM-15.0 and 4.17 p.p., relative
increase from LIC_TCM <cit.> which provides the best performance compared to the other selected methods.  However, the latter is much more demanding in terms of computational 
complexity and number of parameters. This is shown in Fig. <ref>, which provides the BD-rate with VTM-15.0 as an anchor versus the GMACs [MACs and FLOPs are calculated using calflops Library 
<https://github.com/MrYxJ/calculate-flops.pytorch> ] 
of various approaches on the Kodak dataset. These observations confirm that our SSMIC offers a good trade-off between BD-rate performance and computational complexity.

We also evaluate the compression performance of different models across various bitrate ranges on the Kodak dataset in Fig. <ref>. The results show that the proposed model consistently achieves performance comparable to state-of-the-art methods while maintaining competitive computational efficiency. Indeed, we show in Tables <ref> and <ref> the computational complexity in terms of MACs[1] and FLOPs[1], respectively.  The results are shown for three different resolutions, selected for their common usage and to avoid out-of-memory issues on the utilized GPU. It is clear that our SSMIC significantly reduces the computational complexity in terms of MACs and achieves competitive results in terms of FLOPs compared to SwinT <cit.>. 

Table <ref> presents the average latency over 2,000 images at a resolution of 256 × 256 on the utilized GPU. Our model shows competitive decoding times compared to lightweightLIC <cit.>, while maintaining comparable encoding times.








§ CONCLUSION


In this paper, we  proposed State Space Model-based Image Compression (SSMIC) approach, achieving competitive RD performance while significantly reducing the computational complexity and latency, which is potentially helpful to conduct, with further optimizations, high-quality real-time visual data compression. SSMIC leverages the advantages of State Space Models (SSMs) inherited from the Mamba model, enhancing contextual
reasoning while managing computational and memory requirements.  On average across benchmark datasets, SSMIC achieves a substantial reduction in BD-rate compared to VTM-15.0, underscoring its effectiveness in practical applications. 






















































































































































































Efficient_Image_Compression_Using_Advanced_State_Space_Models





