Small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion
By adopting a dual attention mechanism and a multi-scale fusion small sample method in medical image segmentation, and using self-attention and cross-attention modules to align medical image features, the segmentation problem of the complexity and diversity of medical images is solved, and the segmentation efficiency is improved. accuracy and performance.
Patent Information
- Application Number
- CN202410733380.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-06-07
AI Technical Summary
Existing medical image segmentation methods suffer from poor quality and prediction bias when processing complex and diverse medical images, making it difficult to effectively analyze the differences in size, shape, and location of human organs.
A small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion is used to extract feature images through a convolutional neural network, and use self-attention and cross-attention modules to align the foreground features of the support sample and query sample, combined with the prototype method and cosine similarity calculation to reduce intra-class gaps and improve segmentation accuracy.
It improves the accuracy of medical image segmentation, eliminates useless features, enhances the focus on category features, effectively solves the segmentation problem with large intra-class gaps, and improves the performance of medical image segmentation.
Smart Images

Figure CN118334045B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of pattern recognition technology and computer vision, in particular to a medical image segmentation method based on small samples. Background Art
[0002] In medical scenarios, both diagnosis and treatment rely heavily on the analysis of medical images. Currently, the image analysis of medical images mainly relies on the human experience of doctors, which is inefficient. Introducing image segmentation methods into the segmentation scenarios of medical images is of great help to the automated analysis of medical images and is also conducive to the development of smart medicine. At present, most medical image segmentation methods rely on prototype networks. However, compared with other industrial images, medical images are more complex and diverse. The size, shape, and position of human tissues and organs vary from person to person, and different types of medical images are also different, resulting in poor quality of supporting prototypes and serious prediction bias. Therefore, it is necessary to pay attention to the interaction between the effective information of support and query samples, and align the foreground features of query samples and support samples through interaction in the feature extraction stage. Summary of the invention
[0003] The purpose of the present invention is to propose a small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion to better align the foreground features of supporting samples and query samples and improve the accuracy of query sample segmentation.
[0004] The technical solution to achieve the purpose of the present invention is: a small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion, which specifically includes the following steps:
[0005] Step 1: Use convolutional neural network model As a feature extractor, the medical sample image is used as the feature extractor input to extract and Feature maps at two scales, where medical sample images are divided into support samples and query samples;
[0006] Step 2: construct a small sample medical image segmentation model to process two feature maps of different scales respectively; The feature map of is processed according to the small sample prototype method, and the cosine similarity between the query feature map and the corresponding support feature prototype is calculated to obtain the predicted query mask 1; The feature map of size uses the attention mechanism method, and the feature map is processed by the self-attention module and the cross-attention module in turn. The self-attention module and the cross-attention module are both composed of an attention layer, a regularization layer, and a connection layer. The inputs of the three branches Q, K, and V of the self-attention module are all compressed query feature matrices, and the output is a query feature matrix of adaptive global features; the input of the Q branch of the cross-attention module is the query feature matrix of adaptive global features, and the inputs of the K and V branches are the compressed support image foreground feature matrices, and the output is a query feature matrix with accurate category features; the query feature matrix with accurate category features is decompressed and restored Size, calculate the cosine similarity with the corresponding supporting feature prototype to obtain the predicted query mask 2;
[0007] Step 3: restore the predicted query mask 1 and the predicted query mask 2 to the original image size, calculate the cross entropy error with the real mask respectively, add them together to get the total error of model training, and use the total error as the loss function for model training;
[0008] Step 4: In the prediction phase, use the test image set The support samples and query sample instances in the predicted query mask 1 and query mask 2 are restored to the original image size through the decoder, and then the coefficients are used to Combined to get the final prediction result.
[0009] Further, step 1, using convolutional neural network model As a feature extractor, the medical sample image is used as the feature extractor input to extract and The feature maps of two scales are expressed as:
[0010] , ,
[0011] , ,
[0012] in and are support samples and query samples respectively, c is the feature dimension, represents the feature extractor, and Respectively The query feature graph and support feature graph of and Respectively The query feature graph and support feature graph of .
[0013] Furthermore, in step 2, a small sample medical image segmentation model is constructed to process feature maps of two different scales respectively. The specific method is as follows:
[0014] 1) Yes The feature map of is processed according to the small sample prototype method, and the query feature map and the corresponding supporting feature prototype P 32 Perform cosine similarity calculation to obtain the predicted query mask 1 ;
[0015] The supporting feature prototype P is obtained by mask average pooling 32 , expressed as:
[0016] ,
[0017] in represents dot product, represents the true support mask after downsampling;
[0018] The query feature map and the corresponding supporting feature prototype P 32 Perform cosine similarity calculation to obtain the similarity score S 32 , compared with the learnable threshold, the predicted query mask is obtained. ;
[0019] ,
[0020] ,
[0021] ,
[0022] in is the spatial position of the mask, is the scaling factor, express Activation function, T is the learnable threshold, using the learning function Learn to obtain the query feature graph and learn the function There are two convolutional layers and one Function of the layer;
[0023] 2) Yes The feature map of size uses the attention mechanism method. The feature map passes through the self-attention module and the cross-attention module successively. Among them, the inputs of the three branches Q, K, and V of the self-attention module are all compressed query feature matrices , By query feature graph use The function is compressed and output after the self-attention layer:
[0024] ,
[0025] ,
[0026] in ,
[0027] Self-attention layer output Enter the feedforward network , feed-forward network It is a two-layer fully connected layer, and the activation function of the first layer is , the second layer does not use the activation function, and we get:
[0028]
[0029] in is the weight of the first fully connected layer, is the weight of the second fully connected layer;
[0030] Output of the feedforward network Regularize it and get;
[0031] ;
[0032] in represents the regularization parameter;
[0033] In the cross-attention module, the input of the Q branch is the query feature matrix of the adaptive global feature , the input of K and V branches is the compressed support image foreground feature matrix , Support feature map and the true support mask after downsampling Using compression function Compression obtained;
[0034]
[0035] Compressed support image foreground feature matrix Output after the cross attention layer:
[0036] ,
[0037] ,
[0038] in is the training weight of the criss-cross attention module;
[0039] Output after the cross attention layer Enter the fully connected layer of forward propagation, regularize and decompress in turn to obtain the query feature output , with supporting feature prototypes Calculate the predicted query mask 2 ;
[0040] ,
[0041] ,
[0042] ,
[0043] .
[0044] Further, in step 3, the predicted query mask 1 and the predicted query mask 2 are restored to the original image size to obtain and , at image position (h, w) and Respectively with the real mask Calculate the cross entropy error and add it up to get the total error of model training , the model is trained with the total error as the loss function, which is expressed as:
[0045] ,
[0046] in are the height and width of the medical sample image.
[0047] Further, in step 4, in the prediction phase, the test image set is used The predicted query mask is obtained by combining the support samples and query sample instances in and predicted query mask 2 , respectively restored to the original image size through the decoder , and then through the coefficient The final prediction result is obtained by summing , expressed as:
[0048] .
[0049] A small sample medical image segmentation system based on dual attention mechanism and multi-scale fusion implements the small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion to achieve small sample medical image segmentation based on dual attention mechanism and multi-scale fusion.
[0050] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the small sample medical image segmentation method based on the dual attention mechanism and multi-scale fusion is implemented to achieve small sample medical image segmentation based on the dual attention mechanism and multi-scale fusion.
[0051] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion is implemented to achieve small sample medical image segmentation based on dual attention mechanism and multi-scale fusion.
[0052] Compared with the prior art, the present invention has the following significant advantages: it applies the classic attention idea in deep learning, makes the sample more focused on the characteristics of the category through self-attention and cross-attention mechanisms, eliminates useless features, and solves the segmentation problem with large intra-class differences. The model is divided into two scales and different processing methods are used. The original feature values extracted are fully retained through the prototype method, so that the limitations of the attention mechanism will not interfere with the results. The above method increases the accuracy of medical image segmentation. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 This is a flow chart of the small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion.
[0054] Figure 2 This is the architecture diagram of the self-attention mechanism.
[0055] Figure 3 This is the architecture diagram of the cross-attention mechanism. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0057] The present invention is based on a small sample medical image segmentation method with dual attention mechanism and multi-scale fusion. In the process of learning sample to category attribute mapping, the single-scale feature similarity calculation is divided into the calculation combination of different feature scales. Self-attention mechanism and cross-attention mechanism are applied to one scale, so that the sample can focus on the intra-class features on the original basis. The other scale is used to maintain the original feature information and fuse it with the enhanced features to achieve the purpose of performance improvement.
[0058] Figure 1This is a flowchart of a small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion. Medical image samples are extracted through pre-trained image feature convolutional neural network. Extract support image and query image features of different scales, respectively and .in The feature image uses the attention mechanism, The feature image uses the prototype mechanism. Both methods use the similarity index threshold to get the predicted query mask, and the coefficient Combine to get the final result.
[0059] Figure 2 The following is a specific architecture diagram of the self-attention mechanism. The self-attention mechanism consists of an attention layer, a fully connected layer, and a regularization layer. The three inputs of K, V are all compressed one-dimensional query feature matrices, and the query feature matrix of adaptive global features is output as Then input the cross attention module.
[0060] Figure 3 The specific architecture diagram of the cross attention mechanism is shown in Figure 2. The support feature map is multiplied by the support mask to obtain the support foreground feature map. The compressed support foreground feature matrix is used as , Combined with the above Input is a criss-cross attention module, and output is a query feature matrix with interactive segmentation features.
[0061] 1. Data processing
[0062] The present invention is based on a medical image dataset, which is divided into a training set and test set Each set contains multiple sample combinations, among which and Represents the number of combinations of two sets. Each combination includes a supporting image sample with the same organ information and a query image sample , and the true mask of the corresponding organ of the above sample , the few-shot task predicts the segmentation of the query image based on the support images and their corresponding ground-truth masks (knowledge of the segmentation labels). The support masks are used during training. and query mask , only support masks can be used during prediction .
[0063] 2. Training phase
[0064] 2.1 Dual-scale original feature extraction
[0065] Using a pre-trained convolutional neural network model As a feature extractor , extract image features of different scales. and They are from The support samples and query sample instances are as follows, and c is the feature dimension.
[0066] , ,
[0067] , ,
[0068] 2.2 Prototype Mechanism
[0069] The feature maps of this scale are processed using a simple prototype mechanism, where the prototype mechanism uses the downsampled true support mask , distinguish the foreground and background of the supporting feature image category, and obtain the supporting feature prototype P 32 , to prevent interference from background images. Specifically, it is achieved through masked average pooling, where express (Dot product):
[0070] ,
[0071] Then we will query the feature map With the support feature prototype P 32 Perform cosine similarity calculation to obtain the similarity score S 32 , compared with the learnable threshold T, the predicted query mask is obtained :
[0072] ,
[0073] ,
[0074] in
[0075] in is the spatial position of the mask, is the scaling factor, express Activation function, is a learnable threshold, using the learning function The query feature graph is learned and acquired. Specifically, There are two convolutional layers and one The function of the layer, is its parameter.
[0076] 2.3 Attention Mechanism
[0077] The feature map uses the attention mechanism method, which is divided into self-attention module and cross-attention module. Each module consists of an attention layer, a regularization layer, and a connection layer.
[0078] 1) Self-attention module
[0079] First, the original query feature map pass Function compressed into a two-dimensional matrix , and then enter the self-attention module. This module uses only the query feature matrix to extract important global features of the query image. as input.
[0080]
[0081] in ,
[0082] in, is the training weight of the self-attention module. The self-attention layer output is obtained , and then enter the feedforward network , is a two-layer fully connected layer, and the activation function of the first layer is , the second layer does not use an activation function. is the weight of the first fully connected layer, is the weight of the second fully connected layer.
[0083]
[0084]
[0085] Regularization after the feed-forward network Get the output of the self-attention module , the results and Compressed support image foreground feature matrix They are jointly used as the input of the criss-cross attention module.
[0086] 2) Cross-Attention Module
[0087] The output of the self-attention module And the support image foreground feature matrix As the input of the criss-cross attention module, The function realizes the compression function, converting the image size to The three-dimensional features are transformed into The two-dimensional features are as follows:
[0088]
[0089] As above, the feature will be supported and the true support mask after downsampling Do the dot multiplication to get the foreground feature, enter the compression function, and get it as input .
[0090] This module will support the interaction between images and query images, extract common features within the class, and solve the problem of large differences within the class. is the output of the self-attention module, are the training weights of the criss-cross attention module.
[0091] ,
[0092] in ,
[0093] Similar to the self-attention module, this layer outputs Enter the fully connected layer of the forward propagation and regularize the output two-dimensional feature matrix , after decompression, the original characteristic scale is restored Similar to the similarity calculation and threshold setting of the prototype mechanism, the attention mechanism outputs the query feature With supporting feature prototypes Calculate the predicted query mask 2 as follows:
[0094]
[0095]
[0096]
[0097] in
[0098] Which supports feature prototypes Supported by features and the true mask After point multiplication, average mask pooling is implemented, which is the same as The method of obtaining is the same.
[0099] 2.4 Error calculation
[0100] The known features are input into the above two methods to obtain the predicted query mask respectively. and , the predicted query masks of these two scales are restored to the original image size through the decoder .
[0101] The model is trained to minimize the cross entropy between the query mask recovered by the decoder and the true mask. and the decoder recovers the query mask 2 Respectively with the real mask Calculate the cross entropy error and add it up to get the total error of model training , the model is trained with the total error as the loss function, where are the original height and width of the medical sample image.
[0102]
[0103] 3. Prediction stage
[0104] After the above training, the model parameters are obtained. In the prediction stage, the test image set is used The predicted query mask is obtained from the support samples and query sample instances in and , the predicted query masks of these two scales are restored to the original image size through the decoder , through the coefficient Combined to get the final prediction result :
[0105]
[0106] The present invention also proposes a small sample medical image segmentation system based on dual attention mechanism and multi-scale fusion, implements the small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion, and realizes small sample medical image segmentation based on dual attention mechanism and multi-scale fusion.
[0107] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the small sample medical image segmentation method based on the dual attention mechanism and multi-scale fusion is implemented to achieve small sample medical image segmentation based on the dual attention mechanism and multi-scale fusion.
[0108] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion is implemented to achieve small sample medical image segmentation based on dual attention mechanism and multi-scale fusion.
[0109] In summary, the present invention extracts features of the query information through a self-attention mechanism, and enhances features of the query information and the support information through a cross-attention mechanism, thereby achieving the distinction between the foreground and background of the query sample itself and the key interaction between the query and the support effective information, and can effectively solve the problem of intra-class differences in medical images. In addition, considering that the attention mechanism will be disturbed by the background information in the sample, the present invention retains the original feature information through another scale, and fuses it with the enhanced features to protect the correctness of the enhanced features. The dual attention mechanism and multi-scale fusion method improves the accuracy of medical image segmentation based on small samples as a whole.
[0110] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0111] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion, characterized in that: The specific steps include: Step 1: Use convolutional neural network model As a feature extractor, the medical sample image is used as the feature extractor input to extract and Feature maps at two scales, where medical sample images are divided into support samples and query samples; Step 2: construct a small sample medical image segmentation model to process two feature maps of different scales respectively; The feature map of is processed according to the small sample prototype method, and the cosine similarity between the query feature map and the corresponding support feature prototype is calculated to obtain the predicted query mask 1; The feature map of size uses the attention mechanism method. The feature map is processed by the self-attention module and the cross-attention module in sequence. The self-attention module and the cross-attention module are both composed of an attention layer, a regularization layer, and a connection layer. The inputs of the three branches Q, K, and V of the self-attention module are all compressed query feature matrices, and the output is the query feature matrix of the adaptive global feature. The input of the Q branch of the cross attention module is the query feature matrix of the adaptive global feature, the input of the K and V branches is the compressed support image foreground feature matrix, and the output is the query feature matrix with accurate category features; the query feature matrix with accurate category features is decompressed and restored Size, calculate the cosine similarity with the corresponding supporting feature prototype to obtain the predicted query mask 2; Step 3: restore the predicted query mask 1 and the predicted query mask 2 to the original image size, calculate the cross entropy error with the real mask respectively, add them together to get the total error of model training, and use the total error as the loss function for model training; Step 4: In the prediction phase, use the test image set The support samples and query sample instances in the predicted query mask 1 and query mask 2 are restored to the original image size through the decoder, and then the coefficients are used to Combined to get the final prediction result.
2. The small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion according to claim 1, characterized in that: Step 1: Use convolutional neural network model As a feature extractor, the medical sample image is used as the feature extractor input to extract and The feature maps of two scales are expressed as: , , , , in and are support samples and query samples respectively. represents the feature extractor, c is the feature dimension, and Respectively The query feature graph and support feature graph of and Respectively The query feature graph and support feature graph of .
3. The small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion according to claim 1, characterized in that: Step 2: Build a small sample medical image segmentation model and process two feature maps of different scales respectively. The specific method is as follows: 1) Yes The feature map of is processed according to the small sample prototype method, and the query feature map and the corresponding supporting feature prototype P 32 Perform cosine similarity calculation to obtain the predicted query mask 1 ; The supporting feature prototype P is obtained by mask average pooling 32 , expressed as: , in represents dot product, represents the true support mask after downsampling; The query feature map and the corresponding supporting feature prototype P 32 Perform cosine similarity calculation to obtain the similarity score S 32 , compared with the learnable threshold, the predicted query mask is obtained. ; , , , in is the spatial position of the mask, is the scaling factor, express Activation function, T is the learnable threshold, using the learning function Learn to obtain the query feature graph and learn the function There are two convolutional layers and one Function of the layer; 2) Yes The feature map of size uses the attention mechanism method. The feature map passes through the self-attention module and the cross-attention module successively. Among them, the inputs of the three branches Q, K, and V of the self-attention module are all compressed query feature matrices , By query feature graph use The function is compressed and output after the self-attention layer: , , in , Self-attention layer output Enter the feedforward network , feed-forward network It is a two-layer fully connected layer, and the activation function of the first layer is , the second layer does not use the activation function, and we get: in is the weight of the first fully connected layer, is the weight of the second fully connected layer; Output of the feedforward network Regularize it and get; ; in represents the regularization parameter; In the cross-attention module, the input of the Q branch is the query feature matrix of the adaptive global feature , the input of K and V branches is the compressed support image foreground feature matrix , Support feature map and the true support mask after downsampling Using compression function Compression obtained; Compressed support image foreground feature matrix Output after the cross attention layer: , , in is the training weight of the criss-cross attention module; Output after the cross attention layer Enter the fully connected layer of the forward propagation, regularize and decompress in turn to obtain the query feature output , with supporting feature prototypes Calculate the predicted query mask 2 ; 。 4. The small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion according to claim 1, characterized in that: Step 3: restore the predicted query mask 1 and predicted query mask 2 to the original image size to obtain and , at image position (h, w) and The real mask Calculate the cross entropy error and add it up to get the total error of model training , the model is trained with the total error as the loss function, which is expressed as: in are the height and width of the medical sample image.
5. The small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion according to claim 1, characterized in that: Step 4: In the prediction phase, use the test image set The predicted query mask is obtained by combining the support samples and query sample instances in and predicted query mask 2 , respectively restored to the original image size through the decoder , and then through the coefficient The final prediction result is obtained by summing , expressed as: 。 6. A small sample medical image segmentation system based on dual attention mechanism and multi-scale fusion, characterized in that: Implement the small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion as described in any one of claims 1-5 to achieve small sample medical image segmentation based on dual attention mechanism and multi-scale fusion.
7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, it implements the small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion described in any one of claims 1-5, and realizes small sample medical image segmentation based on dual attention mechanism and multi-scale fusion.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, the small sample medical image segmentation method based on dual attention mechanism and multi-scale fusion described in any one of claims 1 to 5 is implemented to achieve small sample medical image segmentation based on dual attention mechanism and multi-scale fusion.
Citation Information
Patent Citations
Small sample segmentation method and device based on attention mechanism, terminal and medium
CN116258937A
Small sample segmentation method based on multi-scale self-attention feature fusion
CN116342875A
Medical small sample segmentation method, apparatus and device, and readable storage medium
CN117036684A
Person Re-Identification Method Combining Random Batch Mask and Multi-Scale Representation Learning
JP6830707B1
