ViT-based image coding method and system fused with high-value local information

By extracting global information in image compression and using the self-attention mechanism to fuse local information, it solves the problem of local information loss when ViT processes images, achieves higher-quality image coding, and reduces computational burden and information loss.

CN118741126AActive Publication Date: 2024-10-01SHANDONG UNIV
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410986842.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2024-05-16
Filing Date
2024-07-23
Publication Date
2024-10-01
Estimated Expiration
2044-07-23

AI Technical Summary

Technical Problem

When using Vision transformer (ViT) to process images, local information inside the divided window is easily lost, and it is difficult for existing technologies to effectively fuse high-value local information to compensate for this defect.

Method used

By first extracting global information, using global information to guide the extraction of local information, and using a self-attention mechanism to fuse global information and local information, high-value image coding is generated. Specific steps include obtaining the global features of the image to be compressed, extracting local information based on the features within the window, and generating weight parameters through the self-attention mechanism for information fusion.

Benefits of technology

It effectively reduces the computational burden, ensures that the extracted local information is more relevant, reduces the information loss during the image compression process, and improves the comprehensiveness of the compression results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118741126A_ABST
    Figure CN118741126A_ABST
Patent Text Reader

Abstract

The invention provides a ViT-based image coding method and system fused with high-value local information, and the method comprises the following steps: obtaining a to-be-compressed image, carrying out the global feature extraction of the to-be-compressed image based on window division, and obtaining the information between windows; obtaining global information based on the information between the windows; performing feature extraction in a window based on the global information to obtain local information; and based on a self-attention mechanism, fusing the global information and the local information to obtain fused information, and completing ViT-based image coding fused with the high-value local information. Based on the technical scheme of the invention, a low-calculation, low-bit-rate and low-loss graph compression technology can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of processing image data by self-attention mechanism, and specifically relates to an image encoding method and system based on ViT that integrates high-value local information. Background Art

[0002] Image compression refers to the technology of representing the original pixel matrix with fewer bits losslessly or losslessly to reduce the amount of data required to represent the digital image, also known as image coding.

[0003] Generally speaking, when using the self-attention mechanism to process images, ViT (Vision transformer) is an effective method worth relying on. The image is divided into 16×16 windows, and each window is projected into a vector of fixed length and sent to the transformer. This reduces the length of the input queue and the complexity of the algorithm. Since ViT uses the entire divided window as input, the local information inside the window will be lost. When using ViT to extract image features, the self-attention mechanism between some windows will be added to compensate for the lost local information. Summary of the invention

[0004] In view of the shortcomings of the prior art, the present invention discloses an image encoding method and system based on ViT that integrates high-value local information. Global information is first generated, and the global information provides guidance for selecting local information for extraction, so that the selected patch blocks are more relevant and the extracted local information inside the window is more valuable.

[0005] To achieve the above object, the present invention provides the following solutions:

[0006] The image encoding method based on ViT and integrating high-value local information includes the following steps:

[0007] Acquire an image to be compressed, and perform global feature extraction based on window division on the image to be compressed to obtain information between windows; obtain global information based on the information between windows;

[0008] Based on the global information, feature extraction is performed within the window to obtain local information;

[0009] Based on the self-attention mechanism, the global information is fused with the local information to obtain fused information, thereby completing the image encoding based on ViT that fuses high-value local information.

[0010] Preferably, the image to be compressed is evenly divided into a number of non-overlapping windows, and a class token of a patch size is added to each window;

[0011] Based on the self-attention mechanism, feature extraction is performed inside the window with the class token added to obtain the class token representing the features of the current window;

[0012] Based on the self-attention mechanism, feature extraction is performed on all class tokens representing the features of the current window to obtain the global information.

[0013] Preferably, based on the global information, a correlation matrix of window-window affinities is obtained;

[0014] Based on the correlation matrix, a window that satisfies a preset correlation with each window is selected to obtain a retrieval matrix;

[0015] Based on the retrieval matrix, the self-attention mechanism is used to extract features within the window to obtain the local information.

[0016] Preferably, the method for fusing the global information with the local information is:

[0017] Based on the global information, obtaining a query matrix;

[0018] Based on the local information, obtaining a key matrix;

[0019] Perform a self-attention mechanism on the query matrix and the key matrix to obtain a weight parameter matrix;

[0020] The weight parameter matrix is ​​multiplied by the global information, and the multiplication result is added to the local information to obtain the fusion information.

[0021] The present invention also provides an image coding system based on ViT and integrating high-value local information, which is used to implement the method described, including:

[0022] A global information acquisition module is used to acquire an image to be compressed, and perform global feature extraction based on window division on the image to be compressed to obtain information between windows; based on the information between windows, obtain global information;

[0023] A local information acquisition module, used to extract features within the window based on the global information to obtain local information;

[0024] The information fusion module is used to fuse the global information with the local information based on the self-attention mechanism to obtain fused information and complete the image encoding based on ViT that fuses the high-value local information.

[0025] Preferably, the global information acquisition module includes:

[0026] A division unit, used for dividing the image to be compressed into a plurality of non-overlapping windows on average, and adding a class token of a patch size in each window;

[0027] The first feature extraction unit is used to extract features from the window with the class token added based on the self-attention mechanism to obtain the class token representing the features of the current window;

[0028] The second feature extraction unit is used to extract features of all class tokens representing the features of the current window based on a self-attention mechanism to obtain the global information.

[0029] Preferably, the local information acquisition module includes:

[0030] A correlation matrix acquisition unit, used for obtaining a correlation matrix of window-window affinities based on the global information;

[0031] A retrieval matrix acquisition unit, configured to select a window that satisfies a preset correlation with each window based on the correlation matrix to obtain a retrieval matrix;

[0032] The local information acquisition unit is used to extract features within the window based on the retrieval matrix using a self-attention mechanism to obtain the local information.

[0033] Preferably, the information fusion module includes:

[0034] A query matrix acquisition unit, used to obtain a query matrix based on the global information;

[0035] A key matrix acquisition unit, used for obtaining a key matrix based on the local information;

[0036] A weight parameter matrix acquisition unit, used for performing a self-attention mechanism on the query matrix and the key matrix to obtain a weight parameter matrix;

[0037] An information fusion unit is used to multiply the weight parameter matrix with the global information, and add the multiplication result with the local information to obtain the fused information.

[0038] Compared with the prior art, the beneficial effects of the present invention are as follows: the global information extraction step disclosed in the present invention can use only the class token of the number of divided windows as the input of the self-attention mechanism, which can obtain the information of the entire image and reduce the input involved in the calculation. The local feature extraction step selectively extracts the information of the internal patch between windows under the guidance of the window correlation matrix, which reduces the calculation and ensures that the extracted local information comes from more relevant windows. The feature information fusion step fuses the global information with the local information, so that the final result contains the overall information and the local information properly fused at the same latitude, so that the final compression result saves more comprehensive information, and the loss of graphic information can be effectively reduced. At the same time, since the local information between all windows is not calculated, the calculation burden will also be reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the technical solution of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0040] Figure 1 This is a flow chart of an image encoding method integrating high-value local information based on ViT according to an embodiment of the present invention;

[0041] Figure 2 This is a flow chart of global information extraction according to an embodiment of the present invention;

[0042] Figure 3 This is a flow chart of local information extraction according to an embodiment of the present invention;

[0043] Figure 4 This is a flow chart of information fusion according to an embodiment of the present invention. DETAILED DESCRIPTION

[0044] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0045] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0046] Embodiment 1

[0047] like Figure 1As shown, the image encoding method based on ViT that integrates high-value local information includes the following steps:

[0048] like Figure 2 As shown, S1: obtain the image to be compressed, and perform global feature extraction based on window division on the image to be compressed to obtain information between windows; based on the information between windows, obtain global information;

[0049] Figure 2 In the above, Partition: window division; embedding: converting images into vectors; MSA: self-attention mechanism; N 2 : The number of partition windows; N 1 : The number of patches divided within the window

[0050] A further implementation method is to divide the image to be compressed into a number of non-overlapping windows evenly, and add a class token of the patch size in each window;

[0051] Based on the self-attention mechanism, feature extraction is performed inside the window with the class token added to obtain the class token representing the features of the current window;

[0052] Based on the self-attention mechanism, feature extraction is performed on all class tokens representing the features of the current window to obtain global information.

[0053] In this embodiment, if Figure 2 As shown in the figure, for the first-level image division, a 256*256 image is divided into 16 64*64 areas, and each 64*64 area is called a window; for the second-level image division, that is, for the window division, a 64*64 window is divided into 16 16*16 areas, and each 16*16 area is called a patch. The principle of class token is to add an element of the same size as the sequence element to the head of the input sequence of the self-attention mechanism, called Class_token. The content is random. After the self-attention mechanism acts on the input content, its content changes, which can represent the characteristics of the input content and represent the content to perform downstream classification tasks.

[0054] The image is evenly divided into multiple non-overlapping windows, and a class token of the size of a patch is added to each window. For each individual window, the self-attention mechanism is performed only within itself. When performing the self-attention mechanism within the window, the input unit is the patch that is further evenly divided for the window. The size of the added class token is consistent with the size of the divided patch, the content is randomly initialized, and the position is the first in the input queue. The class token output by each window represents the characteristics of the current window. The self-attention mechanism is used again in all class tokens. The input unit is the class token, and the number is the number of divided windows. Finally, each class token contains the information of other windows, realizing the generation of global information.

[0055] S2: Based on the global information, extract features within the window to obtain local information;

[0056] A further implementation method is to obtain a correlation matrix of window-to-window affinities based on global information;

[0057] Based on the correlation matrix, a window that satisfies a preset correlation with each window is selected to obtain a retrieval matrix;

[0058] In this embodiment, if Figure 3 As shown. The class token inserted in each window in the previous step replaces the global information of the window feature. When the class token is generated, the dimension is consistent with the feature vector in the window, that is, C is a feature vector of the size of a patch representing the class token. When performing a global self-attention mechanism, the Q, K, and V tensors are obtained by linear mapping C. W is the matrix of the self-attention mechanism. When using the self-attention mechanism, three parameter matrices will be generated. These three matrices will continue to change during training. The process of training the model is actually to continuously correct these three matrices.

[0059] Q=C r W q (1)

[0060] K=C r W k (2)

[0061] V=C r W v (3)

[0062] Afterwards, through Q r and transpose K r The matrix multiplication between them derives the adjacency matrix (correlation matrix) of the window-window affinity.

[0063] A r =Q r (K r ) T (4)

[0064] Adjacency Matrix A r The entries in measure the semantic relevance of two regions. The next core step is to retain only the top k most closely related regions for each region. That is, use a routing index matrix (retrieval matrix) With row-by-row topk operator.

[0065] I r =topkIndex(A r ) (5)

[0066] Line i r Contains the indexes of the k most relevant windows of the i-th window. Each window only performs self-attention between its own k most relevant windows to achieve the generation of local information. The scope of action is multiple windows, and the input sequence size is patch.

[0067] Based on the retrieval matrix, the self-attention mechanism is used to extract features within the window to obtain local information.

[0068] S3: Based on the self-attention mechanism, the global information is fused with the local information to obtain the fused information, and the image encoding based on ViT that integrates the high-value local information is completed.

[0069] A further implementation method is that the method of fusing global information with local information is:

[0070] Based on the global information, obtain the query matrix;

[0071] Based on the local information, a key matrix is ​​obtained;

[0072] Perform self-attention mechanism on query matrix and key matrix to obtain weight parameter matrix;

[0073] The weight parameter matrix is ​​multiplied by the global information, and the multiplication result is added to the local information to obtain the fused information.

[0074] In this embodiment, after completing the first two tasks, the global information S can be obtained. u The classtoken of each patch includes more valuable local information M obtained selectively. Global information S u It is generated by the attention mechanism between window features S.

[0075]

[0076] q, k, and v represent tensors, and d is a scaling factor. Its purpose is to make the gradient descent more stable during the softmax process and avoid stagnation of model parameter updates due to too small gradients.

[0077] Local information M is the sum of global information S u Under the guidance of , the attention mechanism is performed between the TopK related windows selected in the adjacency matrix.

[0078] V i =V[TopK(S u )] (7)

[0079] M=Attn[V i ]V i (8)

[0080] Next, we need to convert the global information S u Fusion with local information M, because global information is obtained from window features, and local information is obtained from the self-attention mechanism of the patch in the window, so the two kinds of information are not in the same order of magnitude. They cannot be added directly. In processing the fusion of the two kinds of information, this study uses the self-attention mechanism to find the relationship weight parameter between the window feature and the specific patch in the window, so that the order of magnitude of the product of the global information and the relationship weight parameter is the same as the order of magnitude of the local information. Figure 4 As shown, the specific implementation is to first make the global information S u Multiply by matrix W 1 Get the query matrix Q S , local information M multiplied by matrix W 2 Get the key matrix K M , based on the obtained Q S , K M Perform a self-attention mechanism to obtain the relationship parameter matrix (weight parameter matrix) λ of the window to all the patch blocks in the window. u Multiply by λ and add to the local information M to get the final fusion result. Here W 1 and W 2 This is W in formula (2). k , do not repeat W k The reason is that the method is the same each time, but the content of the matrix W obtained after each training is different.

[0081]

[0082] Result=M+λS u (10)

[0083] In the global information extraction step, class token is used instead of window to extract global information. In the local feature extraction step, the window correlation matrix is ​​generated through the global feature information. Under the guidance of the correlation matrix, the information of the internal patch between windows is selectively extracted. In the feature information fusion step, weight parameters are generated through the self-attention mechanism, so that the global information can be fused with the local information at the same level through the weight parameters.

[0084] The principle and method of the self-attention mechanism used in the present invention are the same, but the input sequence is different. The present invention uses a total of four self-attention mechanisms, namely:

[0085] 1. Extract the class token; the input sequence is a small patch within each window (not across windows), and the class token is added to the head;

[0086] 2. Get global information; the input sequence is the class token produced for each window

[0087] 3. Obtain local information; the input sequence is a patch within the window (can be across windows), but under the guidance of the retrieval matrix, it is not done between all patches.

[0088] 4. Get the weight parameter of the conversion level; the input is two sequences, one is the global feature and the other is the local feature, but for the intermediate state, only the Q provided by the global feature is used S , and K provided by local features M Fusion to get the weight parameters.

[0089] Embodiment 2

[0090] The present invention also provides an image coding system based on ViT that integrates high-value local information, which is used to implement an image compression method, including

[0091] The global information acquisition module is used to acquire the image to be compressed, and perform global feature extraction based on window division on the image to be compressed to obtain information between windows; based on the information between windows, obtain global information;

[0092] The local information acquisition module is used to extract features within the window based on the global information to obtain local information;

[0093] The information fusion module is used to fuse global information with local information based on the self-attention mechanism, obtain fused information, and complete image encoding based on ViT that fuses high-value local information.

[0094] A further implementation method is that the global information acquisition module includes:

[0095] A division unit is used to divide the image to be compressed into several non-overlapping windows on average and add a class token of the patch size to each window;

[0096] The first feature extraction unit is used to extract features from the window with the class token added based on the self-attention mechanism to obtain the class token representing the features of the current window;

[0097] The second feature extraction unit is used to extract features of all class tokens representing the features of the current window based on the self-attention mechanism to obtain global information.

[0098] A further implementation method is that the local information acquisition module includes:

[0099] A correlation matrix acquisition unit, used for obtaining a correlation matrix of window-window affinities based on global information;

[0100] A retrieval matrix acquisition unit, used to select a window that satisfies a preset correlation with each window based on the correlation matrix to obtain a retrieval matrix;

[0101] The local information acquisition unit is used to extract features within the window based on the retrieval matrix and utilize the self-attention mechanism to obtain local information.

[0102] A further implementation method is that the information fusion module includes:

[0103] A query matrix acquisition unit, used for obtaining a query matrix based on global information;

[0104] A key matrix acquisition unit, used for obtaining a key matrix based on local information;

[0105] The weight parameter matrix acquisition unit is used to perform a self-attention mechanism on the query matrix and the key matrix to obtain the weight parameter matrix;

[0106] The information fusion unit is used to multiply the weight parameter matrix with the global information and add the multiplication result with the local information to obtain fused information.

[0107] The embodiments described above are only descriptions of the preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Without departing from the design spirit of the present invention, various modifications and improvements made to the technical solutions of the present invention by ordinary technicians in this field should all fall within the protection scope determined by the claims of the present invention.

Claims

1. An image coding method based on ViT that integrates high-value local information, characterized in that: The following steps are involved: Acquire an image to be compressed, and perform global feature extraction based on window division on the image to be compressed to obtain information between windows; Based on the information between windows, global information is obtained; Based on the global information, feature extraction is performed within the window to obtain local information; Based on the self-attention mechanism, the global information is fused with the local information to obtain fused information, thereby completing the image encoding based on ViT that fuses high-value local information.

2. The image coding method based on ViT and integrating high-value local information according to claim 1, characterized in that: The method for obtaining the global information is: Divide the image to be compressed into a number of non-overlapping windows on average, and add a class token of the patch size to each window; Based on the self-attention mechanism, feature extraction is performed inside the window with the class token added to obtain the class token representing the features of the current window; Based on the self-attention mechanism, feature extraction is performed on all class tokens representing the features of the current window to obtain the global information.

3. The image coding method based on ViT and integrating high-value local information according to claim 1, characterized in that: The method for obtaining the local information is: Based on the global information, obtaining a correlation matrix between windows and window affinities; Based on the correlation matrix, a window that satisfies a preset correlation with each window is selected to obtain a retrieval matrix; Based on the retrieval matrix, the self-attention mechanism is used to extract features within the window to obtain the local information.

4. The image coding method based on ViT and integrating high-value local information according to claim 1, characterized in that: The method of fusing the global information with the local information is: Based on the global information, obtaining a query matrix; Based on the local information, obtaining a key matrix; Perform a self-attention mechanism on the query matrix and the key matrix to obtain a weight parameter matrix; The weight parameter matrix is ​​multiplied by the global information, and the multiplication result is added to the local information to obtain the fusion information.

5. An image coding system based on ViT that integrates high-value local information, characterized in that: Used to implement the method according to any one of claims 1 to 4, comprising A global information acquisition module is used to acquire an image to be compressed, and perform global feature extraction based on window division on the image to be compressed to obtain information between windows; based on the information between windows, obtain global information; A local information acquisition module, used to extract features within the window based on the global information to obtain local information; The information fusion module is used to fuse the global information with the local information based on the self-attention mechanism to obtain fused information and complete the image encoding based on ViT that fuses the high-value local information.

6. The image coding system based on ViT and integrating high-value local information according to claim 5, characterized in that: The global information acquisition module includes: A division unit, used for dividing the image to be compressed into a plurality of non-overlapping windows on average, and adding a class token of a patch size in each window; The first feature extraction unit is used to extract features from the window with the class token added based on the self-attention mechanism to obtain the class token representing the features of the current window; The second feature extraction unit is used to extract features of all class tokens representing the features of the current window based on a self-attention mechanism to obtain the global information.

7. The image coding system based on ViT and integrating high-value local information according to claim 5, characterized in that: The local information acquisition module includes: A correlation matrix acquisition unit, used for obtaining a correlation matrix of window-window affinities based on the global information; A retrieval matrix acquisition unit, configured to select a window that satisfies a preset correlation with each window based on the correlation matrix to obtain a retrieval matrix; The local information acquisition unit is used to extract features within the window based on the retrieval matrix using a self-attention mechanism to obtain the local information.

8. The image coding system based on ViT and integrating high-value local information according to claim 7, characterized in that: The information fusion module includes: A query matrix acquisition unit, used to obtain a query matrix based on the global information; A key matrix acquisition unit, used for obtaining a key matrix based on the local information; A weight parameter matrix acquisition unit, used for performing a self-attention mechanism on the query matrix and the key matrix to obtain a weight parameter matrix; An information fusion unit is used to multiply the weight parameter matrix with the global information, and add the multiplication result with the local information to obtain the fused information.

Citation Information

Patent Citations

  • Zero-sample learning image classification method based on global and local context awareness

    CN112418351A

  • Image processing method and device and medium

    CN115661609A

  • Wide-view-field high-resolution video efficient intelligent detection method and system

    CN115880614A

  • Compression method of visual self-attention model based on multi-granularity reasoning

    CN115983322A

  • Multi-modal image feature matching method based on window local and global attention

    CN117649541A