Small sample medical image segmentation method based on self-attention mechanism and contrast learning

By combining self-attention mechanism and comparison learning, using a small number of labeled samples for medical image segmentation, the problem of difficulty in obtaining medical image labeled data is solved, high-precision medical image segmentation is achieved, and the generalization ability of the model is improved, and the current situation is overcome. There are limitations in the art that the dependence on labeling samples is too large.

CN118967719AActive Publication Date: 2024-11-15SOUTHEAST UNIV

Patent Information

Application Number
CN202411059017.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-02
Publication Date
2024-11-15
Estimated Expiration
2044-08-02

AI Technical Summary

Technical Problem

Difficulty in obtaining medical image annotation data, resulting in too many denoted samples in medical image segmentation, and insufficient segmentation performance of the model in the case of small samples.

Method used

Combining self-attention mechanism and contrast learning, through MRI data preprocessing and presegmentation, a multi-head attention module and contrast learning framework are constructed, and a small number of labeled samples are used for medical image segmentation, key features are extracted and efficient aggregation is carried out to construct positive samples and negative samples. Sample comparison relationships are used to enhance model generalization capabilities.

Benefits of technology

在少量标注数据下实现高精度医学图像分割,减少了噪声和复杂背景的干扰,提高了模型在小样本场景下的泛化能力和鲁棒性,降低了对标注数据的依赖。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118967719A_ABST
    Figure CN118967719A_ABST
Patent Text Reader

Abstract

The invention discloses a small sample medical image segmentation method based on a self-attention mechanism and comparative learning, and the method comprises the steps: firstly carrying out the preprocessing of the MRI (Magnetic Resonance Imaging) data, and carrying out the pre-segmentation of the processed data; performing mask correction on the pre-segmentation result to obtain a pseudo mask; the pseudo mask and the corresponding medical image are sent to a deep learning network model, model parameters are updated according to the comprehensive loss, and a model training result is saved; and segmenting the new medical image data by using the trained model to obtain a segmentation mask. According to the method, the accuracy of network model learning is improved by correcting the pseudo mask, internal information transmission in a small sample training process is realized and image background information interference is inhibited by adding a self-attention mechanism and contrast learning, and efficient segmentation of the medical image is realized under the condition of limited annotation data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a small sample medical image segmentation method based on a self-attention mechanism and contrastive learning, and belongs to the technical field of medical image processing. Background Art

[0002] With the rapid development of medical imaging technology, medical images have become an important tool for diagnosing, treating and evaluating diseases. As one of the key technologies in the field of image processing, medical image segmentation aims to identify and extract anatomical structures or lesion areas of interest from complex medical images. In recent years, deep learning technology has made significant progress in the field of medical image segmentation, which has greatly promoted the automation and precision of medical imaging diagnosis. Through deep learning, especially the widespread application of convolutional neural networks and their derivative models, the accuracy and efficiency of medical image segmentation have achieved a qualitative leap, which not only reduces the time cost of manual analysis, but also improves the accuracy and consistency of diagnosis.

[0003] However, although deep learning technology has shown great potential in the field of medical image segmentation, the difficulty in obtaining labeled samples is still one of the main factors restricting its further development. The labeling of medical images is usually done manually by experienced radiologists or pathologists. This process is not only time-consuming and laborious, but also requires extremely high professional knowledge and skills of the labelers. In addition, due to the complexity and diversity of medical images, even the same type of lesions may show completely different morphology and characteristics in different patients, which further increases the difficulty and uncertainty of labeling. Therefore, how to reduce the dependence on labeled samples while ensuring model performance is an important problem that deep learning needs to solve in the field of medical image segmentation.

[0004] The attention mechanism is a powerful tool for processing sequence data. It dynamically assigns different weights to different positions in the sequence by simulating the way humans allocate attention when reading or understanding, thereby capturing the dependencies between information more efficiently and accurately. In medical image segmentation, the attention mechanism can enhance the model's sensitivity to key features and help the model ignore irrelevant or redundant information, thereby making more efficient use of limited labeled samples. Contrastive learning is an unsupervised or self-supervised learning method that learns feature representations by comparing the similarities between positive and negative samples. In medical image segmentation, contrastive learning can use limited labeled data to enhance the model's feature extraction capabilities and improve segmentation performance in small sample conditions by constructing positive samples (similar image pairs) and negative samples (dissimilar image pairs). We combine the attention mechanism with contrastive learning, where the attention mechanism helps the model focus on key areas, while contrastive learning enhances the model's ability to understand and generalize lesion features. This combination enables the model to learn effective feature representations and achieve high-precision segmentation under the condition of limited labeled samples. Summary of the invention

[0005] The technical problem to be solved by the present invention is the difficulty in obtaining medical image annotation data. It also overcomes multiple limitations in existing methods and provides a small sample medical image segmentation method based on self-attention mechanism and contrastive learning, which can achieve medical image segmentation using only a small number of annotated samples.

[0006] In order to achieve the above object, the technical solution of the present invention is:

[0007] A small sample medical image segmentation method based on self-attention mechanism and contrastive learning, comprising the following steps:

[0008] (1) MRI data preprocessing and pre-segmentation: To adapt to the model input, the image data is reformatted into two dimensions and resized to 256 × 256 pixels. Each two-dimensional slice is replicated three times in the channel dimension and pre-segmented using an unsupervised image segmentation algorithm to obtain a rough pseudo mask.

[0009] (2) Acquisition of pseudo-mask: Correct the rough pseudo-mask obtained by pre-segmentation and remove the erroneous areas to obtain the pseudo-mask;

[0010] (3) Constructing a deep learning network model: The feature extraction network used is ResNet-101 pre-trained on the MS-COCO dataset, where the classifier is replaced by a 1×1 convolutional layer. A multi-head attention module is added to the back of the model to transfer information between features and build contrastive learning between the foreground and background of the query image;

[0011] (4) Model training process: The total number of iterations of the model is preset. In each iteration, two MRI images are taken out, which are called support images and query images respectively. The two images are sent to the network model to extract features. The prototype of the support feature is taken out according to the pseudo mask of the support image. The query feature is segmented using the support prototype. The query feature segmentation result and the query image pseudo mask are calculated by back propagation to update the network model. After the iteration, the model parameters are saved.

[0012] (5) Model testing process: The model is loaded with the model parameters obtained in step (4), a new image is taken out as the support image, and the remaining images are used as query images. The support image is sent into the model to obtain the prototype, and the prototype is used to segment all query images to obtain the segmentation results.

[0013] Specifically, the steps for correcting the rough pseudo-mask obtained by pre-segmentation in step (2) are as follows: create a Boolean array B of the same size as the pseudo-mask to track the visited pixels, and initialize the size of the largest connected area in the mask to C = 0. Traverse each pixel in the pseudo-mask, and for unvisited pixels marked as 1, perform a breadth-first search on the entire pseudo-mask starting from the pixel. If the connected area found is larger than the current maximum value C max , then update the maximum connected area and record the pixel in B. After traversing all pixels, retain the maximum connected area C max , create a new array M of the same size as the rough pseudo mask, and put the largest connected area C in M max The corresponding position is marked as 1 to obtain the corrected pseudo mask.

[0014] Specifically, the step (3) of using the multi-head attention model to transfer feature information is as follows: first, the input support image and query image are processed through the feature extraction network respectively to obtain their respective feature representations. This process can be expressed as:

[0015] F s =f θ (I s )

[0016] F q =f θ (I q )

[0017] Among them, I s and I q represent the support image and query image respectively, and f θ represents the mapping function of the feature extraction network, F s and F q are the extracted support features and query features. Next, we will query feature F qSend it to self-attention for encoding. The self-attention mechanism allows the model to dynamically pay attention to other parts of the feature when processing the query feature, thereby capturing the dependencies between elements. Its calculation formula is as follows:

[0018] Q = Attention(F q W q Q ,F q W q K ,F q W q V )

[0019]

[0020] Where W q Q , W q K , W q V is for the query feature F q The linear transformation matrix is ​​used to generate the query (Q = F q W q Q ), key (K=F q W q K ) and value (V=F q W q V ) vector. The Attention function is the core calculation process of the self-attention mechanism, and its output Q q represents the enhanced query features, K T and d k denote the transpose and dimension of the key vector, respectively. Next, we calculate the similarity between the key (K) of the support feature and the query (Q) of the query feature, and apply the softmax function for normalization to generate the attention weights. Here, we use softmax(dim=-2) to ensure that the sum of the similarity scores of each column of the result (corresponding to each support pixel) is 1, allowing the support features to aggregate toward the query features. Subsequently, we multiply the attention weights by the pseudo mask of the support image to filter out irrelevant areas. Finally, the filtered attention weights are multiplied by the value (V) of the support image to achieve feature aggregation. This process can be expressed as:

[0021]

[0022] F' q = attn·V s

[0023] Among them, Ks T represents the transposition of the support key, ⊙ represents element-wise multiplication, M s is a pseudo mask of the support image, used to filter out irrelevant areas, attn is the intermediate result, F q ' is the result of aggregating the support feature information into the query feature. The subscripts q and s represent the query image and the support image, respectively.

[0024] Finally, we send the aggregated query features into a module consisting of residual connections, multi-layer perceptrons, and residual connections again to obtain the final aggregated query features. This process efficiently aggregates key feature information from the support set to the query set through a one-way information transmission strategy, avoiding the problem of information misleading caused by inaccurate prediction masks of query images. The specific formula is as follows:

[0025] O q =LN(attn·V+Q)

[0026] O out =LN(MLP(O q )+O q )

[0027] Among them, LN represents layer normalization, MLP represents multi-layer perceptron, and O q represents the intermediate query feature, O out is the final query feature,

[0028] Specifically, the query image foreground-background contrast learning steps in step (3) are as follows:

[0029] First, we use the Masked Average Pooling (MAP) technique to extract the support prototype representing the foreground features from the labeled support image. s The calculation formula is as follows:

[0030] P s =MAP(F s ,M s )

[0031] Next, we use the cosine similarity between these support prototypes and the query features to generate the query mask and then extract the query prototype P q The calculation of cosine similarity and the extraction of query prototypes help us preliminarily screen out the areas in the query image that may be related to the foreground. In order to distinguish the complex background area, we first negate the support image mask to obtain Then the background features corresponding to the supporting features are taken out and expressed as F s b, using the Voronoi-based method Divide and obtain the background area mask set Here B n represents the nth background region, R is the number of regions, which is set to 150. The formula for extracting different region representations is as follows:

[0032]

[0033] Among them, P n represents the prototype of the nth region, H and W represent The height and width of and B n,i Denote the i-th pixel corresponding to the supporting feature and the background area respectively. In the contrastive learning framework we constructed, the query prototype is used as the anchor point, the supporting prototype is used as the positive sample, and multiple partition prototypes of the background area constitute the negative sample set. Each negative sample represents a different part of the background area, thus providing rich background information for the model.

[0034] Specifically, in step (4), the total number of iterations of the model is set to 50,000. The loss of the model includes the use of cross entropy loss to directly measure the similarity between the predicted probability distribution and the true mask distribution. For each pixel, the cross entropy loss is The calculation formula is:

[0035]

[0036] Among them, M q represents the ground-truth mask of the query image, and They represent the query image background and foreground masks predicted by the model, respectively.

[0037] In addition, a threshold loss is added to the model Where T is the segmentation threshold, α is the adjustment parameter, which is set to 20 by default. By minimizing the learning threshold, the foreground features are encouraged to be more compact in the embedding space. In addition, the foreground-background contrast loss is proposed. The segmentation performance of the model is optimized by maximizing the similarity between the query prototype and the support prototype while minimizing the similarity with the background negative sample. The mathematical expression is:

[0038]

[0039] Among them, cos(·) is the cosine similarity function. It is worth noting that the corrected mask background area occupies the majority, so The loss can effectively use a large number of negative samples to optimize the model. Add up to get the total loss The calculation formula is as follows:

[0040] Specifically, in step (5), the model testing process steps are as follows: In the testing phase, a set of medical images that have not been used in the training process are used for segmentation. The test image is divided into a support image and a query image, where the support image contains only one sample with precise annotations. The support and query features are extracted using the model obtained in the training phase, and then the support image features are transferred to the query image features using the attention mechanism. The support image pseudo mask M is used s From the support feature F s Extract the supporting prototype P s Finally, with the help of the extracted supporting feature prototype, the query feature F q Segmentation is performed to obtain the segmentation result. Specifically, the attention mechanism enables the model to accurately focus on the key features in the image, while contrastive learning strengthens the model's feature learning and generalization capabilities. The synergy of the two greatly improves the model's representation capabilities. Since the trained model has fully learned the ability to extract key features from a small amount of data and generalize effectively, when faced with new data in the test phase, the model only needs to rely on one labeled sample to achieve accurate segmentation of the target organ.

[0041] Compared with the prior art, the beneficial effects of the present invention are as follows: the present invention provides a small sample medical image segmentation method based on self-attention mechanism and contrastive learning, which can realize the segmentation of medical images with a small amount of annotated data; the proposed mask correction method removes the noise and error areas accompanied by the pseudo-mask, and provides a more accurate mask for subsequent model learning; the attention mechanism is used to realize one-way information transmission, that is, only the key feature information is efficiently aggregated from the support feature to the query feature, avoiding the information misleading problem caused by the inaccurate prediction mask of the query image; the foreground-background contrast learning aims to enable the model to learn more discriminative feature representations under limited data by constructing the contrast relationship between positive samples (foreground areas) and negative samples (background areas). This method effectively overcomes the model training difficulties caused by less data annotation, improves the generalization ability and robustness of the model in the small sample medical image segmentation scenario, reduces the interference of image noise and complex background, solves the problem of poor segmentation effect of deep learning models in a small number of sample scenarios, and provides new ideas and directions for research in the field of small sample medical image segmentation. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 It is a schematic diagram of the overall process of the present invention;

[0043] Figure 2 This is a deep learning segmentation network training flow chart of the present invention;

[0044] Figure 3 This is a flow chart of the present invention in the testing phase;

[0045] Figure 4 It is a schematic diagram of the segmentation result of the present invention. DETAILED DESCRIPTION

[0046] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0047] Example: Figure 1 The overall flow chart of a small sample medical image segmentation method based on self-attention mechanism and contrastive learning provided in this embodiment includes the following steps:

[0048] (1) MRI data preprocessing and pre-segmentation: To adapt to the model input, the image data is reformatted into two dimensions and resized to 256 × 256 pixels. Each two-dimensional slice is replicated three times in the channel dimension and pre-segmented using an unsupervised image segmentation algorithm to obtain a rough pseudo mask.

[0049] (2) Acquisition of pseudo-mask: Correct the rough pseudo-mask obtained by pre-segmentation and remove the erroneous areas to obtain the pseudo-mask;

[0050] (3) Constructing a deep learning network model: The feature extraction network used is ResNet-101 pre-trained on the MS-COCO dataset, where the classifier is replaced by a 1×1 convolutional layer. A multi-head attention module is added to the back of the model to transfer information between features and build contrastive learning between the foreground and background of the query image;

[0051] (4) Model training process: The total number of iterations of the model is preset. In each iteration, two MRI images are taken out, which are called support images and query images respectively. The two images are sent to the network model to extract features. The prototype of the support feature is taken out according to the pseudo mask of the support image. The query feature is segmented using the support prototype. The query feature segmentation result and the query image pseudo mask are calculated by back propagation to update the network model. After the iteration, the model parameters are saved.

[0052] (5) Model testing process: The model is loaded with the model parameters obtained in step (4), a new image is taken out as the support image, and the remaining images are used as query images. The support image is sent into the model to obtain the prototype, and the prototype is used to segment all query images to obtain the segmentation results.

[0053] like Figure 2 As shown in FIG. 1 , the steps for correcting the rough pseudo mask obtained by pre-segmentation in step (2) are as follows: Create a Boolean array B of the same size as the pseudo mask to track the visited pixels, and initialize the size of the largest connected area in the mask to C = 0. Traverse each pixel in the pseudo mask, and for unvisited pixels marked as 1, perform a breadth-first search on the entire pseudo mask starting from the pixel. If the connected area found is larger than the current maximum value C max , then update the maximum connected area and record the pixel in B. After traversing all pixels, retain the maximum connected area C max , create a new array M of the same size as the rough pseudo mask, and put the largest connected area C in M max The corresponding position is marked as 1 to obtain the corrected pseudo mask.

[0054] like Figure 2 As shown, the step (3) of using the multi-head attention model to transfer feature information is as follows: first, the input support image and query image are processed through the feature extraction network respectively to obtain their respective feature representations. This process can be expressed as:

[0055] F s =f θ (I s )

[0056] F q =f θ (I q )

[0057] Among them, I s and I q represent the support image and query image respectively, and f θ represents the mapping function of the feature extraction network, F s and F q are the extracted support features and query features. Next, we will query feature F q Send it to self-attention for encoding. The self-attention mechanism allows the model to dynamically pay attention to other parts of the feature when processing the query feature, thereby capturing the dependencies between elements. Its calculation formula is as follows:

[0058] Q = Attention(F q W q Q ,F q W q K ,F q W q V )

[0059]

[0060] Where W q Q , W q K , W q V is for the query feature F q The linear transformation matrix is ​​used to generate the query (Q = F q W q Q ), key (K=F q W q K ) and value (V=F q W q V ) vector. The Attention function is the core calculation process of the self-attention mechanism, and its output Q q represents the enhanced query features, K T and d k denote the transpose and dimension of the key vector, respectively. Next, we calculate the similarity between the key (K) of the support feature and the query (Q) of the query feature, and apply the softmax function for normalization to generate the attention weights. Here, we use softmax(dim=-2) to ensure that the sum of the similarity scores of each column of the result (corresponding to each support pixel) is 1, allowing the support features to aggregate toward the query features. Subsequently, we multiply the attention weights by the pseudo mask of the support image to filter out irrelevant areas. Finally, the filtered attention weights are multiplied by the value (V) of the support image to achieve feature aggregation. This process can be expressed as:

[0061]

[0062] F' q = attn·V s

[0063] in, represents the transposition of the support key, ⊙ represents element-wise multiplication, M s is a pseudo mask of the support image, used to filter out irrelevant areas, attn is the intermediate result, F q ' is the result of aggregating the support feature information into the query feature, and the subscripts q and s represent the query image and the support image, respectively.

[0064] Finally, we send the aggregated query features into a module consisting of residual connections, multi-layer perceptrons, and residual connections again to obtain the final aggregated query features. This process efficiently aggregates key feature information from the support set to the query set through a one-way information transmission strategy, avoiding the problem of information misleading caused by inaccurate prediction masks of query images. The specific formula is as follows:

[0065] O q =LN(attn·V+Q)

[0066] O out =LN(MLP(O q )+O q )

[0067] Among them, LN represents layer normalization, MLP represents multi-layer perceptron, and O q represents the intermediate query feature, O out is the final query feature.

[0068] like Figure 2 As shown, the query image foreground and background contrast learning steps in step (3) are as follows:

[0069] First, we use the Masked Average Pooling (MAP) technique to extract support prototypes representing foreground features from the labeled support images. s The calculation formula is as follows:

[0070] P s =MAP(F s ,M s )

[0071] Next, we use the cosine similarity between these support prototypes and the query features to generate the query mask and then extract the query prototype P q The calculation of cosine similarity and the extraction of query prototypes help us preliminarily screen out the areas in the query image that may be related to the foreground. In order to distinguish the complex background area, we first negate the support image mask to obtain Then the background features corresponding to the supporting features are taken out and expressed as F s b The Voronoi-based method is used to Divide and obtain the background area mask set Here B n represents the nth background region, R is the number of regions, and is set to 150. The formula for extracting different region representations is as follows:

[0072]

[0073] Among them, P n represents the prototype of the nth region, H and W represent The height and width of and B n,i Denote the support feature and the background area corresponding to the i-th pixel respectively. In the contrastive learning framework we constructed, the query prototype is used as the anchor point, the support prototype is used as the positive sample, and multiple partition prototypes of the background area constitute the negative sample set. Each negative sample represents a different part of the background area, thus providing rich background information for the model.

[0074] like Figure 2 As shown in step (4), the model loss includes the use of cross entropy loss to directly measure the similarity between the predicted probability distribution and the true mask distribution. For each pixel, its cross entropy loss The calculation formula is:

[0075]

[0076] Among them, M q represents the ground-truth mask of the query image, and They represent the query image background and foreground masks predicted by the model, respectively.

[0077] In addition, a threshold loss is added to the model Where T is the segmentation threshold and α is the adjustment parameter, which is set to 20 by default. By minimizing the learning threshold, the foreground features are encouraged to be more compact in the embedding space. In addition, the foreground-background contrast loss is proposed. The segmentation performance of the model is optimized by maximizing the similarity between the query prototype and the support prototype while minimizing the similarity with the background negative sample. The mathematical expression is:

[0078]

[0079] Among them, cos(·) is the cosine similarity function. It is worth noting that the corrected mask background area occupies the majority, so The loss can effectively use a large number of negative samples to optimize the model. Add up to get the total loss The calculation formula is as follows:

[0080] like Figure 3As shown in Figure 5, in step (5), the model testing process is as follows: In the testing phase, a set of medical images that have not been seen in the training process are used for segmentation. The test images are divided into support images and query images, where the support image contains only one sample with precise annotations. The model obtained in the training phase is used to extract support and query features, and then the support image features are transferred to the query image features using the attention mechanism. The support image pseudo mask M is used to extract the support and query features. s From the support feature F s Extract the supporting prototype P s Finally, with the help of the extracted supporting feature prototype, the query feature F q Segmentation is performed to obtain the segmentation result. Specifically, the attention mechanism enables the model to accurately focus on the key features in the image, while contrastive learning strengthens the model's feature learning and generalization capabilities. The synergy of the two greatly improves the model's representation ability. Since the trained model has fully learned the ability to extract key features from a small amount of data and generalize effectively, when faced with new data in the test phase, the model only needs to rely on one labeled sample to achieve accurate segmentation of the target organ. The detailed segmentation results are as follows: Figure 4 shown.

[0081] It should be noted that the above embodiments are not intended to limit the protection scope of the present invention, and equivalent changes or substitutions made on the basis of the above technical solutions all fall within the protection scope of the claims of the present invention.

Claims

1. A small sample medical image segmentation method based on self-attention mechanism and contrastive learning, characterized in that: The method comprises the following steps: (1) MRI data preprocessing and pre-segmentation: To adapt to the model input, the image data is reformatted into two dimensions and resized to 256 × 256 pixels. Each two-dimensional slice is replicated three times in the channel dimension and pre-segmented using an unsupervised image segmentation algorithm to obtain a rough pseudo mask. (2) Acquisition of pseudo-mask: Correct the rough pseudo-mask obtained by pre-segmentation and remove the erroneous areas to obtain the pseudo-mask; (3) Constructing a deep learning network model: The feature extraction network used is ResNet-101 pre-trained on the MS-COCO dataset, where the classifier is replaced by a 1×1 convolutional layer. A multi-head attention module is added to the back of the model to transfer information between features and build contrastive learning between the foreground and background of the query image; (4) Model training process: The total number of iterations of the model is preset. In each iteration, two MRI images are taken out, which are called support images and query images respectively. The two images are sent to the network model to extract features. The prototype of the support feature is taken out according to the pseudo mask of the support image. The query feature is segmented using the support prototype. The query feature segmentation result and the query image pseudo mask are calculated by back propagation to update the network model. After the iteration, the model parameters are saved. (5) Model testing process: The model is loaded with the model parameters obtained in step (4), a new image is taken out as the support image, and the remaining images are used as query images. The support image is sent into the model to obtain the prototype, and the prototype is used to segment all query images to obtain the segmentation results.

2. The small sample medical image segmentation method based on self-attention mechanism and contrastive learning according to claim 1, characterized in that: The steps for correcting the rough pseudo-mask obtained by pre-segmentation in step (2) are as follows: create a Boolean array B of the same size as the pseudo-mask to track the visited pixels, initialize the size of the largest connected area in the mask to C = 0, traverse each pixel in the pseudo-mask, and for unvisited pixels and the pixel is marked as 1, perform a breadth-first search on the entire pseudo-mask starting from the pixel. If the connected area found is larger than the current maximum value C max , then update the maximum connected area and record the pixel point in B. After traversing all pixels, retain the maximum connected area C max , create a new array M of the same size as the rough pseudo mask, and put the largest connected area C in M max The corresponding position is marked as 1 to obtain the corrected pseudo mask.

3. The small sample medical image segmentation method based on self-attention mechanism and contrastive learning according to claim 1, characterized in that: The steps of using the multi-head attention model to transfer feature information in step (3) are as follows: first, the input support image and query image are processed through the feature extraction network respectively to obtain their respective feature representations. This process is expressed as: F s =f θ (I s ) F q =f θ (I q ) Among them, I s and I q represent the support image and query image respectively, and f θ represents the mapping function of the feature extraction network, F s and F q are the extracted support features and query features. Next, the query feature F q The self-attention mechanism is sent to be encoded. The self-attention mechanism allows the model to dynamically pay attention to other parts of the feature when processing the query feature, thereby capturing the dependency between elements. The calculation formula is as follows: in is for the query feature F q The linear transformation matrix is ​​used to generate the query key Sum vector, the Attention function is the core calculation process of the self-attention mechanism, and its output Q q represents the enhanced query features, K T and d k Represent the transpose and dimension of the key vector respectively. Next, the similarity between the key K of the support feature and the query Q of the query feature is calculated, and the softmax function is applied for normalization to generate the attention weight. Softmax (dim = -2) is used to ensure that the sum of the similarity scores of each column of the result (corresponding to each support pixel) is 1, thereby allowing the support feature to be aggregated to the query feature. Subsequently, the attention weight is multiplied by the pseudo mask of the support image to filter out irrelevant areas. Finally, the filtered attention weight is multiplied by the value V of the support image to achieve feature aggregation. This process is expressed as: F q '=attn·V s in, represents the transposition of the support key, ⊙ represents element-wise multiplication, M s is a pseudo mask of the support image, used to filter out irrelevant areas, attn is the intermediate result, F q ' is the result of aggregating the support feature information into the query feature. The subscripts q and s represent the query image and the support image, respectively. Finally, the aggregated query features are sent to a module consisting of residual connections, multi-layer perceptrons, and residual connections again to obtain the final aggregated query features. This process efficiently aggregates key feature information from the support set to the query set through a one-way information transmission strategy, avoiding the information misleading problem caused by inaccurate prediction masks of query images. The specific formula is as follows: O q =LN(attn·V+Q) O out =LN(MLP(O q )+O q ) Among them, LN represents layer normalization, MLP represents multi-layer perceptron, and O q represents the intermediate query feature, O out is the final query feature.

4. The small sample medical image segmentation method based on self-attention mechanism and contrastive learning according to claim 1, characterized in that: The query image foreground and background contrast learning steps in step (3) are as follows: First, the Masked Average Pooling (MAP) technique is used to extract the support prototype representing the foreground features from the labeled support image. s The calculation formula is as follows: P s =MAP(F s ,M s ) Next, the cosine similarity between these supporting prototypes and the query features is used to generate the query mask, and then the query prototype P is extracted. q , the calculation of cosine similarity and the extraction process of query prototypes preliminarily screen out the areas in the query image that may be related to the foreground. In order to distinguish the complex background area, the support image mask is first negated to obtain Then the background features corresponding to the supporting features are taken out and expressed as The Voronoi-based method is used to Divide and obtain the background area mask set Here B n represents the nth background region, R is the number of regions, which is set to 150. The formula for extracting different region representations is as follows: Among them, P n represents the prototype of the nth region, H and W represent The height and width of and B n,i They represent the i-th pixel corresponding to the supporting feature and the background area respectively. Under the constructed contrastive learning framework, the query prototype is used as the anchor point, the supporting prototype is used as the positive sample, and multiple partitioned prototypes of the background area constitute the negative sample set. Each negative sample represents a different part of the background area, thereby providing rich background information for the model.

5. The small sample medical image segmentation method based on self-attention mechanism and contrastive learning according to claim 1, characterized in that: In step (4), the model loss includes the use of cross entropy loss to directly measure the similarity between the predicted probability distribution and the true mask distribution. For each pixel, the cross entropy loss is The calculation formula is: Among them, M q represents the ground-truth mask of the query image, and denote the query image background and foreground masks predicted by the model, respectively. In addition, a threshold loss is added to the model Where T is the segmentation threshold, α is the adjustment parameter, which is set to 20 by default. By minimizing the learning threshold, the foreground features are encouraged to be more compact in the embedding space, and the foreground-background contrast loss is proposed. The segmentation performance of the model is optimized by maximizing the similarity between the query prototype and the support prototype while minimizing the similarity with the background negative sample. The mathematical expression is: Among them, cos(·) is the cosine similarity function, and the corrected mask background area occupies most of the area, so Able to effectively use a large number of negative samples to optimize the model and reduce the loss Add up to get the total loss The calculation formula is as follows:

Citation Information

Patent Citations

  • Small sample segmentation method based on multi-scale self-attention feature fusion

    CN116342875A

  • Multi-class availability semantic segmentation method based on small samples

    CN117953222A

  • Small sample visual prompt fine tuning method based on attention and contrast prototype

    CN118196831A

  • Small sample medical image segmentation method based on double attention mechanism and multi-scale fusion

    CN118334045A

  • Circumferential measuring instrument for a hoop

    KR102544454B1

Cited By

  • Improved few-sample medical image target region segmentation method

    CN119722604A

  • Supervised prototype comparative learning method based on prototype generator

    CN120726335A