Image compression method based on Focal Transform
Through Focal Transformer's image compression method, the multi-layer windowed focus self-attention and focus attention mechanism, combined with the channel extrusion entropy model, the problem of high computational complexity in resource-constrained devices is solved, and the efficient image compression effect is achieved, which is suitable for the refined analysis of high-resolution images.
Patent Information
- Application Number
- CN202510606737.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-12
- Publication Date
- 2025-08-12
AI Technical Summary
Existing image compression techniques are difficult to balance image edge clarity, texture details and spectral integrity, resulting in the loss of key details of fine tasks under high compression ratios. Traditional methods have high computational complexity in resource-constrained devices, making it difficult to adapt to the needs of modern refined analysis.
The image compression method based on Focal Transformer is adopted to generate potential representations through the multi-layer windowed focus self-attention module and the focus attention mechanism module. The channel extrusion entropy model based on attention is quantified to achieve the unity of local detail retention and global semantic perception.
In resource-constrained scenarios, the balance between computing efficiency and visual tasks is achieved, which significantly reduces computing and storage overhead, while maintaining image compression quality, which is suitable for efficient compression of high-resolution images.
Smart Images

Figure CN120475151A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of deep learning image compression, and in particular relates to an image compression method based on FocalTransformer. Background Art
[0002] With the rapid development of computer and network communication technologies, services such as real-time visual communications, multimedia communications, IPTV, and video surveillance are gaining increasing attention. Consequently, image compression technology has become an urgent challenge. While traditional general-purpose compression standards can reduce data size, they struggle to preserve key features of the original image, such as edge clarity, texture detail, and spectral integrity, directly impacting the accuracy of AI analysis. The development of specialized image compression technologies can effectively balance data size and feature preservation, reducing transmission costs while ensuring the accuracy of intelligent decision-making, providing technical support for AI-powered image analysis applications.
[0003] Current surveillance systems widely utilize traditional lossy compression techniques. Their encoding process is based on fixed rules for transforms, quantization, and entropy coding, but these techniques present significant limitations in specific applications. JPEG relies on the discrete cosine transform (DCT) to remove high-frequency information. While computationally simple and high-quality at low compression ratios, it is prone to blocking artifacts at high compression ratios, resulting in loss of critical details for fine-grained tasks and inability to process multispectral / hyperspectral data. JPEG2000 utilizes wavelet transforms for multiresolution encoding, supporting lossless compression and region coding, making it suitable for scalable transmission and high-fidelity scenarios. However, its high algorithmic complexity makes it difficult to deploy on resource-constrained edge devices, and it still suffers from artifacts at ultra-high resolutions. BPG, based on the HEVC standard, surpasses the previous two in compression efficiency and detail fidelity (e.g., high dynamic range images). However, its high computational requirements and compatibility issues limit its application in scenarios such as real-time drone data collection. Overall, traditional methods rely on artificial rules and lack adaptive optimization for complex image features (e.g., dense textures and multispectral information). This results in a difficult balance between compression efficiency and visual fidelity, making it difficult to meet the demands of modern, sophisticated analysis. Summary of the Invention
[0004] To solve the above technical problems, the present invention proposes an image compression method based on Focal Transformer to improve the image compression transmission efficiency in the scene.
[0005] To achieve the above object, the present invention provides an image compression method based on Focal Transformer, comprising:
[0006] Obtain an image to be compressed and generate a latent representation through an encoder, wherein the encoder includes a multi-layer windowed focal self-attention module and a focal attention mechanism module;
[0007] Estimate the entropy parameters of the latent representation using an attention-based channel-squeezing entropy model;
[0008] Quantify the latent representation according to an entropy parameter;
[0009] Decode the quantized latent representation to reconstruct the image.
[0010] Optionally, the configuration of the windowed focus self-attention module includes:
[0011] The input feature map is divided into multiple sub-windows, and the query position within each window selects keys and values from multiple focus levels;
[0012] The attention weights of different granularity levels are fused through the relative position deviation matrix to output multi-scale feature representation.
[0013] Optionally, the configuration of the focused attention mechanism module includes:
[0014] After normalizing the input feature map, local window attention calculation, residual connection, and multi-layer perceptron nonlinear transformation are performed in sequence;
[0015] The LayerNorm layer is used to stabilize feature distribution and enhance the synergy between local and global features.
[0016] Optionally, the attention-based channel squeezing entropy model includes:
[0017] The potential representation is sliced according to the channel dimension, and the mean and variance of each slice are predicted in turn through the autoregressive module;
[0018] The channel attention block is used to dynamically adjust the entropy parameter and suppress redundant information.
[0019] Optionally, the configuration of the channel attention block includes:
[0020] Convolution is performed on channel slices to extract local spatial features, and residual connections are used to generate attention weights;
[0021] The entropy parameter is adjusted through Softmax normalization to optimize the channel-level compression efficiency.
[0022] Optionally, the channel attention block also includes hyperparameter settings including: batch size is set to 4, initial learning rate is 0.00001, and optimizer is Adam; quality indicators use MSE and MS-SSIM, λ1 value range is {0.0018, 0.0035,…, 0.05}, λ2 = 0.999.
[0023] Optionally, the loss function for quantizing the latent representation according to the entropy parameter is defined as:
[0024] L = λ1·D + λ2R;
[0025] Where L is the loss function; D is the distortion between the reconstructed image and the original image; λ1 and λ2 are hyperparameters for adjusting the balance between reconstruction loss and compression bit rate; R is the compression bit rate of the attention-based channel squeezing entropy model.
[0026] Technical effect of the invention: The present invention discloses an image compression method based on Focal Transformer, which achieves a balance between computational efficiency and long-range dependency capture through multi-granularity hierarchical aggregation, pooling compression and local-global attention fusion, and is the preferred solution for visual tasks in resource-constrained scenarios. Through the collaborative design of windowing and multi-level focused attention, the unity of local detail preservation and global semantic perception is achieved, and a balance between high precision and high efficiency is achieved at a lower computational cost in tasks such as image compression. Through channel slicing separation, attention-driven local feature extraction and super-prior path compression, efficient entropy modeling and fast decoding are achieved, which significantly reduces computational and storage overhead while maintaining image compression quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings, which constitute part of this application, are intended to provide a further understanding of this application. The exemplary embodiments and descriptions of this application are intended to explain this application and do not constitute an improper limitation on this application. In the accompanying drawings:
[0028] Figure 1 A schematic diagram of a flow chart of an image compression method based on Focal Transformer according to an embodiment of the present invention;
[0029] Figure 2 Schematic diagram of an example of windowed focus self-attention according to an embodiment of the present invention;
[0030] Figure 3 This is a schematic diagram of the attention mechanism module according to an embodiment of the present invention;
[0031] Figure 4 Schematic diagram of an attention-based channel squeezing entropy model according to an embodiment of the present invention;
[0032] Figure 5 Schematic diagram of the CLAB module in the attention-based channel squeezing entropy model according to an embodiment of the present invention;
[0033] Figure 6 The rate-distortion curves of different methods on the Kodak dataset according to an embodiment of the present invention are shown, where (a) is the model using multi-scale structural similarity on the Kodak dataset, and (b) is the model using peak signal-to-noise ratio on the Kodak dataset;
[0034] Figure 7The rate-distortion curves of different methods on the CLIC-PRO dataset according to an embodiment of the present invention are shown, where (a) is the model using multi-scale structural similarity on the CLIC-PRO dataset, and (b) is the model using peak signal-to-noise ratio on the CLIC-PRO dataset;
[0035] Figure 8 It is the feature map of the potential feature y after downsampling in the embodiment of the present invention. DETAILED DESCRIPTION
[0036] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0037] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0038] With breakthroughs in deep learning technology, end-to-end compression models based on variational autoencoders (VAEs) and convolutional neural networks have gradually become mainstream. Early studies significantly improved rate-distortion performance by introducing nonlinear transformations (such as GDN), differentiable quantization techniques (such as UNAQ), and hyper-prior probability models (such as PixelCNN). The introduction of attention mechanisms (such as non-local modules and SwinTransformer) further optimized bit allocation, allowing the algorithm to focus more on key areas such as textures and edges. Asymmetric convolution enhances model flexibility through differentiated feature extraction, and combined with dense modules or graph attention mechanisms, it strikes a balance between compression efficiency and detail preservation. In response to the particularity of scenes, existing studies have proposed solutions such as parallel compression of video slices and joint compression-classification models, which reduce transmission and storage costs and improve disease detection accuracy.
[0039] However, existing deep learning models still face multiple challenges and have the following technical bottlenecks: CNN model limitations: Although traditional compression methods based on convolutional neural networks (CNNs) are good at capturing local spatial features, they lack the ability to model global context, resulting in limited reconstruction quality of complex textures (such as crop leaf veins); Transformer direct application defects: Redundant calculation problem: Large-size image blocks (such as 16×16 patches) lead to internal spatial redundancy, reducing compression efficiency; Normalization incompatibility: There is an optimization conflict between the generalized normalization transform (GDN) and the Transformer attention mechanism, and the model training stability is poor; Computational complexity is out of control: The computational complexity of the global self-attention mechanism is quadratic with the image resolution, making it difficult to adapt to high-resolution images (such as drone aerial photos); Insufficient adaptability of activation functions: The traditional ReLU function has insufficient nonlinear expression capabilities in complex feature distribution scenarios, affecting the reconstruction accuracy of high dynamic range images.
[0040] like Figure 1 As shown, this embodiment provides an image compression method based on Focal Transformer, including:
[0041] Obtain an image to be compressed and generate a latent representation through an encoder, wherein the encoder includes a multi-layer windowed focal self-attention module and a focal attention mechanism module;
[0042] Estimate the entropy parameters of the latent representation using an attention-based channel-squeezing entropy model;
[0043] Quantify the latent representation according to an entropy parameter;
[0044] Decode the quantized latent representation to reconstruct the image.
[0045] Furthermore, the configuration of the windowed focus self-attention module includes:
[0046] The input feature map is divided into multiple sub-windows, and the query position within each window selects keys and values from multiple focus levels;
[0047] The attention weights of different granularity levels are fused through the relative position deviation matrix to output multi-scale feature representation.
[0048] Furthermore, the configuration of the focus attention mechanism module includes:
[0049] After normalizing the input feature map, local window attention calculation, residual connection, and multi-layer perceptron nonlinear transformation are performed in sequence;
[0050] The LayerNorm layer is used to stabilize feature distribution and enhance the synergy between local and global features.
[0051] Furthermore, the attention-based channel squeezing entropy model includes:
[0052] The potential representation is sliced according to the channel dimension, and the mean and variance of each slice are predicted in turn through the autoregressive module;
[0053] The channel attention block is used to dynamically adjust the entropy parameter and suppress redundant information.
[0054] Furthermore, the configuration of the channel attention block includes:
[0055] Convolution is performed on channel slices to extract local spatial features, and residual connections are used to generate attention weights;
[0056] The entropy parameter is adjusted through Softmax normalization to optimize the channel-level compression efficiency.
[0057] Furthermore, the channel attention block also includes hyperparameter settings including: batch size is set to 4, initial learning rate is 0.00001, and optimizer adopts Adam; quality indicators adopt MSE and MS-SSIM, λ1 value range is {0.0018, 0.0035,…, 0.05}, λ2 = 0.999.
[0058] Furthermore, the loss function in the process of quantizing the potential representation according to the entropy parameter is defined as:
[0059] L = λ1·D + λ2R;
[0060] Where L is the loss function; D is the distortion between the reconstructed image and the original image; λ1 and λ2 are hyperparameters for adjusting the balance between reconstruction loss and compression bit rate; R is the compression bit rate of the attention-based channel squeezing entropy model.
[0061] Specifically, the implementation process of an embodiment of the present invention includes:
[0062] receiving an input image;
[0063] Encode the input image using an encoder consisting of a multi-layer windowed focal self-attention module and a focal attention mechanism module to generate a latent representation;
[0064] Estimate the entropy parameters of the latent representation using an attention-based channel-squeezing entropy model;
[0065] quantize the latent representation according to the estimated entropy parameter;
[0066] Decode the quantized latent representation to reconstruct the image.
[0067] The windowed focused self-attention module is configured to: partition the input feature map into multiple sub-windows of size pxp; for each query position within a sub-window, select keys and values from multiple granularity levels surrounding the sub-window, where the key and value selection operation includes: for each granularity level, pooling the feature map to a coarser resolution of the corresponding level and selecting keys and values from the pooled feature map; computing attention using the selected keys and values, including adding a relative position bias for each focus level; and outputting an attention representation of the input feature map. In this way, the focused self-attention mechanism can capture global information with less computation and memory consumption while maintaining high efficiency.
[0068] The focused attention mechanism module is configured to: receive an input feature map; apply a normalization layer to the input feature map; process the normalized feature map using a window attention component to capture local features; process the output of the window attention component using a focused self-attention component to capture global information across multiple levels of granularity; append the output of the focused self-attention component to the input feature map via a residual connection; perform a nonlinear transformation on the result using a multi-layer perceptron; and output the transformed feature map. The core idea of this module is to gradually expand the scope of attention from local regions to global feature capture through a multi-level focusing mechanism, thereby optimizing compression efficiency and image quality in high-resolution compression tasks.
[0069] The attention-based channel-squeezing entropy model is configured as follows: receiving a latent representation from the encoder; dividing the latent representation into multiple channel slices in a predefined order; estimating the mean and variance of each channel slice using an autoregressive module, where the autoregressive module predicts the parameters of the current slice using the previous channel slice in the order; processing the channel slice using a channel attention block (CLAB) and adjusting the entropy parameters; and outputting the entropy parameters for decoding. This module significantly optimizes computational efficiency and model complexity while maintaining image compression performance by enhancing local modeling through an attention mechanism, reducing redundancy through channel compression, and improving parallelism through a divide-and-conquer strategy. Its core innovation lies in dynamically balancing the advantages of the super-prior and autoregressive models, and achieving a dual breakthrough in detail preservation and parameter reduction through the CLAB module. The channel attention block (CLAB) is configured as follows: receiving channel slices; processing each channel slice using a convolutional layer to capture local spatial features; calculating an attention weight for each channel slice based on the local features; and adjusting the entropy parameters of each channel slice using the attention weights. This module captures local information, enabling the entropy model to better grasp specific image details.
[0070] The overall compression and decompression structure process is as follows Figure 1 As shown, the compression step includes:
[0071] Divide the input image into patches of size N;
[0072] By applying a linear embedding layer to each patch, we get a feature map with C channels This process can effectively reduce spatial redundancy and provide efficient feature representation for subsequent processing;
[0073] Feature map f p Will be reshaped into a sequence f p ∈R 2C×P , where P = H × 2 / N 2 Indicates the number of patches;
[0074] The input is fed into an image compression encoder consisting of a multi-layer Fsformer module and a patch merging layer for downsampling, quantization, and entropy encoding to obtain latent representation and super latent representation.
[0075] The decompression steps include:
[0076] The latent representation is fed into a decoder network consisting of multiple Fsformer modules and a patch split layer (PatchSplit) to obtain an upsampled feature map. The patch split layer restores the spatial resolution of the feature map through upsampling and reduces the feature dimension by reducing the number of channels.
[0077] The feature map is fed into the De-Embedding layer to map it back to the spatial size of the original image and generate the final reconstructed image.
[0078] The windowed focal self-attention steps include:
[0079] The input feature map (x∈R M×N×d , where M and N are spatial dimensions and d is the feature dimension) is divided into A grid of subwindows, with tokens within each window sharing the same environment.
[0080] For the query position in each window, multiple tokens (keys and values) at different levels around it are extracted instead of focusing on just one token. For a query Q within the query window, we select from the key and value sets at multiple focus levels around the query window. Specifically, the key K at level l is i Sum V i It is given by the following formula:
[0081] K i ={K1,K2......K L}and V i ={V1,V2......V L};
[0082] Where L is the number of focus levels, and the size of the keys and values at each level in is the size of the focus area, which represents the scope of the window's surroundings.
[0083] Next, the core operation of calculating focal self-attention is as follows:
[0084]
[0085] Where B is the learnable relative position bias, which consists of a subset of L focus levels. The relative position bias B of each level l It can be expressed as the relative position relationship between the query and the environment token within the window: For level 1, On this basis, all focus levels are calculated and the final focus self-attention representation is obtained.
[0086] A specific implementation example of windowed focus self-attention is as follows Figure 2 As shown in the figure, a 20×20 input feature map is first partitioned into 5×5 windows, each of 4×4 size. In this process, the central 4×4 green window is used as the query, and tokens in the surrounding area are extracted. Specifically, the focused self-attention mechanism extracts surrounding tokens from the feature map as keys and values at different levels of granularity. At the first level, the 8×8 tokens closest to the green window are extracted and processed at the finest granularity. Next, at the second level, the attention area is expanded, pooling the surrounding 2×2 subwindows to generate 6×6 pooled tokens. At the third level, the attention range is further expanded to cover the entire feature map, and 4×4 subwindows are pooled. The tokens from these three levels are concatenated together to ultimately compute the corresponding keys and values for the 16 tokens (query) in the blue window. In this way, the focused self-attention mechanism captures global information with reduced computation and memory consumption while maintaining high efficiency.
[0087] like Figure 3 The following steps are shown in the focused attention mechanism module:
[0088] The input feature map (denoted as x in ) undergoes normalization (e.g., LayerNorm) to stabilize model training and normalize feature distribution. Subsequently, the feature map is padded according to a predefined window size to ensure that the feature map size is evenly divisible by the window size, facilitating subsequent local window operations.
[0089] The preprocessed feature map is then self-attentioned in the local window using WindowAttention (or FSA in the figure, which may be FocusedSelf-Attention or a similar self-attention mechanism). In this step, the model focuses on the feature information in the local area, capturing local dependencies in space or sequence, thereby enhancing the understanding of local patterns.
[0090] To avoid the vanishing gradient problem and preserve the input feature information, a residual connection is used. The features processed by WindowAttention are added to the original input features (or their variants) to generate more stable output features. This process is illustrated by the green circle (representing the addition operation) in the figure.
[0091] The fused features are then normalized again (LayerNorm, LN) to further stabilize the feature distribution. They are then passed to a multi-layer perceptron (MLP, a feedforward network) that uses nonlinear transformations (such as activation functions like ReLU or GELU) to enhance the model’s expressive power and extract more complex feature patterns.
[0092] The features processed by MLP are used as the output of the module (denoted as x out ) for processing in subsequent layers or modules. This step retains rich information of local and global features, providing support for subsequent tasks (such as classification, detection, etc.).
[0093] like Figure 4 The following are the steps of the attention-based channel squeezing entropy model:
[0094] The potential representation y is fed into the entropy prior module to estimate the image entropy;
[0095] The potential representation y is separated at the channel level, that is, the potential image is divided into i roughly equal slices along the channel dimension, and the mean and variance of each slice are estimated separately through the autoregressive module. In addition, the mean and variance of the previous layer prediction need to be considered.
[0096] The various parts of the autoregressive code stream are integrated through the network and input into the decoder for decoding. The decoding process is obtained as follows: in represents the discrete representation of the latent feature y, g s is the decoder, and θ represents the optimization parameter. In addition, to improve the parallelization capability of the framework, the entropy parameter of each slice is adjusted on the previously decoded slices (using the CLAB module).
[0097] like Figure 5 The CLAB module steps shown include:
[0098] Receive channel slices;
[0099] Each channel slice is processed using convolutional layers and residual connections to capture local spatial features;
[0100] Calculate attention weights for each channel slice based on local features;
[0101] The entropy parameter of each channel slice is adjusted using the attention weight.
[0102] The hyperparameter setting steps include:
[0103] For training, we randomly selected 300K images from the OpenImages dataset and randomly cropped the images to 256×256 during training.
[0104] In all model training, the batch size is set to 4, the initial learning rate is set to 0.00001, and the Adam optimiser is used to optimize the network.
[0105] Two quality metrics (MSE and MS-SSIM) were used for supervision during optimization. When the model was optimized using MSE, the λ1 values fell into the range {0.0018, 0.0035, 0.0067, 0.0130, 0.025, 0.05}, and the λ2 value was set to 0.999. When optimized using MS-SSIM, the λ1 values fell into the range {3, 5, 8, 16, 32, 60}, and the λ2 value was set to 0.999.
[0106] For the Fsformer module in the main codec of the model, set the values of num_heads in the Fsformer module to [3, 6, 12, 24], the values of focal_windows to [7, 5, 3, 1], window_size to 7, and patch_size to 2.
[0107] For the CLAB module, the num_heads of the main path is set to 8 and the kernel_size is set to 7. The number of channels M of the latent feature y is set to 320, and the number of channels M of z is set to 192.
[0108] The distortion of the source image and the reconstructed image, constructing the loss function for end-to-end overall optimization function:
[0109] L = λ1·D + λ2R;
[0110] Where L contains two terms, where D represents the distortion between the reconstructed image and the original image, and D is defined as:
[0111]
[0112] Where C, W, and H represent the channel, height, and width of the image, respectively.
[0113] R represents the compression bitrate of the whole framework, and the coefficients λ1 and λ2 represent the hyperparameters that adjust the balance between reconstruction loss and compression bitrate. The bitrate is given by and The bit stream composition can be defined as:
[0114]
[0115] in,
[0116]
[0117]
[0118] Where, and They are and The probability density model of .
[0119] The rate-distortion performance of Focal Transformer-based image compression methods, traditional image compression methods, and other deep learning-based compression methods were verified on different datasets. Figure 6 (a) and Figure 6 (b) shows the performance of the model using multi-scale structural similarity (MS-SSIM) and peak signal-to-noise ratio (PSNR) on the Kodak dataset to measure these performances. Figure 7 (a) and Figure 7 (b) shows the performance of the model of the present invention on the CLICPRO dataset using multi-scale structural similarity (MS-SSIM) and peak signal-to-noise ratio (PSNR) to measure these performances. In order to facilitate comparison with other methods, the present invention converts MS-SSIM to -10log 10 (1-(MS-SSIM)) for a clearer comparison.
[0120] The rate-distortion characteristics of the image compression method based on deep learning are slightly higher than those of the traditional image compression method. At the same time, the method proposed in the present invention, the multi-way residual asymmetric convolutional compression network (MRACNN), outperforms all other methods, including image compression methods based on deep learning and traditional classical image compression methods. In addition, the method of the present invention achieves state-of-the-art compression performance in terms of PSNR and MS-SSIM indicators, which verifies the effectiveness of the method proposed in the present invention. The asymmetric convolution feature module based on multi-way residuals can better extract important feature information in the image, while the dual-branch enhanced local attention mechanism pays more attention to high-contrast areas, thereby allocating more bits to them. At the same time, the comparison results on the CLIC professional verification dataset also show the robustness of the model of the present invention, which can still maintain excellent performance even in complex scenes.
[0121] like Figure 8 The figure shows the average feature maps of the latent features at time y after downsampling animal photos by different models. It can be clearly seen that the model of the present invention concentrates the energy of the feature map more on the animal region. This key information includes important details and characteristic regions related to the animal's feathers, beak, eyes, etc. These details are crucial for capturing the animal's appearance characteristics and subsequent image reconstruction. This effect is attributed to the Focal Self-Attention module, which effectively focuses on regions with important details and structure through a combination of local and global attention during the encoder's downsampling operation.
[0122] The Focal Self-Attention module allocates more computing resources to key image regions through detailed feature capture within a local window and a progressively larger global receptive field, while performing less processing on less important areas. Compared to the traditional uniform attention mechanism, this approach can more efficiently capture directional and spatial relationship features in images, and also demonstrates strong feature extraction capabilities, especially in scenes. For example, in an image, the model can automatically focus on areas such as leaves, fruits, and flowers of crops, as well as key structural features of farmland. This focused feature enables the model to efficiently extract important production-related information, providing more accurate feature representations for compression.
[0123] Furthermore, the Focal Self-Attention module, implemented in the encoder, ensures detail preservation in key local areas through layer-by-layer self-attention calculation and feature aggregation, while gradually expanding global feature perception and reducing redundant information in non-critical areas. This feature not only improves the model's compression performance at low bitrates but also enables better reconstruction of texture and detail in key areas during the decoding phase. For animal photos, this means the model can more clearly reproduce feather texture, eye luster, and beak details. For images, this mechanism ensures the preservation of crop morphology, texture, and key growth information, supporting refined production.
[0124] Contribution of CLAB to Focal Transformer-based image compression methods: In order to prove that the CLAB module proposed in this paper can bring significant gains in image compression and improve RD performance, this paper conducted an ablation experiment on the Kodak dataset. The experimental results are shown in Table 1.
[0125] Table 1
[0126]
[0127] w / FSB and w / oCLAB indicate that only the focused attention module in the codec is used for upsampling and downsampling. For a fairer comparison, w / oFSB and w / oCLAB indicate that the Transformer Block module is used for upsampling and downsampling. w / FSB and W / CLAB indicate that both the FSB and CLAB modules are used.
[0128] As can be seen from Table 1, the CLAB module of the present invention can achieve more RD improvement. Compared with the previous method, the PSNR evaluation is improved by about 0.15dB. At the same time, the FSB module also has a certain improvement compared with the previous method. It is worth mentioning that according to the time analysis of different codecs in the table below, the time cost of our STF method is still at the same order of magnitude. This shows that the FSB module and CLAB module proposed in the present invention can indeed effectively improve the model performance while maintaining a low time cost. The introduction of these modules has brought new ideas and methods to the field of image compression, and is expected to be more widely used in the future.
[0129] The present invention tests the running time of the proposed method on the CPU and compares it with the execution time of traditional image compression methods such as VTM, AV1, WebP, BPG, JPEG and JPEG2000. Then, the present invention demonstrates the running time of the method in the present invention on the GPU and compares it with other deep learning-based image compression methods. The time comparison of different methods on the CPU is shown in Table 2. EncT and DecT represent the time cost of encoding and decoding on Kodak. It reveals that due to the high complexity of the CNN model, the method of the present invention runs slower on the CPU compared with some traditional codecs. However, its performance is better than VCC, AV1 and JPEG2000.
[0130] Table 2
[0131] Method EncT DecT MRACNN 1.18s 0.21s FTF 1.21 0.23 Vtm 129.21s 0.14s Av1 22.24s 0.037s Webp 0.059s 0.007s Bpg 0.66s 0.17s Jpeg 0.012s 0.006s Jpeg2000 0.50s 0.48s
[0132] With the support of GPU, the two models proposed in the present invention achieve faster encoding and decoding speeds, as shown in Table 3 compared with several learning-based image compression models. Although slightly behind SwinTChARM in encoding and decoding speed, the method of the present invention is still superior to other image compression methods based on deep learning, and the performance is improved. In addition, the method of the present invention also has excellent scalability and flexibility, and is therefore suitable for large-scale image compression scenarios. Although the encoding time of most image compression methods based on deep learning is shorter than that of traditional algorithms under GPU acceleration, the strict sequentiality of the decoder causes the decoding time to be much longer than that of traditional algorithms.
[0133] Table 3
[0134]
[0135]
[0136] This paper proposes a Focal Transformer-based image compression method to address the trade-off between high resolution and high compression rate faced by traditional image compression methods. The Transformer architecture, with its global modeling capabilities and flexible feature extraction mechanism, has shown significant potential in image compression tasks. However, direct application of the Transformer faces challenges such as spatial redundancy, normalization instability, and high computational complexity. To address these challenges, this study effectively improves the expressiveness and efficiency of the Transformer in high-resolution scenarios by introducing small patch partitioning, layer normalization (LN), the GELU activation function, and a focal self-attention mechanism. The overall architecture consists of an encoder and a decoder. In the encoder, the input image is partitioned into fine-grained patches and processed by a linear embedding layer and a Focal Transformer module to extract rich local and global features. Simultaneously, downsampling is achieved through a patch merging layer, reducing computational complexity while preserving key features. In the decoder, patch segmentation and de-embedding layers gradually restore image resolution and detail. The attention mechanism of the Focal Transformer module dynamically adjusts feature weights to ensure image reconstruction quality. Furthermore, focused attention captures a wider range of contextual information at different granularity levels, effectively balancing computational efficiency and image reconstruction quality to meet the needs of image compression. Overall, the Focal Transformer-based image compression method fully leverages the Transformer's global modeling capabilities and optimizes computational efficiency and model expressiveness through the focused attention mechanism. This method significantly improves image reconstruction quality in high-resolution scenarios while increasing compression ratios, providing new research directions for image compression.
[0137] The above are merely preferred embodiments of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. An image compression method based on Focal Transformer, characterized in that: include: Obtain an image to be compressed and generate a latent representation through an encoder, wherein the encoder includes a multi-layer windowed focal self-attention module and a focal attention mechanism module; Estimate the entropy parameters of the latent representation using an attention-based channel-squeezing entropy model; Quantify the latent representation according to an entropy parameter; Decode the quantized latent representation to reconstruct the image.
2. The image compression method based on Focal Transformer according to claim 1, wherein: The configuration of the windowed focus self-attention module includes: The input feature map is divided into multiple sub-windows, and the query position within each window selects keys and values from multiple focus levels; The attention weights of different granularity levels are fused through the relative position deviation matrix to output multi-scale feature representation.
3. The image compression method based on Focal Transformer according to claim 1, wherein: The configuration of the focused attention mechanism module includes: After normalizing the input feature map, local window attention calculation, residual connection, and multi-layer perceptron nonlinear transformation are performed in sequence; The LayerNorm layer is used to stabilize feature distribution and enhance the synergy between local and global features.
4. The image compression method based on Focal Transformer according to claim 1, wherein: The attention-based channel squeezing entropy model includes: The potential representation is sliced according to the channel dimension, and the mean and variance of each slice are predicted in turn through the autoregressive module; The channel attention block is used to dynamically adjust the entropy parameter and suppress redundant information.
5. The image compression method based on Focal Transformer according to claim 4, characterized in that: The configuration of the channel attention block includes: Convolution is performed on channel slices to extract local spatial features, and residual connections are used to generate attention weights; The entropy parameter is adjusted through Softmax normalization to optimize the channel-level compression efficiency.
6. The image compression method based on FocalTransformer according to claim 4, characterized in that: The channel attention block also includes hyperparameter settings including: The batch size is set to 4, the initial learning rate is 0.00001, and the optimizer is Adam; The quality indicators used are MSE and MS-SSIM, the value range of λ1 is {0.0018, 0.0035,…, 0.05}, and λ2 = 0.
999.
7. The image compression method based on FocalTransformer according to claim 1, characterized in that: The loss function in the process of quantizing the potential representation according to the entropy parameter is defined as: L = λ1·D + λ2R; Where L is the loss function; D is the distortion between the reconstructed image and the original image; λ1 and λ2 are hyperparameters for adjusting the balance between reconstruction loss and compression bit rate; R is the compression bit rate of the attention-based channel squeezing entropy model.