A weakly supervised image semantic segmentation method based on sample mixing and contrastive learning
By using sample mixing and contrastive learning methods in weakly supervised image semantic segmentation, combined with the self-attention mechanism of the Transformer architecture, the problem of inaccurate model positioning under noise interference is solved, and the robustness and performance of image segmentation are improved.
Patent Information
- Application Number
- CN202410584673.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-05-13
AI Technical Summary
Existing weakly supervised image semantic segmentation models are difficult to capture the integrity and accuracy of local objects under noise interference, and are prone to overfitting global features, resulting in target incompleteness.
Using a method based on sample mixing and contrastive learning, the image features are mixed through the self-attention mechanism of the Transformer architecture, and dual image mixing and contrasting learning are introduced to help the network locate key areas in a noisy environment and improve the model's robustness and segmentation performance.
Through dual image mixing and contrast learning, the impact of noise is reduced, and the robustness of the model in local feature capture and global feature fusion is improved, thereby improving the performance of weakly supervised image semantic segmentation.
Smart Images

Figure CN118154884B
Abstract
Description
Technical Field
[0001] The present invention relates to a weakly supervised image semantic segmentation method, in particular to a weakly supervised image semantic segmentation method based on sample mixing and contrast learning, and belongs to the technical fields of image processing and recognition, and artificial intelligence. Background Art
[0002] Image segmentation technology is one of the basic tasks of computer vision and has broad application prospects. It can be used in autonomous driving, assisted medical care, image editing and other fields. Existing deep model technology has achieved successful segmentation performance based on labeled data. However, the generation of image segmentation labels requires high labor costs, especially in the field of remote sensing, where the labeling of image segments requires high professional knowledge. For example, it takes 1.5 hours to fully label the semantic segmentation labels in an image, and thousands of images are required to train a usable semantic segmentation model. Therefore, reducing dependence on labels has become a research hotspot in the current semantic segmentation direction. In order to solve the problem of expensive labeling, weakly supervised image semantic segmentation came into being. Weakly supervised image semantic segmentation aims to use only image-level annotations and train the network through classification tasks to segment the target in the image, and the performance is similar to that of fully supervised training tasks.
[0003] Existing weakly supervised image semantic segmentation models usually rely on class activation maps (CAMs) to locate class-related pixels. High-quality class activation maps rely on highly robust classification performance. Because CAM can reversely deduce the pixel area that contributes most to the classification based on the classification score. However, although the existing methods have designed complex CAM expansion strategies, there is still a lot of room for improvement in the integrity and accuracy of local objects. This is because when the model is classifying, there is noise interference in the image, and the existing methods are difficult to adapt to the noise. In addition, the model is prone to overfitting the global features of the object and it is difficult to capture discriminative details, resulting in incompleteness of the target. Existing patents such as CN 110930413 A and CN109344837 A usually use different feature extraction methods to obtain different features for an image, and then fuse and enhance these features, but cannot cope with the interference of significant noise. Therefore, the main challenge in the field of weakly supervised image semantic segmentation is how to eliminate the influence of noise and capture the local features of the object. Summary of the invention
[0004] The purpose of the present invention is to overcome the above-mentioned shortcomings and provide a weakly supervised image semantic segmentation method based on sample mixing and contrastive learning. By mixing the features of different images to help the network learn to locate the most critical area in the presence of significant noise, the self-attention mechanism of the Transformer architecture is used for sample mixing. Contrastive learning is used to help the network distinguish mixed samples, so that the model can accurately distinguish samples under the interference of mixed samples, thereby improving the performance of weakly supervised image semantic segmentation.
[0005] The technical solution adopted by the present invention is:
[0006] A weakly supervised image semantic segmentation method based on sample mixing and contrastive learning includes the following steps:
[0007] S1. Preprocess the image into a sequence of image block features and divide the data set;
[0008] S2. Input the image block feature sequence into the Transformer network with N layers of encoders. piece Each time the feature sequence passes through a layer of encoder, the attention propagation algorithm (Attention Rollout) is used to calculate the attention weight of each layer. After obtaining the attention weight of each layer, the attention propagation weight is calculated, and the attention score (i.e., importance score) of the image block feature is obtained according to the correlation score between the classification vector and the image block feature in the attention propagation weight.
[0009] S3. In the training phase, after the training set is input, the output features of the encoder at the tth layer are taken, the image block feature sequence of each sample output is randomly shuffled, and dual image mixing is performed on the image according to the attention score of the image block feature;
[0010] S4. The feature maps after the sample dual images are mixed are concatenated in the batch dimension and input into the subsequent N-t layer encoder to complete the encoding process and obtain the final feature representation Z ’ L , then Z ’ L The first feature vector in the classification vector CLS token is taken out and input into the classifier to calculate the cross entropy loss of the global feature. L g ;
[0011] S5. Z ’ L The remaining image block features after taking out the first feature vector are entered into the classifier after global average pooling and the cross entropy loss of these features is calculated. L p ;
[0012] S6. Z’ L After taking out the first feature vector, the remaining image block features are used for contrastive learning, the cosine similarity between the image block features is calculated, and the adversarial loss is calculated using the cosine similarity; the total loss is calculated, and the model network is iteratively updated;
[0013] S7. In the test phase, the test samples are input into the encoders of each layer in the trained model network, and the attention propagation weights of all layers are calculated. The output features of the last layer are linearly processed and average pooled for classification, and the class activation map (CAM) of the output image block features is calculated. The attention propagation weights are fused with the class activation map to obtain the optimized class activation map. The optimized class activation map is converted into a semantic segmentation label through binarization to complete the segmentation.
[0014] In the above method, the preprocessing described in step S1 is to first scale the image to the same size, then divide the image into N image blocks according to a certain interval, flatten the image into a feature vector of D dimension, input it into a linear layer for embedding to obtain N D-dimensional image block features, splice a trainable D-dimensional vector into the image block feature sequence to obtain a sequence of 1+N length, and add a randomly initialized N+1-dimensional trainable vector as a position code to the image block feature sequence, thereby obtaining a 1+N length D-dimensional image block feature sequence.
[0015] The attention weights of each layer in step S2 are calculated as follows:
[0016] ,
[0017] in is the image block feature sequence Z l The feature representation obtained by linear mapping is D is the dimension of the image patch feature;
[0018] After obtaining the attention weight, the attention values of each head of all multi-head self-attention are averaged, and the attention propagation weight is calculated by the following method:
[0019] ,
[0020] in I is the identity matrix, we get , t is the number of layers determined randomly, A l + I It simulates the transfer of knowledge at this layer. I represents the knowledge flow of the residual link, and then takes out W The fraction of CLS tokens in the classification vector , that is, the score except the first value in the first row, and the correlation score between the classification vector CLS token and other image block features in the calculated attention propagation weight is obtained. This score indicates the importance of the image block, that is, the importance score.
[0021] The dual image mixing described in step S3 is:
[0022] First obtain the t Output features of the layer Z t And the importance score (attention score) of its feature sequence S t Then a batch of Z t Divide into two equal parts Z t 1 and Z t 2 , S t Divide into two parts S t 1 and S t 2 , then Z t 1 and Z t 2 The image features of each sample in piece The sequence is randomly shuffled into Z t 1’ and Z t 2’ , S t 1 and S t 2 In the same shuffle order, S t 1’ and S t 2’ Next, Z t 1 and Z t 2’ Mixing is done by mixing at the same position in the sequence according to S t 1 andS t 2’ At this position, the image block features with large scores are retained, thus forming Z t 12’ , and then conversely, Z t 1’ and Z t 2 Fusion Z t 1’2 ; According to the score of the retained image block feature sequence, the label weight is calculated, that is, the importance score of the image block feature of each sample retained is added and divided by the total score to get two weights, and the weight is multiplied by the original one-hot label, and the label is changed from a one-hot label to a soft label Y’ The purpose is to reflect the composition of objects in the image through labels. For example, a mixed image is a mixture of cat and dog images. The importance scores of cats and dogs in the mixed image account for 40% and 60% of the total score respectively. Then the labels during training should be 0.4 for cats and 0.6 for dogs. The purpose is to make the model better understand the content of the image.
[0023] Cross entropy loss in step S4 L g The calculation formula is:
[0024] ,
[0025] in is the i-th category label of the sample, Represents the probability of the i-th category predicted using global features.
[0026] Cross entropy loss in step S5 L p The calculation formula is:
[0027] ,
[0028] in is the i-th category label of the sample, represents the probability of the i-th category predicted using local features.
[0029] The cosine similarity between the image block features in step S6 is:
[0030] ,
[0031] ,
[0032] in sim neg and sim pos are the cosine similarity scores between different samples and the same samples, Φ 1 and Φ 2 are the index sets of the locations of the features of the two sample image blocks, and the adversarial loss is calculated as follows:
[0033] ,
[0034] The total loss is calculated as follows,
[0035] .
[0036] The process of obtaining the class activation map (CAM) in step S7 is as follows: extract the classification category with the highest score based on the loss calculation, multiply the linear weight of the classifier that outputs the score with the feature of the linear processing output of the corresponding channel, and then add them to obtain the class activation map.
[0037] The process of fusing the attention propagation weight and the class activation map described in step S7 is:
[0038] The attention score of the classification vector in the attention propagation weight is transformed into an attention map. According to the class activation map of the image block feature, the product of the attention map and the class activation map is calculated point by point to obtain the optimized class activation map.
[0039] The binarization described in step S7 uses the mean as the threshold, and the area greater than the threshold becomes 1, and the area less than the threshold becomes 0.
[0040] The beneficial effects of the present invention are:
[0041] (1) Artificially introduce noise by mixing dual images, and use contrastive learning to help the network distinguish mixed samples, forcing the network to find the area most relevant to the label, thereby reducing the impact of noise;
[0042] (2) By fusing global features with local features, the model is helped to better locate the target area. Since the mixture in the mixed sample is the most significant area of the two samples, the information of one sample is strong noise for the other sample. The present invention can help the model effectively reduce the impact of noise and generate stronger robustness, thereby improving the performance of weakly supervised image semantic segmentation. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 This is a schematic diagram of the network model structure in the training phase of the method of the present invention;
[0044] Figure 2 This is a schematic diagram of the network model structure in the test phase of the method of the present invention;
[0045] Figure 3 is a flow chart of the training phase of the method of the present invention;
[0046] Figure 4 is a flow chart of the testing phase of the method of the present invention;
[0047] Figure 5 Schematic diagram of the dual image mixing process in an embodiment of the present invention; wherein a is an attention map, b is an image block feature sequence, c is a score description of each image block, and d is a shuffled image block feature;
[0048] Figure 6 4 is a diagram of the process of obtaining a class activation map in an embodiment of the present invention. DETAILED DESCRIPTION
[0049] The following further describes the invention in conjunction with specific embodiments.
[0050] Embodiment 1 A weakly supervised image semantic segmentation method based on sample mixing and contrastive learning comprises the following steps:
[0051] S1. Preprocess the image into a sequence of image block features and divide the data set:
[0052] The images are first scaled to the same size. The size is set to 448×448, that is, W=H=448, C=3. The image is then divided into 28×28 image blocks (patches) in intervals of 16×16. After the image is flattened into a 768-dimensional feature vector, it is input into the linear layer for embedding to obtain 784 768-dimensional image block features (tokens). Then, a trainable D=768-dimensional vector (this vector is called the classification vector CLS token) is concatenated with the image block feature sequence of length 784 to obtain a sequence of length 1+N, that is, a sequence of length 785. Finally, a randomly initialized 785×1 trainable vector is used as a position code and added to the 785-length image block feature sequence (when adding, the position code will be copied D=768 times along the second dimension to obtain a 785×768 matrix, and then added element by element to the image block feature sequence), thus obtaining the preprocessed image block feature sequence. ,Right now The training set and the test set are processed in the same way.
[0053] S2. Input the image block feature sequence into the Transformer network with N layers of encoders. pieceEach time the feature sequence passes through a layer of encoder, the attention propagation algorithm (Attention Rollout) is used to calculate the attention weight of each layer. After obtaining the attention weight of each layer, the attention propagation weight is calculated, and the attention score of the image block feature is obtained according to the correlation score between the classification vector and the image block feature in the attention propagation weight:
[0054] The preprocessed image patch feature sequence is input into a Transformer network with 12 layers of encoders. Each encoder consists of multi-head self-attention and two linear layers. Multi-head self-attention captures the long- and short-range relationships between image patch features by calculating the weight matrix on the image patch features. The attention weight of the classification vector CLS token indicates the importance of the image patch features to the classification. The weight matrix between encoders can be obtained by the attention propagation algorithm. piece The information between features flows from the bottom layer to the top layer. The weight score obtained by the attention propagation algorithm can better obtain the importance of the image block features. In order to obtain the attention propagation weight, it is first necessary to determine which layer it needs to flow to. The present invention determines the number of layers t by random numbers, and each training batch is randomly determined again. Next, the attention weight of each layer is calculated:
[0055] ,
[0056] in is the image block feature sequence Z l The feature representation is obtained through linear mapping. D is the length of the image block feature. This formula calculates the correlation between each image block feature and the image block feature in each layer of the image block feature sequence. After obtaining the attention weight, the attention value of each head of all multi-head self-attention is averaged, and then the attention propagation weight is calculated by the following method:
[0057] ,
[0058] in I is the identity matrix, we get , t is the number of layers determined randomly, A l + I It simulates the transfer of knowledge at this layer. I represents the knowledge flow of the residual link, and then takes out W The fraction of CLS tokens in the classification vector , that is, the score except the first value in row 1. This step is to obtain the correlation score between the classification vector CLS token and other image block features in the calculated attention propagation weight, because the classification vector CLS token is used for classification, so the image block features that are highly correlated with the CLS token are very important for classification, and are most likely the image block features of the key area.
[0059] S3. In the training phase, after the training set is input, the output features of the encoder at the tth layer are taken, the image block feature sequence of each sample output is randomly shuffled, and dual image mixing is performed on the image according to the attention score of the image block feature:
[0060] For a batch of data, first get the output features of the tth layer Z t And the importance score of its feature sequence S t Then a batch of Z t Divide into two equal parts Z t 1 and Z t 2 , S t Divide into two parts S t 1 and S t 2 , if there are 16 samples in a batch, they are divided into two parts, the first 8 are one part, and the last 8 are one part. Then Z t 1 and Z t 2 The image features of each sample in piece Randomly shuffle the sequence Z t 1’ and Z t 2’ , S t 1 and S t 2 In the same shuffle order, S t 1’ and S t 2’ Next, Zt 1 and Z t 2’ Mixing is done by mixing at the same position in the sequence according to S t 1 and S t 2’ At this position, the image block features with large scores are retained, thus forming Z t 12’ , and then conversely, Z t 1’ and Z t 2 Fusion Z t 1’2 According to the score of the retained image block feature sequence, the label weight is calculated, that is, the importance score of the image block feature of each sample retained is added and divided by the total score to get two weights, and the weight is multiplied by the original one-hot label, and the label is changed from a one-hot label to a soft label. Y’ .
[0061] The mixing process is further explained:
[0062] Z t 1 and Z t 2 is the feature sequence of the image blocks output by the tth layer, with 16 samples in a batch Z t 1 and Z t 2 , which are the first 8 and the last 8 respectively, and there are N image block features. S t 1 and S t 2 is the attention score of the image block features in these two batches of samples, which can also be called the importance score. Z t 1 and Z t 2 The image block feature sequence of each sample in is shuffled to obtain Z t 1’ andZ t 2’ , attention score S t 1 and S t 2 Also shuffled in the same way to get S t 1’ and S t 2’ , so that the score will refer to the original image patch, such as Figure 5 Then Z t 1 and Z t 2’ Mix Z t 1’ and Z t 2 Mixing. The mixing method is: at the same position, retain the image blocks with high scores to form mixed features, such as Figure 1 As shown in .
[0063] S4. The feature maps after the sample dual images are mixed are concatenated in the batch dimension and input into the subsequent N-t layer encoder to complete the encoding process and obtain the final feature representation Z L ’ , then Z L ’ The first feature vector in is taken out, input into the classifier and the cross entropy loss of the global feature is calculated L g :
[0064] After mixing the dual images Z t 12’ and Z t 1’2 Concatenate them in the batch dimension to get Z t ’ , for example, originally Z t 12’ and Z t 1 ’2The features are all 8 samples in a batch, and when they are concatenated, they are 16 samples in a batch. They are input to the subsequent encoder to perform the complete encoding process. For example, if an encoder has 12 layers, the input batch of images should go through 12 layers directly in the normal way. After adding the dual image mixture, it acts on a certain layer in the middle, and after processing, it continues to go through the subsequent layers to obtain the final feature representation. Z L ’ , and then separate the classification vector CLS token and the image block features, that is, Z L ’ The first feature vector in is taken out, which is the classification vector CLS token, which represents the global feature of the sample. The classification vector CLS token is input into the classifier to obtain the classification score, and then the probability score is obtained through softmax. P g Finally, the cross loss is calculated, where Y is the label and i is the i-th category. L g is the cross entropy loss calculated using CLS token as the global feature.
[0065] ,
[0066] in is the i-th category label of the sample, Represents the probability of the i-th category predicted using global features.
[0067] S5. Z L ’ The remaining image block features after taking out the first feature vector are entered into the classifier after global average pooling and the cross entropy loss of these features is calculated. L p :
[0068] Z L ’ The remaining image patch features after taking out the first feature vector contain richer local information. Therefore, incorporating image patch features into the final classification process will better help the model understand the object. First, the image patch features are passed through a linear layer to map the dimension D=768 to C, where C is the number of categories, depending on the dataset, and then global average pooling (GAP) is applied.
[0069] ,
[0070] Z p is the feature after global average pooling, where F is a linear layer, GAP takes all N images piece The features are averaged to become a one-dimensional feature vector, which is then mapped into a classification score by the classifier and then passed through softmax to obtain a probability score. P l . Finally, the cross entropy loss is calculated, L p is the cross entropy loss calculated using the features after global average pooling,
[0071] ,
[0072] in is the i-th category label of the sample, is the i-th category label of the sample, represents the probability of the i-th category predicted using local features.
[0073] S6. Z L ’ After taking out the remaining image block features after the first feature vector, perform contrastive learning, calculate the cosine similarity between the image block features, and use the cosine similarity to calculate the adversarial loss; calculate the total loss and iteratively update the model network:
[0074] Different samples are mixed together. Since self-attention allows the two samples to be fully integrated, the image block features of one sample will become the noise of another sample. Therefore, it is necessary to allow the model to adaptively distinguish the two to achieve noise tolerance. Therefore, contrastive learning is performed in the last layer of output features. First, the cosine similarity between the image block features is calculated.
[0075] ,
[0076] ,
[0077] in sim neg and sim pos are the cosine similarity scores between different samples and the same samples, Φ 1 and Φ 2 are the index sets of the locations of the features of the two sample image blocks, and the adversarial loss is calculated as follows:
[0078] ,
[0079] Finally, the final loss is calculated as follows,
[0080] .
[0081] S7. In the test phase, the test samples are input into the encoders of each layer in the trained model network, and the attention propagation weights of all layers are calculated; the output features of the last layer are linearly processed and averaged pooled for classification, and the class activation map (CAM) of the output image block features is calculated; the attention propagation weights are fused with the class activation map to obtain the optimized class activation map; the optimized class activation map is converted into a semantic segmentation label through binarization to complete the segmentation:
[0082] (1) Calculate the attention propagation weights of all layers:
[0083] The sample image is input into the model, and then input into all layer encoders in sequence, and then the attention of all layers is aggregated.
[0084] ,
[0085] Where L=12 is the number of all encoders, I is the identity matrix mentioned above, A l + I It simulates the transfer of knowledge at this layer. I Represents the knowledge flow of the residual link.
[0086] (2) Calculate the class activation map (CAM) of the output image patch features:
[0087] By calculating the classification loss of the image block feature sequence, the category with the highest score is extracted. In the classifier, the weight of the score is added to the features of the linear layer dimensionality reduction output channel-level weighted addition. Then we get Figure 2 Class activation map for the top category shown.
[0088] The class activation map is obtained as follows: the length of the image block feature sequence is N×D (784×768), first Figure 2 As shown, a linear layer is used to transform it into an N×C (784×C) feature sequence, where C is the number of categories. The feature sequence can then be transformed and arranged to obtain a 28×28×C feature map. The spatial dimension is averaged into a one-dimensional vector through global average pooling, that is, the 28×28×C feature becomes a 1×C vector. The 1×C feature is passed through a linear layer to obtain a 1×C category prediction output. Then the highest score is taken, and the linear weight in the classifier that outputs the score is multiplied by the corresponding channel in the feature map and then added to obtain the class activation map as shown in Figure 6 shown.
[0089] (3) Fusion of attention propagation weights and class activation maps:
[0090] The attention score of the classification vector CLS token in the attention propagation weight represents the area of global feature attention, and its shape is 784×1, which is transformed into a 28×28×1 attention map, while the class activation map CAM of the image block feature represents the area of local feature attention, and its shape is also 28×28×1. The product of the attention map and the class activation map is calculated point by point to obtain the optimized class activation map.
[0091] (4) Obtain segmentation labels through binarization:
[0092] The class activation map is expanded to a size of 448×448 through bilinear interpolation, and then the mean is used as the threshold. The area greater than the threshold becomes 1, and the area less than the threshold becomes 0, and the segmentation label is obtained to complete the segmentation.
[0093] The above description is only a specific implementation mode of the present invention and is not intended to limit the protection scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A weakly supervised image semantic segmentation method based on sample mixing and contrastive learning, characterized by: The steps include: S1. Preprocess the image into a sequence of image block features and divide the data set; S2. Input the image block feature sequence into a Transformer network with N layers of encoders. After each layer of encoder passes through, the attention propagation algorithm is used to calculate the attention weight of each layer. After obtaining the attention weight of each layer, the attention propagation weight is calculated. The attention score of the image block feature is obtained according to the correlation score between the classification vector and the image block feature in the attention propagation weight. The attention weights of each layer are calculated as follows: , in is the image block feature sequence Z l The feature representation obtained by linear mapping is D is the dimension of the image patch feature; After obtaining the attention weight, the attention values of each head of all multi-head self-attention are averaged, and the attention propagation weight is calculated by the following method: , in I is the identity matrix, we get , t is the number of layers determined randomly, A l + I It simulates the transfer of knowledge at this layer. I represents the knowledge flow of the residual link, and then takes out W The fraction of classified vectors in , that is, the score except the first value in the first row, and the correlation score between the classification vector and other image block features in the calculated attention propagation weight is obtained, that is, the attention score; S3. In the training phase, after the training set is input, the output features of the encoder at the tth layer are taken, the image block feature sequence of each sample output is randomly shuffled, and dual image mixing is performed on the image according to the attention score of the image block feature; The dual image mixing is: first obtain the t Output features of the layer Z t And the attention score of its feature sequence S t , and then a batch of Z t Divide into two equal parts Z t 1 and Z t 2 , S t Divide into two parts S t 1 and S t 2 , then Z t 1 and Z t 2 The image feature block sequence of each sample in is randomly shuffled to become Z t 1’ and Z t 2’ , S t 1 and S t 2 In the same shuffle order, S t 1’ and S t 2’ Next, Z t 1 and Z t 2’ Mixing is done by mixing at the same position in the sequence according to S t 1 and S t 2’ At this position, the image block features with large scores are retained, thus forming Z t 12’ , and then conversely, Z t 1’ and Z t 2 Fusion Z t 1’2 ; S4. The feature maps after the sample dual images are mixed are concatenated in the batch dimension and input into the subsequent N-t layer encoder to complete the encoding process and obtain the final feature representation Z ’ L , then Z ’ L The first feature vector in the classification vector CLS token is taken out and input into the classifier to calculate the cross entropy loss of the global feature. L g ; S5. Z ’ L The remaining image block features after taking out the first feature vector are entered into the classifier after global average pooling and the cross entropy loss of these features is calculated. L p ; S6. Z ’ L After taking out the first feature vector, the remaining image block features are used for contrastive learning, the cosine similarity between the image block features is calculated, and the adversarial loss is calculated using the cosine similarity; the total loss is calculated, and the model network is iteratively updated; S7. In the test phase, the test samples are input into the encoders of each layer in the trained model network, and the attention propagation weights of all layers are calculated. The output features of the last layer are linearly processed and average pooled for classification, and the class activation map of the output image block features is calculated. The attention propagation weights are fused with the class activation map to obtain the optimized class activation map. The optimized class activation map is converted into a semantic segmentation label through binarization to complete the segmentation.
2. According to claim 1, a weakly supervised image semantic segmentation method based on sample mixing and contrastive learning is characterized in that: The preprocessing described in step S1 is to first scale the image to the same size, then divide the image into N image blocks, flatten the image into a D-dimensional feature vector, input it into a linear layer for embedding to obtain N D-dimensional image block features, splice a trainable D-dimensional vector into the image block feature sequence to obtain a sequence of 1+N length, and add a randomly initialized N+1-dimensional trainable vector as a position code to the image block feature sequence, thereby obtaining a 1+N length D-dimensional image block feature sequence.
3. The weakly supervised image semantic segmentation method based on sample mixing and contrastive learning according to claim 1, characterized in that: Cross entropy loss in step S4 L g The calculation formula is: , in is the i-th category label of the sample, Represents the probability of the i-th category predicted using global features.
4. The weakly supervised image semantic segmentation method based on sample mixing and contrastive learning according to claim 1, characterized in that: Cross entropy loss in step S5 L p The calculation formula is: , in is the i-th category label of the sample, represents the probability of the i-th category predicted using local features.
5. The weakly supervised image semantic segmentation method based on sample mixing and contrastive learning according to claim 1, characterized in that: The cosine similarity between the image block features in step S6 is: , , in sim neg and sim pos are the cosine similarity scores between different samples and the same samples, Φ 1 and Φ 2 are the index sets of the locations of the features of the two sample image blocks, and the adversarial loss is calculated as follows: ; The total loss is calculated as follows, 。 6. The weakly supervised image semantic segmentation method based on sample mixing and contrastive learning according to claim 1, characterized in that: The process of obtaining the class activation map in step S7 is as follows: extracting the classification category with the highest score based on the loss calculation, multiplying the linear weight of the classifier that outputs the score with the feature of the linear processing output of the corresponding channel, and then adding them to obtain the class activation map.
7. The weakly supervised image semantic segmentation method based on sample mixing and contrastive learning according to claim 1, characterized in that: The process of fusing the attention propagation weight and the class activation map described in step S7 is: The attention score of the classification vector in the attention propagation weight is transformed into an attention map. According to the class activation map of the image block feature, the product of the attention map and the class activation map is calculated point by point to obtain the optimized class activation map.
8. The weakly supervised image semantic segmentation method based on sample mixing and contrastive learning according to claim 1, characterized in that: The binarization described in step S7 uses the mean as the threshold, and the area greater than the threshold becomes 1, and the area less than the threshold becomes 0.
