An ultra-lightweight image segmentation method and computer device based on Mamba
By adopting an ultra-lightweight image segmentation method based on Mamba in image segmentation, using encoder, decoder and skip connection structure, combined with visual state space block and attention mechanism, the problem of insufficient computing resources of traditional methods is solved and applicable Efficient image segmentation for mobile devices.
Patent Information
- Application Number
- CN202411082749.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-08
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2044-08-08
AI Technical Summary
Traditional image segmentation methods have insufficient computing resources in mobile detection devices, resulting in excessive computational load and difficulty in adapting to actual application scenarios.
Using an ultra-lightweight image segmentation method based on Mamba, through the encoder, decoder and skip connection structure, combined with the visual state space block and attention mechanism, the amount of parameters and calculations are reduced, and an asymmetric encoder-decoder model is constructed. Perform multi-level and multi-scale information fusion.
While maintaining excellent segmentation performance, it significantly optimizes computing resources and obtains an ultra-lightweight model, which is suitable for mobile detection equipment.
Smart Images

Figure CN118608792B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image segmentation, and in particular to an ultra-lightweight image segmentation method and a computer device based on Mamba. Background Art
[0002] Traditional image segmentation is usually achieved using deep learning networks represented by convolution and Transformer architectures. Convolution has excellent local feature extraction capabilities, but it is insufficient in establishing the correlation of remote information. Although the self-attention mechanism can solve the problem of extracting remote information using continuous patch sequences, it also brings a large computational load. In order to improve the segmentation performance of the model, most methods tend to use more complex modules. However, this is not suitable for practical application scenarios, especially mobile detection equipment. Due to the limitation of computing resources, the computationally loaded model is not suitable for real application scenarios.
[0003] In recent years, state-space models (SSMs), represented by Mamba, have become strong competitors to traditional convolutional neural networks and Transformer architectures. State-space models (SSMs) show linear complexity in input size and memory footprint, which makes them key to lightweight model foundations. In addition, SSMs are good at capturing long-range dependencies, which can be critical to solving the convolution problem for extracting information over long distances. In industrial detection, actual computing power and memory constraints usually need to be considered. Summary of the invention
[0004] The purpose of the present invention is to overcome the shortcomings of the prior art and provide an ultra-lightweight image segmentation method and computer device based on Mamba, which can maximize the optimization of computing resources while maintaining excellent segmentation performance, obtain an ultra-lightweight model, and is more suitable for mobile detection equipment.
[0005] The present invention adopts the following technical solutions to achieve the above-mentioned purpose. In a first aspect, the present invention provides an ultra-lightweight image segmentation method based on Mamba, comprising:
[0006] S1, obtaining an original image, preprocessing the original image to obtain an original image set, and dividing the original image set into a training set, a validation set, and a test set according to a set ratio;
[0007] S2. Build an ultra-lightweight image segmentation model based on Mamba;
[0008] The Mamba-based ultra-lightweight image segmentation model mainly consists of an encoder, a decoder, and a skip connection between the encoder and the decoder;
[0009] The encoder includes a first residual convolution module, a second residual convolution module, a first parallel convolution module and a second parallel convolution module, the decoder includes a convolution module, a first parallel vision module, a second parallel vision module and a third parallel vision module, the jump connection performs multi-level and multi-scale information fusion through an attention mechanism module, and the attention mechanism module is mainly composed of a spatial attention mechanism submodule and a channel attention mechanism submodule;
[0010] The first residual convolution module and the second residual convolution module have the same structure, mainly consisting of three parallel convolution layers. The first parallel convolution module and the second parallel convolution module have the same structure, mainly consisting of four parallel layers, each parallel layer mainly consisting of three residual connected branches, the first branch consists of a visual state space block and a jump connection, the second branch consists of a standard convolution with a convolution kernel of 3 and a jump connection, and the third branch consists of a standard convolution with a convolution kernel of 5 and a jump connection;
[0011] The first parallel vision module, the second parallel vision module and the third parallel vision module have the same structure, and are mainly composed of four parallel layers, each parallel layer is mainly composed of a visual state space block and a jump connection, the visual state space block is mainly composed of two branches, the first branch is mainly composed of a linear layer and a SiLU activation function, and the second branch is mainly composed of a linear layer, a deep convolution, a SiLU activation function, a state space model and a layer normalization layer, and finally the two branches are merged by element-by-element multiplication to output;
[0012] S3, using the original images in the training set and the validation set as inputs of the Mamba-based ultra-lightweight image segmentation model, and performing image segmentation training on the Mamba-based ultra-lightweight image segmentation model;
[0013] S4. Input the original image in the test set into the trained Mamba-based ultra-lightweight image segmentation model to obtain the image segmentation result.
[0014] Furthermore, S3 specifically includes:
[0015] Encoder training process: The original image is input into the 3×3 convolution layer and 5×5 convolution layer of the first residual convolution module respectively to obtain the corresponding two branch results, and then the two branch results are merged to obtain the first feature map. Then the original image is input into the 1×1 convolution layer of the first residual convolution module to obtain a feature map and fuse it with the first feature map. After fusion, the second feature map is output, and the second feature map is input into the second residual convolution module. The second residual convolution module outputs the third feature map.
[0016] The third feature map with the number of channels C is input into the layer normalization layer of the first parallel convolution module, and then is divided into four corresponding feature maps with the number of channels C / 4. Then, each corresponding feature map is input into each parallel layer respectively, and the outputs of the three residual connected branches in the parallel layer are spliced and adjusted to obtain three corresponding feature maps. The three corresponding feature maps of each branch are added together to obtain four intermediate feature maps with the number of channels C / 4. The four intermediate feature maps with the number of channels C / 4 are combined into a fourth feature map with the number of channels C through splicing operations. Finally, the fifth feature map is output through layer normalization layers and projection operation layers respectively.
[0017] Furthermore, S3 specifically includes:
[0018] Decoder training process: The feature map with the number of channels C output by the encoder is input into the layer normalization layer of the third parallel vision module, and then divided into four corresponding feature maps with the number of channels C / 4. Then each feature is input into the VSS Block respectively, and then the residual splicing and adjustment factor are performed. The feature map with the number of channels C is obtained by splicing the feature maps, and then the corresponding feature maps are output through the layer normalization layer and the projection operation layer respectively. The corresponding feature map is input into the convolution module with the convolution kernel of 1, and the segmented image is output.
[0019] Furthermore, the skip connection uses the attention mechanism to perform multi-level and multi-scale information fusion, including:
[0020] First, the feature map is input into the spatial attention mechanism submodule, and the maximum pooling and average pooling are performed respectively. Then, the results of the two pooling are spliced along the channel dimension, and then the convolution layer is used for convolution operation. Then, the output result is limited to the range of [0, 1] through the Sigmoid activation function. Finally, the input feature map is multiplied by the result, and then added to the input feature map to obtain the spatial attention feature map;
[0021] The spatial attention feature map is used as the input of the channel attention mechanism submodule. The input feature map is globally averaged pooled through the channel attention mechanism submodule. The spatial dimension of the input feature map is compressed through adaptive pooling to retain the channel information. The global attention weight is calculated using one-dimensional convolution. The attention weight of each channel is calculated using a fully connected layer or a convolutional layer. The Sigmoid activation function is then used to limit the attention weight to the range of [0, 1]. The calculated attention weight is applied to the corresponding input feature map, and the final attention feature map is returned after being concatenated with the input feature map.
[0022] In a second aspect, the present invention provides a computer device, including a memory, wherein the memory stores program instructions, and when the program instructions are executed, the ultra-lightweight image segmentation method based on Mamba as described above is executed.
[0023] The beneficial effects of the present invention are:
[0024] The present invention introduces visual state space blocks as basic blocks to capture a wide range of contextual information. At the same time, combined with the excellent local feature extraction capability of convolution, a method of parallel processing of channel division and local convolution is proposed, which greatly reduces the number of parameters and calculations, and constructs an asymmetric encoder-decoder structure. While maintaining excellent segmentation performance, an ultra-lightweight model is obtained, which maximizes the optimization of computing resources and is more suitable for mobile detection equipment. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It is a flow chart of an ultra-lightweight image segmentation method based on Mamba provided by an embodiment of the present invention;
[0026] Figure 2 It is a schematic diagram of the structure of an ultra-lightweight image segmentation model based on Mamba provided by an embodiment of the present invention;
[0027] Figure 3 Schematic diagram of the structure of the submodule of the spatial attention mechanism provided by an embodiment of the present invention;
[0028] Figure 4 Schematic diagram of the structure of the channel attention mechanism submodule provided by an embodiment of the present invention;
[0029] Figure 5 is a schematic diagram of the structure of a first parallel convolution module provided in an embodiment of the present invention;
[0030] Figure 6 It is a schematic diagram of the structure of each parallel layer in the MPL (Multiple Parallel Vision Layer) module, i.e., the first parallel convolution module, provided in an embodiment of the present invention;
[0031] Figure 7 It is a schematic diagram of the structure of each parallel layer in the PVL (Parallel Vision Layer) module, i.e., the first parallel vision module, provided in an embodiment of the present invention;
[0032] Figure 8 4 is a schematic diagram of the structure of a visual state space block provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0033] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0034] The present invention provides an ultra-lightweight image segmentation method based on Mamba, such as Figure 1 As shown, including:
[0035] S1. Obtain the original image, preprocess the original image to obtain the original image set, and divide the original image into a training set, a verification set, and a test set according to a certain ratio.
[0036] S2. Build an ultra-lightweight image segmentation model based on Mamba.
[0037] like Figure 2 As shown in the figure, the ultra-lightweight image segmentation model based on Mamba has a four-layer structure, which is mainly composed of an encoder, a decoder, and a jump connection between the encoder and the decoder;
[0038] The encoder includes a first residual convolution module, a second residual convolution module, a first parallel convolution module and a second parallel convolution module, the decoder includes a convolution module, a first parallel vision module, a second parallel vision module and a third parallel vision module, the jump connection performs multi-level and multi-scale information fusion through an attention mechanism module, and the attention mechanism module is mainly composed of a spatial attention mechanism submodule and a channel attention mechanism submodule. The structures of the spatial attention mechanism submodule and the channel attention mechanism submodule are respectively as follows: Figure 3 , Figure 4 As shown;
[0039] The first residual convolution module and the second residual convolution module have the same structure, which is mainly composed of three parallel convolution layers. The first parallel convolution module and the second parallel convolution module have the same structure. Figure 5 As shown, it is mainly composed of four parallel layers, each of which is mainly composed of three residual connected branches, such as Figure 6 As shown in the figure, the first branch consists of a visual state space block and a jump connection. Scale (a scalar value) is introduced to control the scaling of the jump connection, which helps to alleviate the gradient vanishing problem and accelerate training. The second branch consists of a standard convolution with a convolution kernel of 3 and a jump connection, and the third branch consists of a standard convolution with a convolution kernel of 5 and a jump connection. At the same time, scale is introduced to control the scaling of the jump connection.
[0040] The structures of the first parallel vision module, the second parallel vision module and the third parallel vision module are similar to the first parallel convolution module. Figure 5As shown in the figure, it is mainly composed of four parallel layers. Unlike the first parallel convolution module, each parallel layer of the first parallel vision module is mainly composed of a residual connection branch, lacking two parallel convolution layers and only containing the visual state space module, which can restore the resolution of the feature map while maintaining high-level features. Figure 7 As shown in Figure 2, each parallel layer of the first parallel vision module is mainly composed of a visual state space block and a jump connection, such as Figure 8 As shown in Figure 1, the visual state space block mainly consists of two branches. The first branch mainly consists of linear layers and SiLU activation functions, and the second branch mainly consists of linear layers, depthwise convolutions, SiLU activation functions, state space models, and layer normalization layers. Finally, the two branches are merged through element-wise multiplication to output.
[0041] S3. Use the original images in the training set and the validation set as inputs of the Mamba-based ultra-lightweight image segmentation model, and perform image segmentation training on the Mamba-based ultra-lightweight image segmentation model.
[0042] S4. Input the original image in the test set into the trained Mamba-based ultra-lightweight image segmentation model to obtain the image segmentation result.
[0043] In one embodiment of the present invention, S3 specifically includes:
[0044] Encoder training process: the original image The 3×3 convolution layer and 5×5 convolution layer of the first residual convolution module are input respectively to obtain the corresponding two branch results, and then the two branch results are merged to obtain the first feature map , then the original image Input the 1×1 convolution layer of the first residual convolution module to obtain the feature map and the first feature map After fusion, the second feature map is output , the second feature map Input the second residual convolution module, and the second residual convolution module outputs the third feature map , the specific operation can be expressed as follows:
[0045] ;
[0046] Cat represents a concatenation operation, and Add represents an element superposition operation.
[0047] like Figure 5 As shown, the third feature map with the number of channels C First, the layer normalization layer of the first parallel convolution module is input, and then it is divided into four feature maps with a channel number of C / 4 Then each feature map is input into the visual state space block, 3×3 convolution, and 5×5 convolution parallel layers respectively, and the outputs of the three residual connection branches in the parallel layer are concatenated and adjusted by factors. , and get three corresponding feature maps , add the corresponding elements of the three feature maps of each branch to obtain 4 feature maps with a channel number of C / 4 , through the concatenation operation, the four feature maps with the number of channels C / 4 are combined into the fourth feature map with the number of channels C Finally, the fifth feature map is output through the layer normalization layer and the projection operation layer. .
[0048] The specific operation can be expressed as follows:
[0049] ;
[0050] .
[0051] Chunk 4 It means that the input feature map is divided into four parts along the channel dimension; LayerNorm means layer normalization; Projection means projection operation; reshape means changing the shape of a multidimensional array.
[0052] The fifth feature map Input the second parallel convolution module, and obtain the sixth feature map through similar operations as above F 6 .
[0053] Decoder training process: The sixth feature map with the number of channels C F 6 First, the layer normalization layer of the third parallel vision module is input, and then it is divided into four feature maps with a channel number of C / 4. Then, each feature map is input into the visual state space block, and then residual splicing and adjustment factors are performed. The feature map with a channel number of C is obtained by splicing the feature maps, and then the seventh feature map is output through the layer normalization layer and the projection operation layer. F 7 , and then the seventh feature map F 7 Input the second parallel vision module and output the eighth feature map F 8 , the eighth feature map F 8 Input the first parallel vision module and output the ninth feature map F 9 , and finally the ninth feature map F 9Input a convolution module with a convolution kernel of 1 and output the segmented image.
[0054] In one embodiment of the present invention, the skip connection performs multi-level and multi-scale information fusion through the attention mechanism, specifically including:
[0055] like Figure 3 As shown in the figure, the feature map is first input into the spatial attention mechanism submodule, and the maximum pooling and average pooling are performed respectively. Then, the two pooling results are spliced along the channel dimension, and then a one-dimensional convolution layer is used for convolution operation. Then, the output is limited to the range of [0, 1] through a fully connected layer and a Sigmoid activation function. Finally, the input feature map is multiplied by the result and then added to the input feature map to obtain the spatial attention feature map.
[0056] like Figure 4 As shown in the figure, the output of the spatial attention mechanism submodule is used as the input of the channel attention mechanism submodule. The channel attention mechanism submodule first performs global average pooling on the input feature map, compresses the spatial dimension of the input feature map through adaptive pooling, retains the channel information, and then splices it with the feature maps of the remaining layers. The global attention weight is calculated using one-dimensional convolution, and the attention weight of each channel is calculated using a fully connected layer or a convolutional layer. The Sigmoid activation function is then used to limit the attention weight to the range of [0, 1], and the calculated attention weight is applied to the corresponding input feature map. After adding it to the input feature map, the final attention feature map is returned. The specific operation can be expressed as follows:
[0057] ;
[0058] Where GAP is the global average pooling, are the feature maps of different stages obtained from the encoder, Concat represents the connection operation on the channel dimension, Conv1D represents the one-dimensional convolution operation, FCi is the fully connected layer of stage i, σ is the sigmoid function, and ⊙ is the element multiplication.
[0059] In order to verify the competitive performance of the ultra-lightweight image segmentation model based on Mamba proposed in this invention under lightweight conditions, this invention conducted a comparative experiment between the lightweight model based on Mamba and the classic medical image segmentation model. Specifically, the comparison objects include U-Net, VM-UNet, MALUNet and UltraLight VM-UNet.
[0060] Common indicators for evaluating model performance using commonly used segmentation datasets in medicine include Dice similarity coefficient (DSC), sensitivity (SE), specificity (SP) and accuracy (ACC). See Table 1 for specific data.
[0061] Table 1 Parameter evaluation table
[0062]
[0063] As shown in Table 1, the model parameters of the present invention are 99.94% lower than the traditional pure visual Mamba UNet model (VM-UNet), 75.51% lower than the current lightest visual Mamba UNet model (UltraLight VM-UNet), 99.84% lower than the traditional U-Net model, and 93.14% lower than the MALUNet model. The GFLOPs of this model are 97.28% lower than VM-UNet. Although its GFLOPs are slightly higher than UltraLightVM-UNet and MALUNet, the final calculation amount is only 32.58% higher than that of the UltraLight VM-UNet model, but the parameter amount is reduced by 75.51%. Overall, this model is still better than the current lightest visual Mamba UNet model. The remaining parameters, among which DSC is an accuracy index for evaluating the segmentation results, are all better than all the above models; Sensitivity (SE) measures the ability of the model to correctly identify positive samples, and Specificity (SP) measures the ability of the model to correctly identify negative samples, which are a pair of opposite parameters; Accuracy measures the proportion of correctly classified samples in the model as a whole, and as can be seen from Table 1, all are better than the above models. With such a large reduction in parameters and GFLOPs, the performance of the model of the present invention still maintains excellent and highly competitive performance.
[0064] The above is only a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in various other combinations, modifications and environments, and can be modified within the scope of the concept described herein through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art shall not deviate from the spirit and scope of the present invention, and shall be within the scope of protection of the claims attached to the present invention.
Claims
1. An ultra-lightweight image segmentation method based on Mamba, characterized in that: include: S1. Obtain original images, preprocess the original images to obtain original image sets, and divide the original images into training sets, verification sets, and test sets according to set ratios; S2. Build an ultra-lightweight image segmentation model based on Mamba; The Mamba-based ultra-lightweight image segmentation model mainly consists of an encoder, a decoder, and a skip connection between the encoder and the decoder; The encoder includes a first residual convolution module, a second residual convolution module, a first parallel convolution module and a second parallel convolution module, the decoder includes a convolution module, a first parallel vision module, a second parallel vision module and a third parallel vision module, the jump connection performs multi-level and multi-scale information fusion through an attention mechanism module, and the attention mechanism module is mainly composed of a spatial attention mechanism submodule and a channel attention mechanism submodule; The first residual convolution module and the second residual convolution module have the same structure, mainly consisting of three parallel convolution layers. The first parallel convolution module and the second parallel convolution module have the same structure, mainly consisting of four parallel layers, each parallel layer mainly consisting of three residual connected branches, the first branch consists of a visual state space block and a jump connection, the second branch consists of a standard convolution with a convolution kernel of 3 and a jump connection, and the third branch consists of a standard convolution with a convolution kernel of 5 and a jump connection; The first parallel vision module, the second parallel vision module and the third parallel vision module have the same structure, and are mainly composed of four parallel layers, each parallel layer is mainly composed of a visual state space block and a jump connection, the visual state space block is mainly composed of two branches, the first branch is mainly composed of a linear layer and a SiLU activation function, and the second branch is mainly composed of a linear layer, a deep convolution, a SiLU activation function, a state space model and a layer normalization layer, and finally the two branches are merged by element-by-element multiplication to output; S3, using the original images in the training set and the validation set as inputs of the Mamba-based ultra-lightweight image segmentation model, and performing image segmentation training on the Mamba-based ultra-lightweight image segmentation model; S4. Input the original image in the test set into the trained Mamba-based ultra-lightweight image segmentation model to obtain the image segmentation result.
2. The ultra-lightweight image segmentation method based on Mamba according to claim 1, characterized in that: S3 specifically includes: Encoder training process: The original image is input into the 3×3 convolution layer and 5×5 convolution layer of the first residual convolution module respectively to obtain the corresponding two branch results, and then the two branch results are merged to obtain the first feature map. Then the original image is input into the 1×1 convolution layer of the first residual convolution module to obtain the feature map and fuse it with the first feature map. After fusion, the second feature map is output, and the second feature map is input into the second residual convolution module. The second residual convolution module outputs the third feature map.
3. The ultra-lightweight image segmentation method based on Mamba according to claim 2, characterized in that: The encoder training process also includes: The third feature map with the number of channels C is input into the layer normalization layer of the first parallel convolution module, and then is divided into four corresponding feature maps with the number of channels C / 4. Then, each corresponding feature map is input into each parallel layer respectively, and the outputs of the three residual connected branches in the parallel layer are spliced and adjusted to obtain three corresponding feature maps. The three corresponding feature maps of each branch are added together to obtain four intermediate feature maps with the number of channels C / 4. The four intermediate feature maps with the number of channels C / 4 are combined into a fourth feature map with the number of channels C through splicing operations. Finally, the fifth feature map is output through layer normalization layers and projection operation layers respectively.
4. The Mamba-based ultra-lightweight image segmentation method according to claim 1, characterized in that: S3 specifically includes: Decoder training process: The feature map with the number of channels C output by the encoder is input into the layer normalization layer of the third parallel vision module, and then divided into four corresponding feature maps with the number of channels C / 4. Then each feature is input into VSSBlock respectively, and then residual splicing and adjustment factors are performed. The feature map with the number of channels C is obtained by splicing the feature maps, and then the corresponding feature maps are output through the layer normalization layer and the projection operation layer respectively. The corresponding feature map is input into the convolution module with the convolution kernel of 1, and the segmented image is output.
5. The ultra-lightweight image segmentation method based on Mamba according to claim 1, characterized in that: The skip connection uses the attention mechanism to perform multi-level and multi-scale information fusion, including: First, the feature map is input into the spatial attention mechanism submodule, and the maximum pooling and average pooling are performed respectively. Then, the two pooling results are spliced along the channel dimension, and then the convolution layer is used for convolution operation. Then, the output result is limited to the range of [0, 1] through the Sigmoid activation function. Finally, the input feature map is multiplied by the result and then added to the input feature map to obtain the spatial attention feature map.
6. The Mamba-based ultra-lightweight image segmentation method according to claim 5, characterized in that: The skip connection uses the attention mechanism to perform multi-level and multi-scale information fusion, which also includes: The spatial attention feature map is used as the input of the channel attention mechanism submodule. The input feature map is globally averaged pooled through the channel attention mechanism submodule. The spatial dimension of the input feature map is compressed through adaptive pooling to retain the channel information. The global attention weight is calculated using one-dimensional convolution. The attention weight of each channel is calculated using a fully connected layer or a convolutional layer. The Sigmoid activation function is then used to limit the attention weight to the range of [0, 1]. The calculated attention weight is applied to the corresponding input feature map, and the final attention feature map is returned after being concatenated with the input feature map.
7. A computer device comprising a memory, wherein the memory stores program instructions, characterized in that: When the program instructions are executed, the Mamba-based ultra-lightweight image segmentation method as described in any one of claims 1 to 6 is executed.
