Image encoder, high-precision interactive image segmentation method, electronic apparatus, and storage medium
By using multiple attention calculation modes and cyclic scanning modules in the image encoder, image feature fusion is optimized and solves the problems of low computational efficiency and poor segmentation effect of interactive image segmentation on high-resolution images in the existing technology. problem, achieving interactive segmentation effects with high precision and low latency.
Patent Information
- Application Number
- CN202410834157.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-06-26
AI Technical Summary
Existing click-based interactive image segmentation methods have problems with low computational efficiency and poor segmentation results on high-resolution images. In particular, the attention calculation method of the visual Transformer cannot be implemented efficiently, resulting in inference in an environment with insufficient video memory. Unable to perform, and the model lacks generalization to high-resolution images.
An image encoder is designed, including an image embedding module, a Transformer module and a cyclic scanning module. It uses the alternating distribution of general window attention and translation window attention, combined with a feedforward neural network, to optimize attention calculation and feature fusion. Through Flash Attention The library optimizes the calculation process and makes iterative predictions through a decoder combined with user interaction encoding.
It improves the computational efficiency and segmentation quality of interactive segmentation, enables high-precision interactive segmentation on high-resolution images, reduces computing latency, and maintains high segmentation effects on low-power devices.
Smart Images

Figure CN118864490A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to an image encoder, a high-precision interactive image segmentation method, an electronic device and a storage medium. Background Art
[0002] Driven by massive amounts of data, deep networks have demonstrated impressive performance in various computer vision tasks. The availability of accurately annotated data is crucial to the success of deep networks, but the manual annotation process takes up a lot of time and computing resources. Therefore, the gradually developed interactive image segmentation has become an indispensable tool for annotating large-scale image datasets. This technology aims to achieve high-quality pixel-level annotation through limited interaction, and the interaction method includes a combination of one or more methods such as graffiti, bounding boxes, polygons, and clicks. Among the many interactive image segmentation methods, click-based methods have attracted much attention due to their simplicity and efficiency. Therefore, the present invention focuses on click-based methods and attempts to solve their computational and efficiency problems in practical applications.
[0003] In the prior art, the research on click-based interactive image segmentation methods mainly focuses on real-time, low-resolution interactive segmentation models, such as SAM (Alexander Kirillov, Eric Mintun, Nikhila Ravi, Hanzi Mao, Chloe Rolland, Laura Gustafson, Tete Xiao, Spencer Whitehead, Alexander C. Berg, Wan-Yen Lo, Piotr Doll ́ar, and Ross Girshick. Segment anything.arXiv:2304.02643, 2023.). However, this interactive segmentation model has two problems: (1) First, the attention calculation of the Visual Transformer (ViT) used by the encoder cannot adopt the efficient underlying implementation of Flatten Attention; (2) Secondly, the encoder’s global attention does not produce performance improvements commensurate with its computational effort on high-resolution images.
[0004] Therefore, when faced with high-resolution images, SAM cannot perform reasoning on an operating environment with insufficient video memory (such as the common 3090 graphics card) due to its inefficient attention calculation method; even if it runs on a graphics card with sufficient video memory, it cannot guarantee that the use of high-resolution images can effectively improve the segmentation effect. This is because the attention calculation used by SAM has a length extrapolation problem. Specifically, when the training process and the test process use different image resolutions, the model lacks sufficient high-resolution image generalization due to the significant length difference in the image feature sequence it faces during the attention calculation process. For example, when a 1024×1024 image is used as input during training and a 2048×2048 image is used as input during testing, the resolution of the input image in the training phase and the test phase is inconsistent, which may cause a difference in the numerical distribution during the attention calculation, making the model unable to effectively improve the segmentation effect on high-resolution images but bringing huge inference calculation costs. Summary of the invention
[0005] The purpose of the present invention is to provide an image encoder, a high-precision interactive image segmentation method, an electronic device and a storage medium to solve the problems existing in the prior art, improve the computational efficiency and segmentation quality of interactive segmentation, and realize high-precision interactive segmentation on high-resolution images.
[0006] In order to achieve the above object, one of the solutions of the present invention is: An image encoder comprises an image embedding module, 12 Transformer modules and 4 loop scanning modules constructed in series, wherein three Transformer modules constitute one stage, and a loop scanning module is inserted before the last Transformer module in each stage; the Transformer module comprises an attention calculation module and a feedforward neural network module connected in series; the attention of the attention calculation module comprises a general window attention and a translation window attention, and these two attentions are alternately distributed in the 12 Transformer modules; The image embedding module linearly transforms the image to be annotated by convolution to obtain image features. ,in represents the real number space, and Respectively represent the height and width of the image; The Transformer module uses the attention calculation module to calculate the image features. Perform spatial fusion and then enhance features through the feedforward neural network module; The two types of attention calculations in the attention calculation module are: The general window attention is to take the image features Reshape to get the reshaped image features ,in Indicates a predefined window size, superscript It stands for reshape, and then the features of each window are The conventional attention calculation is performed in parallel, and after the attention calculation is completed, the original feature form is restored through the reshaping operation, where Indicates the sequence number of the feature after windowing; The translation window attention is obtained by Fill the left and top of and A zero vector of units, and at the same time in the image features Right and bottom padding and The zero vector of units is used to obtain the image features after expansion. , and then the general window attention is calculated, where Indicates a predefined window size, and Respectively represent the number of features of the preset horizontal and vertical axis translation, and the values are between 0 and between.
[0007] The feedforward neural network module first transforms the image features After general matrix multiplication mapping, the mapped image features are obtained , where the superscript Abbreviation for mapping; the mapping image features After nonlinear activation calculation, it is converted into image features through another linear mapping. ; The loop module first inputs the image features Flatten into short sequence features , and then the short sequence feature short sequence feature After three copies, concatenation is performed to obtain long sequence features , where the superscript and Represent short sequence and long sequence respectively; then, coefficients are generated through multiple parallel linear mappings and ,in and This linear mapping is used to generate the weights of the two coefficients; then the coefficients and The two are input into the computational library of the selective state space model to perform a scanning computation process of sequence features, which is described in the form of iteration. ,in Indicates the first The calculation result of each element is Indicates The features corresponding to the elements are and have the same dimensions, Represents the serial number of the element in the sequence; output after traversing and calculating all the elements in this sequence As the final result of this scanning calculation process, the merged sequence features are obtained by equal length division and summing, and finally the merged sequence features are converted into image features through reshaping operation. As the output of the loop module.
[0008] Preferably, when performing general window attention calculation, the attention calculation module uses the calculation function library Flash Attention to run this calculation process.
[0009] The second solution of the present invention is: A high-precision interactive image segmentation method, using a decoder and the image encoder, comprises the following steps: Step 1: Preprocess the image to be annotated by the image encoder to obtain image features ; Then the image features The number of channels is reduced through convolution calculation to obtain the final image features. ; Step 2: The image encoder converts the user input Click information is converted into click code , the rough mask information provided by the user is converted into a mask code , get the click code and mask encoding The interaction code is updated each time the user interacts by clicking; Step 3: Combine the interaction code with the learnable query code It is fed into the decoder and combined with the final image features in step 1 Combined, we get the query encoding that integrates the interactive information Upsampled image features with fused mutual information , and its calculation formula is as follows: ; in represents a cross-attention operation; Step 4: Use the dot multiplication operation to integrate the upsampled image features of the interactive information Query encoding with fusion of interactive information Further fusion to obtain the predicted mask , and its calculation formula is as follows: ; in express The transpose of Step 5. During the model training and standard testing process, find the connected area with the largest error based on the final predicted mask and mask label, select the central pixel of the connected area as the location of the next simulated click, and iterate the next model prediction; in the real test environment, iterative prediction is performed based on the user's interactive click feedback to gradually improve the segmentation quality.
[0010] The third solution of the present invention is: An electronic device comprises a processor, a memory and an application program; the application program is stored in the memory and is configured so that the processor executes the high-precision interactive image segmentation method.
[0011] The fourth solution of the present invention is: A computer-readable storage medium stores a computer program; when the computer program is executed in the computer, the computer executes the high-precision interactive image segmentation method.
[0012] After adopting the above technical solution, the present invention has the following technical effects: The present invention optimizes the image encoder in the preprocessing stage of large-scale visual models, and can extract high-quality and reusable image features from the images to be annotated, and realize the fusion of global feature information of the images to be annotated, so that the model can be more competitive on high-resolution images while maintaining the original efficient calculation, and provides an effective solution for high-precision interactive image segmentation; the image encoder integrates multiple windowed attention calculation modes, which significantly improves the ability of image encoders trained under conventional resolution to perform high-precision interactive segmentation on high-resolution images.
[0013] The method of the present invention uses an image encoder to extract high-quality and reusable image features from the image to be annotated, and can realize interactive segmentation on low-power devices such as personal computers or mobile devices through a lightweight interactive segmentation module. The image features extracted by the large visual model and the clicks of the annotator will be used as the input of the interactive segmentation module; under the premise of low computing delay, the high-precision segmentation effect of the overall interactive segmentation model on high-resolution images can be improved. The model architecture using this method can only use the simplest distillation training, but the trained model can still maintain lower computing delay on high-resolution images. The premise exceeds the teacher model used for distillation and achieves a very high segmentation effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 A schematic diagram of the network structure of an image encoder according to a specific embodiment of the present invention; Figure 2 This is an experimental data table of a specific embodiment of the present invention. DETAILED DESCRIPTION
[0015] In order to further explain the technical solution of the present invention, the present invention is described in detail below through specific embodiments.
[0016] The present invention discloses an image encoder for extracting high-quality and reusable image features from an image to be annotated before the interactive process of an interactive image segmentation method. The image encoder mainly uses window attention calculation as the main method, constructs two attention calculation methods: general window attention and translation window attention, and cooperates with a cyclic scanning module to strengthen the global feature information fusion of the image.
[0017] refer to Figure 1 As shown in FIG. 1 , the image encoder mainly includes an image embedding module, 12 Transformer modules and 4 loop scanning modules constructed in series. Every 3 Transformer modules form a stage, and a loop scanning module is inserted before the last Transformer module in each stage. The Transformer module includes a series of attention calculation modules and feedforward neural network modules (FFN). The attention of the attention calculation module includes general window attention (corresponding to Figure 1 The general module in ) and the translation window attention (corresponding to Figure 1 The above two types of attention are alternately distributed in the 12 Transformer modules. For example, the attention calculation module of the first Transformer module adopts general window attention, and the second Transformer module adopts translation window attention, and vice versa.
[0018] The image embedding module uses convolution to linearly transform the original three-channel image to be annotated to obtain image features. ,in represents the real number space, and Represent the height and width of the image respectively; the subsequent 12 Transformer modules then transform the image features Perform serial processing.
[0019] The Transformer module receives image features As input, it outputs image features of the same dimension; specifically, the image features are first calculated by the attention calculation module Perform spatial fusion and then enhance the features through a feedforward neural network module.
[0020] The two types of attention calculations in the attention calculation module are: a. General Window Attention Generally, window attention transforms image features into Windowing: Image features Reshape to get the reshaped image features ,in Indicates a predefined window size (preset by the user, for example, set to 16), the superscript Reshape is an abbreviation for reshape, which is used to distinguish different image features (the superscript is mainly used for distinction and will not be repeated below).
[0021] Afterwards, the features of each window The conventional attention calculation is performed in parallel, and after the attention calculation is completed, the original feature form is restored through the reshaping operation, where Indicates the sequence number of the feature after windowing.
[0022] b. Shift window attention The overall process of shifting window attention is similar to that of general window attention. The main difference lies in the windowing method: shifting window attention mainly transforms the preliminary image features into Perform a fixed amount of translation in both the horizontal and vertical directions, for example, Line The image features of the columns are in the horizontal direction ( axis direction) and longitudinal direction ( axis direction) respectively and Units ( Represents a predefined window size), so when it is reshaped for windowing, it is equivalent to indirectly moving the window, that is, achieving the effect of panning the window.
[0023] The present invention simplifies the translation operation process: by Fill the left and top of and The zero vector of units, at the same time in the image features Right and bottom padding and The zero vector of units is used to obtain the image features after expansion. , and then perform the above general window attention calculation, which is equivalent to the image features The above-mentioned translation operation is performed; wherein, Indicates a predefined window size, and Respectively represent the number of features of the preset horizontal and vertical axis translation, and the values are between 0 and between.
[0024] The feedforward neural network module consists of two simple linear mapping layers. After general matrix multiplication mapping, the mapped image features are obtained , where the superscript Abbreviation for mapping; mapping image features After nonlinear activation calculation, it is converted into image features through another linear mapping. .
[0025] The loop module first inputs the image features Flatten into short sequence features , and then the short sequence feature short sequence feature After three copies, concatenation is performed to obtain long sequence features , where the superscript and Respectively represent short sequence and long sequence; then, multiple parallel linear mappings are used to generate coefficients and ,in and This linear mapping is used to generate the weights of the two coefficients; then the coefficients and The two are input into the computational library of the selective state space model to perform a scanning computation process of sequence features, which is described in the form of iteration. ,in Indicates the first The calculation result of each element is Indicates The features corresponding to the elements are and have the same dimensions, Represents the serial number of the element in the sequence; output after traversing and calculating all the elements in this sequence As the final result of this scanning calculation process, the merged sequence features are obtained by equal length division and summing, and finally the merged sequence features are converted into image features through reshaping operation. As the output of the loop module.
[0026] Through the above scheme, the present invention has the following outstanding advantages: The present invention optimizes the image encoder in the preprocessing stage of large-scale visual models. It can extract high-quality and reusable image features from the images to be labeled, and realize the fusion of global feature information of the images to be labeled. Under the premise of maintaining the original efficient calculation, the model is more competitive on high-resolution images, providing an effective solution for high-precision interactive image segmentation.
[0027] In some embodiments of the present invention, when performing general window attention calculation, the attention calculation module uses the mature calculation function library Flash Attention to run the calculation process, which can reduce the actual video memory occupancy.
[0028] The present invention also discloses a high-precision interactive image segmentation method, which aims to improve the processing effect of interactive segmentation on high-resolution images. The above-mentioned image encoder is used to extract high-quality and reusable image features from the image to be annotated, so that interactive segmentation can be performed on low-power devices such as personal computers or mobile devices through a lightweight interactive segmentation module. The image features extracted by the large visual model and the clicks of the annotator will be used as the input of the interactive segmentation module. The advantage of this interactive image segmentation method is that it can improve the high-precision segmentation effect of the overall interactive segmentation model on high-resolution images under the premise of low computing latency. The specific steps of this method are as follows: Step 1: Preprocess the image to be annotated through the image encoder to obtain image features ; Then the image features The number of channels is reduced through convolution calculation to obtain the final image features. ; Step 2: Use the image encoder to convert the user input Click information is converted into click code , the rough mask information provided by the user is converted into a mask code , get the click code and mask encoding The interaction code is updated every time the user interacts by clicking; Step 3: Interaction encoding and learnable query encoding It is fed into the decoder and combined with the final image features in step 1 Combined, we get the query encoding that integrates the interactive information Upsampled image features with fused mutual information , and its calculation formula is as follows: ; in represents a cross-attention operation; Step 4: Use the dot multiplication operation to integrate the upsampled image features of the interactive information Query encoding with fusion of interactive information Further fusion to obtain the predicted mask , and its calculation formula is as follows: ; in express The transpose of Step 5. During the model training and standard testing process, find the connected area with the largest error based on the final predicted mask and mask label, select the central pixel of the connected area as the location of the next simulated click, and iterate the next model prediction; in the real test environment, iterative prediction is performed based on the user's interactive click feedback to gradually improve the segmentation quality.
[0029] The following further illustrates the technical effects of the present invention through simulation experiments and experimental data.
[0030] 1) Simulation conditions The present invention is developed on the Ubuntu platform, and the developed deep learning framework is based on Pytorch, and the main language used is Python.
[0031] 2) Simulation content Take COCO2017, LVIS and HQSeg44K-Training datasets, first use the SAM model as the teacher model on the first two datasets, distill the large visual model of the present invention, then use the simulated interaction process to perform fine-tuning training on the last dataset, and use HQSeg44K-Validation and DAVIS as test sets for testing. Figure 2, which are the segmentation results of the present invention and other methods in various test data sets. After intuitive numerical comparison, it can be found that compared with other methods, the present invention has the best effect. Among them, the evaluation index NoC (Number of Clicks) represents the number of clicks required to reach a certain IoU threshold, and SPC (Seconds Per Click) represents the time spent on one click reasoning, which measures the efficiency of the model in pixel segmentation on potential large or small objects; through the comparison of NoC indicators, it can be seen that under the same training method, the segmentation quality of this method surpasses other advanced methods, and at the same time has lower computational delay (SPC) than the previous best method, that is, it has a smaller computational burden and higher segmentation quality.
[0032] The present invention also discloses an electronic device, comprising a processor, a memory and an application program; the application program is stored in the memory and is configured to execute the above method by the processor.
[0033] The present invention also discloses a computer-readable storage medium, which stores a computer program; when the computer program is executed in a computer, the computer executes the above method. The storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0034] The above embodiments and drawings do not limit the product form and style of the present invention. Any appropriate changes or modifications made by ordinary technicians in the relevant technical field should be deemed to be within the patent scope of the present invention.
Claims
1. An image encoder, characterized in that: The method comprises one image embedding module, 12 Transformer modules and four loop scanning modules constructed in series, wherein three Transformer modules constitute one stage, and one loop scanning module is inserted before the last Transformer module in each stage; the Transformer module comprises an attention calculation module and a feedforward neural network module connected in series; the attention of the attention calculation module comprises general window attention and translation window attention, and these two types of attention are alternately distributed in the 12 Transformer modules; The image embedding module linearly transforms the image to be annotated by convolution to obtain image features. ,in represents the real number space, and Respectively represent the height and width of the image; The Transformer module uses the attention calculation module to calculate the image features. Perform spatial fusion and then enhance features through the feedforward neural network module; The two types of attention calculations in the attention calculation module are: The general window attention is to take the image features Reshape to get the reshaped image features ,in Indicates a predefined window size, superscript It stands for reshape, and then the features of each window are The conventional attention calculation is performed in parallel, and after the attention calculation is completed, the original feature form is restored through the reshaping operation, where Indicates the sequence number of the feature after windowing; The translation window attention is obtained by Fill the left and top of and A zero vector of units, and at the same time in the image features Right and bottom padding and The zero vector of units is used to obtain the image features after expansion. , and then the general window attention is calculated, where Indicates a predefined window size, and Respectively represent the number of features of the preset horizontal and vertical axis translation, and the values are between 0 and between. The feedforward neural network module first transforms the image features After general matrix multiplication mapping, the mapped image features are obtained , where the superscript Abbreviation for mapping; the mapping image features After nonlinear activation calculation, it is converted into image features through another linear mapping. ; The loop module first inputs the image features Flatten into short sequence features , and then the short sequence feature short sequence feature After three copies, concatenation is performed to obtain long sequence features , where the superscript and Respectively represent short sequence and long sequence; Afterwards, the coefficients are generated through multiple parallel linear mappings and ,in and This linear mapping is used to generate the weights of the two coefficients; then the coefficients and The two are input into the computational library of the selective state space model to perform a scanning computation process of sequence features, which is described in the form of iteration. ,in Indicates the first The calculation result of each element is Indicates The features corresponding to the elements are and have the same dimensions, Represents the serial number of the element in the sequence; output after traversing and calculating all the elements in this sequence As the final result of this scanning calculation process, the merged sequence features are obtained by equal length division and summing, and finally the merged sequence features are converted into image features through reshaping operation. As the output of the loop module.
2. The image encoder according to claim 1, wherein: When performing general window attention calculation, the attention calculation module uses the calculation function library FlashAttention to run this calculation process.
3. A high-precision interactive image segmentation method, using a decoder and an image encoder as claimed in any one of claims 1 or 2, characterized in that The following steps are involved: Step 1: Preprocess the image to be annotated by the image encoder to obtain image features ; Then the image features The number of channels is reduced through convolution calculation to obtain the final image features. ; Step 2: The image encoder converts the user input Click information is converted into click code , the rough mask information provided by the user is converted into a mask code , get the click code and mask encoding The interaction code is updated each time the user interacts by clicking; Step 3: Combine the interaction code with the learnable query code It is fed into the decoder and combined with the final image features in step 1 Combined, we get the query encoding that integrates the interactive information Upsampled image features with fused mutual information , and its calculation formula is as follows: ; in represents a cross-attention operation; Step 4: Use the dot multiplication operation to integrate the upsampled image features of the interactive information Query encoding with fusion of interactive information Further fusion to obtain the predicted mask , and its calculation formula is as follows: ; in express The transpose of Step 5: In the process of model training and standard testing, according to the final prediction mask and mask label, find the connected area with the largest error, select the central pixel of the connected area as the position of the next simulated click, and iterate the next model prediction; In a real test environment, iterative predictions are performed based on the user's interactive click feedback to gradually improve the segmentation quality.
4. An electronic device, characterized in that: The system comprises a processor, a memory and an application program; the application program is stored in the memory and is configured so that the processor executes the high-precision interactive image segmentation method as claimed in claim 3.
5. A computer-readable storage medium, characterized in that: The storage medium stores a computer program; when the computer program is executed in the computer, the computer executes the high-precision interactive image segmentation method as claimed in claim 3.
Citation Information
Patent Citations
U-shaped image segmentation network based on convolution enhanced cross self-attention deformer
CN115908805A
Lightweight Transform-based text semantic mining method and system
CN117474003A
Transform-based gray medical image coloring method and system
CN117671045A
Dental caries PS-OCT lesion region segmentation and extraction method based on improved convolutional neural network
CN118015014A
Real-time interactive image segmentation method
CN118229700A
