Small sample image semantic segmentation optimization method fusing attention mechanism

By constructing a dual-branch feature extraction network and attention mechanism, multi-granularity category prototypes are generated. Combining channel and spatial attention, the problem of consistency between local details and global semantics in small sample image semantic segmentation is solved, achieving high-efficiency segmentation performance with very few annotations and expanding the application of image semantic segmentation technology in high-cost annotation fields.

CN121661349APending Publication Date: 2026-03-13SHANGHAI AOZHENG NETWORK TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-15
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Existing semantic segmentation methods for small sample images struggle to balance local details with global semantic consistency and lack the ability to dynamically focus on key semantic regions, which leads to noise interference being easily amplified and propagated to the final prediction result.

Method used

A dual-branch feature extraction network is constructed to generate multi-granularity category prototypes through cross-scale feature aggregation. Combined with channel and spatial attention mechanisms, local structural dependencies are captured, and an edge-aware loss function is introduced to optimize the segmentation results.

Benefits of technology

With a very small number of labeled samples, the model's discrimination ability under low-sample conditions is improved, noise propagation is suppressed, attention to key target regions is enhanced, the stability and continuity of segmentation results are improved, and semantic consistency is significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121661349A_ABST
    Figure CN121661349A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image semantic segmentation, in particular to a small sample image semantic segmentation optimization method fusing an attention mechanism, which comprises the following steps of: constructing a double-branch feature extraction network to respectively process a support set and a query image, and generating a multi-granularity category prototype; based on a channel attention and space attention mechanism, performing dynamic re-calibration and region enhancement on the features; and based on joint attention feature fusion and edge perception loss, boundary segmentation precision and semantic consistency are improved. According to the method, the segmentation performance can be remarkably improved under the condition that only 1-5 annotation samples exist in each class, dependence on large-scale annotation data is reduced, and the method is suitable for high-cost annotation scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image semantic segmentation technology, and in particular to a few-sample image semantic segmentation optimization method that incorporates an attention mechanism. Background Technology

[0002] Image semantic segmentation aims to assign a semantic category label to each pixel in an image, thereby achieving a refined understanding of the scene. In recent years, deep learning methods, especially convolutional neural networks, have significantly improved the performance of semantic segmentation. However, their high dependence on large amounts of labeled data poses a serious challenge in practical applications, especially in fields where labeling costs are high or samples are scarce.

[0003] Among them, few-shot image semantic segmentation technology aims to complete the segmentation task of new categories under the condition of providing only a very small number of labeled samples, becoming a key research direction to overcome the data bottleneck. However, existing methods have an inherent contradiction between the discriminativeness of feature representation and the completeness of context modeling, making it difficult to simultaneously take into account the consistency of local details and global semantics with limited samples. At the same time, traditional few-shot segmentation frameworks do not adequately model the cross-sample association between the support set and the query image, and lack a focusing mechanism for key semantic regions, making noise interference easily amplified and propagated to the final prediction result. Summary of the Invention

[0004] The purpose of this invention is to provide a few-sample image semantic segmentation optimization method that integrates an attention mechanism, in order to solve the technical problem that existing few-sample image semantic segmentation methods are unable to take into account both local details and global semantic consistency, resulting in insufficient dynamic focusing ability on key semantic regions.

[0005] This invention provides a few-sample image semantic segmentation optimization method incorporating an attention mechanism, comprising: A dual-branch feature extraction network is constructed to process support set images and query images; The binary mask of the target category is extracted from the labeled mask of the support set image, and then the binary mask is weighted and averaged with the multi-scale feature map extracted from the corresponding branch to obtain the category prototype vector at each scale. The prototype vectors at different levels are then fused into a unified multi-granularity category prototype through cross-scale feature aggregation. Based on the similarity between the high-level feature map extracted from the query image and the multi-granularity category prototype, a dot product operation is used to generate a channel attention map, where the response value of each channel reflects the relevance of the channel feature to the current segmentation task, and the channel attention weight distribution is constrained to the range of 0 to 1 by a normalization function. A correlation tensor is constructed by utilizing the pixel-level matching relationship between the feature maps of the support set image and the query image. Cross-image feature alignment is achieved by transposing the correlation tensor, and a two-dimensional convolutional layer is applied to the correlation tensor to capture local structural dependencies, outputting a spatial attention weight map. The channel attention weights are multiplied element-wise with the original feature map to complete the channel dimension feature recalibration. At the same time, the spatial attention weight map and the channel weighted feature map are fused position-wise to form joint attention-enhanced features. The joint attention-enhanced features and multi-granularity category prototypes are used to calculate pixel similarity to generate a preliminary segmentation probability map, and an edge-aware loss function is introduced to supervise the prediction results. Based on the initial segmentation probability map, the feature alignment threshold of spatial attention is dynamically adjusted, and the aforementioned steps are repeated until the segmentation result converges or the preset number of iterations is reached.

[0006] In some embodiments, the construction of the dual-branch feature extraction network for processing the support set image and the query image includes: each branch adopts a deep residual network as the backbone network, introduces dilated convolution after the fourth residual block to expand the receptive field, and outputs a multi-scale feature map sequence, wherein the multi-scale feature map sequence includes feature maps of the second, third and fourth stages, with spatial resolutions of 1 / 8, 1 / 16 and 1 / 32 of the input image, respectively.

[0007] 3. The method according to claim 1, wherein the cross-scale feature aggregation adopts a gated feature selection mechanism, including a weight vector with learnable parameters, used to dynamically allocate the contribution ratio of prototype vectors at each scale, and the fusion vector dimension is consistent with the highest layer feature.

[0008] In some embodiments, the correlation tensor is constructed as follows: The high-level feature maps of the query image and the support set image are expanded in the spatial dimension and matrix multiplication is performed to generate a correlation mapping of size H×W×H'×W'. By compressing the height and width dimensions through max pooling, we obtain the H×W spatial attention base map.

[0009] In some embodiments, the edge-aware loss function consists of cross-entropy loss and boundary-weighted loss, wherein the boundary-weighted loss extracts the edge regions of the true labels through a morphological gradient operator and assigns edge pixels a loss weight that is 5 times that of non-edge pixels.

[0010] In some embodiments, the pixel-level similarity calculation is based on the cosine similarity formula, which calculates the cosine value of the angle between the feature vector of each query image pixel position and the prototype vector of the multi-granularity category, and the resulting similarity score is transformed into the probability distribution of each category by the softmax function.

[0011] Compared with the prior art, the present invention has the following advantages: 1. By generating multi-granularity category prototypes and combining them with channel attention mechanisms, dynamic filtering and enhancement of feature channels are achieved, thereby improving the model's discriminative ability under low-sample conditions; 2. By designing a spatial attention module to capture pixel-level matching relationships, the focus on key target areas is enhanced, effectively suppressing noise propagation; 3. By jointly optimizing channel and spatial dual attention features, complementary fusion of multi-dimensional information is achieved, improving the stability and continuity of segmentation results under complex texture and fuzzy boundary conditions; 4. By introducing an edge-aware loss function, the segmentation boundaries are further refined, significantly improving semantic consistency. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a flowchart of the segmentation optimization method of the present invention; Figure 2 This is a diagram illustrating the core principle framework of attention fusion in this invention. Detailed Implementation

[0014] The following will be based on embodiments of the present invention. Figures 1-2 The technical solutions in the embodiments of the present invention will be clearly and completely described together. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.

[0015] Partial interpretation: H, W, H', W': In the process of generating the relevance mapping between the query image and the support set images, H and W represent the height and width of the high-level feature map of the query image, respectively; while H' and W' represent the height and width of the high-level feature map of the support set images, respectively.

[0016] Example This embodiment provides a few-sample image semantic segmentation optimization method that integrates an attention mechanism, including: constructing a dual-branch feature extraction network to process support set images and query images; extracting a binary mask of the target category from the labeled mask of the support set image, performing a channel-wise weighted average with the multi-scale feature map extracted from the corresponding branch to obtain the category prototype vector at each scale, and fusing the prototype vectors at different levels into a unified multi-granularity category prototype through cross-scale feature aggregation; generating channel attention maps using dot product operations based on the similarity between the high-level feature map extracted from the query image and the multi-granularity category prototype, wherein the response value of each channel reflects the relevance of the channel feature to the current segmentation task, and constraining the channel attention weight distribution within the range of 0 to 1 through a normalization function; utilizing the support set... A relevance tensor is constructed based on the pixel-level matching relationship between the image and the query image feature maps. Cross-image feature alignment is achieved through transposition, and a two-dimensional convolutional layer is applied to the relevance tensor to capture local structural dependencies, outputting a spatial attention weight map. The channel attention weights are multiplied element-wise with the original feature map to complete the channel-dimensional feature recalibration. Simultaneously, the spatial attention weight map and the channel-weighted feature map are fused position-wise to form a joint attention enhancement feature. The joint attention enhancement feature is then used to calculate pixel similarity with the multi-granularity category prototype to generate a preliminary segmentation probability map, and an edge-aware loss function is introduced to supervise the prediction results. Based on the preliminary segmentation probability map, the feature alignment threshold of the spatial attention is dynamically adjusted, and the above steps are repeated until the segmentation results converge or the preset number of iterations is reached.

[0017] The solution of this invention can maintain excellent segmentation performance with a very small number of labeled samples, significantly reducing the dependence on large-scale labeled data and expanding the application of image semantic segmentation technology in the field of high-cost annotation.

[0018] To better understand this invention, the details are as follows: first, A dual-branch feature extraction network is constructed to process the support set image and the query image. Each branch uses a deep residual network as the backbone network. Dilated convolutions are introduced after the fourth residual block to expand the receptive field, and a multi-scale feature map sequence is output, including feature maps from the second, third, and fourth stages, with spatial resolutions relative to the input image of 1 / 8, 1 / 16, and 1 / 32, respectively. Specifically, the deep residual network adopts the ResNet-50 architecture, and its second-stage output has 256 channels, with the corresponding feature map denoted as F. s2 or F q2 The third stage outputs 512 channels, and the corresponding feature map is denoted as F. s3 or F q3 The fourth stage outputs 1024 channels, and the corresponding feature map is denoted as F. s4 or F q4In this context, the subscript s indicates the support set branch, and q indicates the query set branch.

[0019] After the fourth residual block, two dilated convolutional layers are inserted sequentially, with dilation rates set to 2 and 4 respectively. Both layers have a kernel size of 3×3 and zero-padding. The activation function is a modified linear unit. This design effectively expands the receptive field without reducing spatial resolution, enabling high-level features to capture a wider range of contextual information while preserving more fine-grained texture details. This provides a high-quality multi-scale representation foundation for subsequent prototype generation and attention computation. The input image size is uniformly preprocessed to 473×473 pixels. After processing by the backbone network, the F... s2 / F q2 The spatial dimensions are 59×59, F s3 / F q3 For 29×29, F s4 / F q4 It is 15×15.

[0020] then, The binary mask for the target category is extracted from the labeled mask of the support set image. This mask is then weighted and averaged channel-wise with the multi-scale feature maps extracted from the corresponding branches to obtain the category prototype vectors at each scale. Finally, cross-scale feature aggregation is used to fuse the prototype vectors from different levels into a unified multi-granularity category prototype. The binary mask M for the target category is extracted from the labeled mask of the support set image. s The feature map F is then weighted and averaged channel-wise with the multi-scale feature maps extracted from the corresponding branches to obtain the class prototype vectors P2, P3, and P4 at each scale. Specifically, for the support set feature map F at the k-th scale (k=2,3,4)... sk ∈R^(C k ×H k ×W k ) and binary mask M s ∈{0,1}^(H k ×W k First, M s The total number of foreground pixels Nf is obtained by summing along the spatial dimension. g = Σ {i,j} M s(i,j) If N fg If >0, then the prototype vector P at the k-th scale is k ∈R^(C k ) Calculated as P k =(1 / N fg )Σ {i=1} ^{H_k} Σ {j=1} ^{W k} M s(i,j) ·F sk(:,i,j) If N fg= 0, then P k Let it be a vector of all zeros.

[0021] Furthermore, a cross-scale feature aggregation module is used to fuse prototype vectors from different levels into a unified multi-granularity category prototype P. multi Cross-scale feature aggregation employs a gated feature selection mechanism, containing a weight vector α = [α2, α3, α4] with learnable parameters, used to dynamically allocate the contribution ratio of prototype vectors at each scale. In implementation, the low-level prototypes P2 and P3 are projected onto the high-level channel dimension 1024 through a 1×1 convolution to obtain P'2 and P'3, and then the weighted fusion vector P is calculated. multi =α2·P'2+α3·P'3+ α4·P4, where α is normalized by the softmax function, i.e., α i =exp(w i ) / Σ j exp(wj), w i For learnable scalar parameters, it should be noted that the learnable scalar parameters w2, w3, and w4 are independent trainable variables, and their gradients are derived from the total loss function L. total Backpropagation updates are performed in sync with the parameters of the backbone network and attention module. This mechanism ensures that low-level prototypes focus on geometric details, such as edges and textures, while high-level prototypes focus on semantic abstractions, such as the overall structure of an object. Finally, the fused vector dimension is kept consistent with the highest-level features.

[0022] Immediately afterwards, Based on the similarity between the high-level feature map extracted from the query image and the multi-granularity category prototype, a dot product operation is used to generate a channel attention map. Each channel response value reflects the relevance of that channel's features to the current segmentation task, and a normalization function constrains the distribution of channel attention weights within the range of 0 to 1. For F... q4 With P multi L2 normalization is performed separately to eliminate interference from differences in feature amplitudes and improve the stability of attention calculation. The normalized features are denoted as \hat{F}. q4 With \hat{P} multi .

[0023] Furthermore, calculate the channel attention response: A c = \hat{F} q4 ^T·\hat{P} multi A c ∈R^(1024).

[0024] Here, the dot product is averaged over the spatial dimension, that is, for each channel c, A c(c) = (1 / (H q4 ·W q4)) Σ{i,j}\hat{F} q4(c,i,j) ·\hat{P} multi(c) This response value reflects the relevance of the channel feature to the current segmentation task.

[0025] Furthermore, the attention weight distribution is constrained to the interval between 0 and 1 using a softmax normalization function, and the temperature coefficient of the softmax function is set to 0.07 to smooth extreme response values. The final channel attention weight vector W c ∈R^(1024) is represented as: W c =softmax(A c / 0.07), the aforementioned channel attention weight vector W c This enables the model to adaptively enhance feature channels that are highly relevant to the target category and suppress irrelevant or noisy channels, thereby improving the discriminative power of the feature representation.

[0026] Then, A relevance tensor is constructed using the pixel-level matching relationship between the feature maps of the support set image and the query image. Cross-image feature alignment is achieved through transposition. A two-dimensional convolutional layer is applied to the relevance tensor to capture local structural dependencies, outputting a spatial attention weight map. The high-level feature map F of the query image is then used to... q4 ∈R^(1024 × H q × W q ) and support set image high-level feature map F s4 ∈R^(1024 × H s × W s Expanding into a matrix form in spatial dimensions, i.e., F q4 ∈R^(1024 × N q ), F s4 ∈R^(1024 × N s ), where N q = H q ·W q N s = H s ·W s Furthermore, perform matrix multiplication R=F. q4 ^T·F s4 Generate a size of N q ×N s The correlation mapping, i.e., R∈R^(H q W q ×H s ×W s To reduce computational complexity and focus on the most relevant matching regions, for R in (H) s W sMax pooling is applied to the height and width dimensions, with a pooling window size of 3×3, a stride of 1, and padding of 1, compressing the height and width dimensions to obtain H. q ×W q Spatial Attention Basic Diagram R base .

[0027] Furthermore, in R base A 3×3 two-dimensional convolutional layer is applied on top, with zero padding and a modified linear unit activation function, outputting a single-channel feature map.

[0028] Furthermore, the final spatial attention weight map W is generated after transformation by the sigmoid function. s ∈[0,1]^(H q ×W q The weighted image, whose value is strictly limited to between 0 and 1, highlights the spatial region in the query image that best matches the target semantics of the support set, effectively enhancing the response intensity of key regions while suppressing interference from background and noise regions.

[0029] Then, The channel attention weights are multiplied element-wise with the original feature map to complete the channel-dimensional feature recalibration. Simultaneously, the spatial attention weight map and the channel-weighted feature map are fused position-wise to form a joint attention-enhanced feature. Specifically: Phase 1: High-level feature map F of the query image q4 ∈R^(1024×H q ×W q ), and transfer the channel attention weight vector W c ∈R^(1024) expands to be related to F q4 With the same spatial dimensions, we obtain W cexp ∈R^(1024×H q ×W q ), where W cexp(c,i,j) = W c (c) Next, perform element-wise multiplication to obtain the channel-weighted feature F. cw =F q4 •W cexp .

[0030] Phase 2: Improving the spatial attention weight map W s ∈R^(H q ×W q ) Expanded to be related to F cw With the same channel dimension, we get W sexp ∈R^(1024×H q ×W q ), where W sexp(c,i,j) =W s(i,j) .

[0031] Furthermore, W sexp With F cw Perform position-wise weighted fusion, i.e., F joint = F cw •W sexp +F cw ∙(1-W sexp )·β, where β is a learnable balancing factor, initially set to 0.2, used to retain some contextual information of non-target regions and avoid excessive sparsity. It should be noted that the learnable balancing factor β, as a trainable parameter of the network, is jointly optimized with the overall loss function through backpropagation during the training phase; during the inference phase, a fixed value after training convergence is used.

[0032] After the element-wise multiplication operation in the channel dimension is completed, feature normalization is performed immediately. Batch normalization algorithm is used to standardize the weighted features. The mean and variance are statistically analyzed during the training phase and the moving average is used in the inference phase to achieve the synergistic effect of dual attention in channels and space. This not only selects the most discriminative feature channels, but also focuses on the most relevant spatial regions, significantly improving the semantic consistency of feature representation.

[0033] Then, Pixel similarity is calculated between the joint attention enhancement feature and the multi-granularity category prototype to generate a preliminary segmentation probability map, and an edge-aware loss function is introduced to supervise the prediction results. For the joint attention enhancement feature F... joint The feature vector f of each pixel position (i,j) ij ∈R^(1024), and the multi-granularity category prototype P multi ∈R^(1024) Calculate the cosine similarity score s(i,j) = (f ij∙ P multi ) / (||f ij ||∙||P multi The obtained similarity score is transformed into a binary probability distribution using the softmax function, i.e., the foreground probability p. fg(i,j) =exp(s(i,j)) / (exp(s(i,j))+exp(s bg ), where s bg The similarity to the background prototype is typically set to 0 or obtained through negative sampling. In this embodiment, the background prototype similarity s is preferably... bg Always set to 0, meaning no explicit modeling of the background prototype is performed; binary classification is only performed based on the target category prototype. Or s bg The background prototype P is obtained by randomly sampling 50 pixel feature vectors from non-target regions in the support set image and taking their mean value. bg Then, calculate the cosine similarity with the query features.

[0034] Finally, a preliminary segmentation probability map P is generated. pred ∈[0,1]^(H q ×W q To improve boundary segmentation accuracy, an edge-aware loss function L is introduced. total =L ce +λ∙L edge , where L ce For standard cross-entropy loss, L edge The boundary-weighted loss is λ, which is the balance coefficient and is set to 1.0.

[0035] The boundary-weighted loss extracts the edge region E of the true label Y through the morphological gradient operator, which is defined as E=dilate(Y, k)-erode(Y, k), where dilate and erode are the morphological dilation and erosion operations, respectively, and the structuring element k is a 3×3 cross-shaped kernel.

[0036] Furthermore, edge pixels are assigned a loss weight that is 5 times that of non-edge pixels, i.e., L edge =(1 / N)Σ {i,j} w(i,j)·CE(p pred(i,j) Y(i,j)), where the weight w(i,j) = 5, if (i,j)∈E, otherwise w(i,j) = 1, and N is the total number of pixels. This loss function prompts the model to focus on the consistency of the boundary region during training, effectively improving the accuracy of the segmentation boundary.

[0037] Finally, the feature alignment threshold for spatial attention is dynamically adjusted based on the initial segmentation probability map, and the aforementioned steps are repeated until the segmentation result converges or the preset number of iterations is reached. The initial segmentation probability map P... pred Apply threshold filtering to generate a soft mask guiding signal M guide The threshold is set to 0.5; locations above this value are considered reliable foreground regions, while locations below this value are considered uncertain regions. That is, M... guide(i,j) =1, if P pred(i,j) ≥0.5, otherwise, M guide(i,j) =0.

[0038] It should be noted that the guiding signal is used to adjust the feature alignment process in the spatial attention module as follows: In the t-th iteration (t≥2), when recalculating the correlation tensor R, only in M guide Perform feature matching on regions where M = 1, or on M guide A higher sparsity penalty is applied to regions where the correlation coefficient (=0), thereby dynamically adjusting the attention distribution and focusing on high-confidence regions. In this embodiment, it is preferable that in the t-th iteration (t≥2), when recalculating the correlation tensor R, only M is retained.guide The query feature corresponding to the region with a value of 1 participates in the matching, while the remaining positions are set to zero, i.e., let F... q4 ^(t) = F q4 ∙M guide , where ∙ denotes element-wise multiplication, followed by F q4 ^(t) replaces the original F q4 Used for subsequent correlation tensor calculations.

[0039] The joint attention enhancement feature F is updated in each iteration. joint ^(t) and the segmentation probability plot P pred ^(t). Experiments show that after three rounds of iteration, the segmentation results tend to stabilize, and the average intersection-union ratio improves by about 2.1 percentage points, proving that the iterative mechanism can effectively refine the segmentation results, especially in regions with fuzzy boundaries and large intra-class differences.

[0040] To further illustrate the practical application of this invention, the inventors have demonstrated its application in specific scenarios: 1. In the autonomous driving scenario understanding task, real-time segmentation of newly appearing road obstacles (such as construction cones and temporary roadblocks) is required, but only 1 to 3 labeled samples can be obtained. The input support set contains 2 labeled cone images, and the query image is a street scene captured in real time by an onboard camera. First, multi-scale features are extracted through a dual-branch network to generate multi-granular prototypes of the cones. Then, channel and spatial attention are calculated to focus on the orange reflective stripes and cone-shaped contour region of the cones. After multi-dimensional attention fusion, the main body of the cones is initially segmented. Then, through two rounds of iterative optimization, the segmentation gaps caused by changes in lighting and occlusion are gradually repaired, and finally, a complete and continuous cone mask is output, providing accurate obstacle information for the path planning module. In this scenario, the proposed method achieves a 1-shot average intersection-union ratio of 65.8% in a small subset test on the KITTI dataset, which is significantly better than benchmark models such as PANet (56.3%) and PFENet (58.1%).

[0041] 2. In the skin lesion segmentation scenario of medical imaging, using only 3 labeled cases as the support set on the ISIC-2018 dataset, lesion region segmentation was performed on new dermoscopic images. Because the boundaries of lesion regions are blurred and their colors are similar to normal skin, traditional methods are prone to oversegmentation or undersegmentation. This invention captures the texture (low-level) and overall shape (high-level) features of the lesion through multi-granularity prototypes, and strengthens boundary supervision by combining edge-aware loss. Ultimately, a Dice coefficient of 0.867 and a segmentation accuracy of 91.3% were achieved, meeting the accuracy requirements for clinical auxiliary diagnosis.

[0042] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. It will be apparent to those skilled in the art that the invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the scope of the invention. No reference numerals in the claims should be construed as limiting the scope of the claims.

[0043] Furthermore, it should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This narrative style is merely for clarity. Those skilled in the art should consider the specification as a whole, and the technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.

Claims

1. A few-sample image semantic segmentation optimization method incorporating an attention mechanism, characterized in that, include: A dual-branch feature extraction network is constructed to process support set images and query images; The binary mask of the target category is extracted from the labeled mask of the support set image, and then the binary mask is weighted and averaged with the multi-scale feature map extracted from the corresponding branch to obtain the category prototype vector at each scale. The prototype vectors at different levels are then fused into a unified multi-granularity category prototype through cross-scale feature aggregation. Based on the similarity between the high-level feature map extracted from the query image and the multi-granularity category prototype, a dot product operation is used to generate a channel attention map, where the response value of each channel reflects the relevance of the channel feature to the current segmentation task, and the channel attention weight distribution is constrained to the range of 0 to 1 by a normalization function. A correlation tensor is constructed by utilizing the pixel-level matching relationship between the feature maps of the support set image and the query image. Cross-image feature alignment is achieved by transposing the correlation tensor, and a two-dimensional convolutional layer is applied to the correlation tensor to capture local structural dependencies, outputting a spatial attention weight map. The channel attention weights are multiplied element-wise with the original feature map to complete the channel dimension feature recalibration. At the same time, the spatial attention weight map and the channel weighted feature map are fused position-wise to form joint attention-enhanced features. The joint attention-enhanced features and multi-granularity category prototypes are used to calculate pixel similarity to generate a preliminary segmentation probability map, and an edge-aware loss function is introduced to supervise the prediction results. Based on the initial segmentation probability map, the feature alignment threshold of spatial attention is dynamically adjusted, and the aforementioned steps are repeated until the segmentation result converges or the preset number of iterations is reached.

2. The method according to claim 1, characterized in that, The construction of a dual-branch feature extraction network for processing support set images and query images includes: each branch uses a deep residual network as the backbone network, introduces dilated convolution after the fourth residual block to expand the receptive field, and outputs a multi-scale feature map sequence, wherein the multi-scale feature map sequence includes feature maps of the second, third and fourth stages, with spatial resolutions of 1 / 8, 1 / 16 and 1 / 32 of the input image, respectively.

3. The method according to claim 1, characterized in that, The cross-scale feature aggregation adopts a gated feature selection mechanism, which includes a weight vector with learnable parameters to dynamically allocate the contribution ratio of prototype vectors at each scale, and the fusion vector dimension is consistent with the highest layer feature.

4. The method according to claim 1, characterized in that, The correlation tensor is constructed as follows: The high-level feature maps of the query image and the support set image are expanded in the spatial dimension and matrix multiplication is performed to generate a correlation mapping of size H×W×H'×W'. By compressing the height and width dimensions through max pooling, we obtain the H×W spatial attention base map.

5. The method according to claim 1, characterized in that, The edge-aware loss function consists of cross-entropy loss and boundary-weighted loss. The boundary-weighted loss extracts the edge regions of the true labels through morphological gradient operators and assigns edge pixels a loss weight that is 5 times that of non-edge pixels.

6. The method according to claim 1, characterized in that, The pixel-level similarity calculation is based on the cosine similarity formula. The cosine value of the angle between the feature vector of each pixel position in the query image and the prototype vector of the multi-granularity category is calculated. The resulting similarity score is transformed into the probability distribution of each category by the softmax function.