A semantic segmentation training method based on endogenous boundaries and adaptive focusing mechanism
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-23
- Publication Date
- 2026-08-14
AI Technical Summary
传统语义分割训练方案在处理复杂目标形态时存在明显的边界感知局限性
[0043]本发明的有益效果是:创新性地引入了SDF梯度引导注意力模块与隐式梯度蒸馏机制,使得网络能够在特征提取阶段直接感知边界法向量,并利用该方向向量控制特征沿着平行于边界的走向进行各向异性扩散,阻断了跨越不同语义区域的特征平滑污染。另一方面,还构建了基于距离场动态衰减的自适应聚焦权重函数,使模型在训练的全生命周期中,能够自动将优化重心锁定在难分且关键的边界窄带区域内。不仅如此,该方案通过联合损失函数的深层结构化耦合,无需在实际部署推理阶段额外输入任何真实的距离场或梯度数据,而且仅凭网络自身提取的图像特征即可实现高精度的几何拓扑约束,大幅增强了网络对微小目标和细粒度轮廓的分割表现力。
Smart Images

Figure CN122574378A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer vision and deep learning technology, and specifically relates to a semantic segmentation training method based on endogenous boundaries and adaptive focusing mechanisms. Background Technology
[0002] Semantic segmentation, as one of the core foundational tasks in computer vision, aims to assign specific predefined semantic category labels to each pixel in an image, thereby achieving pixel-level fine-grained understanding of image content. Traditional semantic segmentation training schemes suffer from significant limitations in boundary awareness when handling complex target shapes. On the one hand, existing conventional training paradigms mainly rely on supervised strategies based on region overlap, such as cross-entropy loss and Dice loss. These strategies treat all pixels equally at the global level, lacking sufficient optimization sensitivity for high-frequency boundary regions that account for a small proportion, leading to easy blurring or over-smoothing of contours during network prediction. On the other hand, although some methods attempt to introduce signed distance fields as additional loss terms, this approach only remains at the numerical penalty level at the end of network prediction, failing to deeply intervene in the internal physical process of feature extraction. This results in feature intrusion across different semantic boundaries when convolutional kernels perform spatial feature aggregation. Moreover, existing boundary constraint methods often use static distance scalars to calculate weights and lack the mining of deep spatial gradient direction information such as boundary normals, making it difficult for models to achieve adaptive geometric focusing for high curvature or extremely complex topological structures. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a semantic segmentation training method based on endogenous boundaries and adaptive focusing mechanisms to solve the aforementioned technical problems.
[0004] The semantic segmentation training method based on endogenous boundaries and adaptive focusing mechanism includes the following steps:
[0005] S1: Obtain the training images and their corresponding real semantic segmentation labels;
[0006] S2: Convert the real semantic segmentation labels into a signed distance field SDF image, and calculate the spatial gradient of the signed distance field SDF image to obtain the real SDF gradient field;
[0007] S3: Input the training image into a semantic segmentation network containing an SDF gradient-guided attention module to extract image features; predict a pseudo gradient field based on the SDF gradient-guided attention module for the image features, and use the pseudo gradient field to perform anisotropic diffusion on the image features to obtain an enhanced feature map; output a predicted segmentation probability map based on the enhanced feature map.
[0008] S4: Based on the signed distance field SDF image, calculate the pixel weight matrix that dynamically changes with distance;
[0009] S5: Construct a joint loss function, calculate the total loss using the joint loss function, and update the parameters of the semantic segmentation network through backpropagation; the joint loss function includes: a basic segmentation loss based on the predicted segmentation probability map and the real label, an SDF intrinsic boundary loss based on the predicted segmentation probability map and the signed distance field SDF image, a boundary bandwidth weighted loss combined with the pixel weight matrix, and a gradient distillation loss used to constrain the pseudo gradient field to approximate the real SDF gradient field.
[0010] Preferably, the method for converting real semantic segmentation labels into a signed distance field SDF image in step S2 specifically includes the following steps:
[0011] Calculate the Euclidean distance from each pixel in the image to its nearest boundary pixel;
[0012] The Euclidean distance of pixels inside the target region is defined as positive, the Euclidean distance of pixels outside the target region is defined as negative, and the Euclidean distance of pixels at the boundary is defined as zero, thus obtaining the original distance field.
[0013] The original range field is truncated using a truncation threshold and then linearly normalized to... The interval is used to obtain the signed range field SDF image. ,in For pixel index.
[0014] Preferably, the calculation of the true SDF gradient field in step S2 specifically includes the following steps:
[0015] The first-order spatial partial derivatives of the signed distance field SDF image in the horizontal direction and the first-order spatial partial derivatives in the vertical direction are obtained using the Sobel operator.
[0016] By merging the first-order spatial partial derivatives in the horizontal and vertical directions of any pixel, the true SDF gradient vector is obtained. .
[0017] Preferably, the execution process of the SDF gradient-guided attention module in step S3 specifically includes the following steps:
[0018] The image features are mapped using a side-branch network consisting of convolutional layers and activation functions, outputting a pseudo-gradient field with the same resolution as the image features. ,in These are the spatial coordinates of the image features;
[0019] The pseudo gradient field As a guiding signal, the anisotropic diffusion is performed on the image features.
[0020] Preferably, the mathematical expression for the anisotropic diffusion is as follows:
[0021] For any center pixel on the initial feature map Its enhanced features after diffusion The calculation formula is:
[0022] ,
[0023] in, For pixels The local spatial neighborhood, For neighboring pixels The original characteristics; The diffusion weight is calculated using the following formula:
[0024] ,
[0025] in, This is the scaling factor; when the neighborhood offset direction... With pseudo gradient vector When parallel, the diffusion weight approaches a minimum; when the neighborhood offset direction With pseudo gradient vector When vertical, the diffusion weight approaches its maximum value.
[0026] Preferably, the pixel weight matrix in step S4 The calculation formula is:
[0027] ,
[0028] in, The values of the normalized signed range field SDF image. It is a nonlinear hyperparameter.
[0029] Preferably, the basic segmentation loss in step S5 Including binary cross-entropy loss and Dice loss The calculation formula is:
[0030] ,
[0031] in:
[0032] in, To predict the segmentation probability map, For real labels, The total number of pixels contained in the input image / feature map. To prevent the smoothing of extremely small constant terms with a denominator of zero.
[0033] Preferably, the SDF intrinsic boundary loss in step S5 and boundary bandwidth weighted loss The calculation formulas are as follows:
[0034] ,
[0035] ,
[0036] in, This is a penalty image, for the background pixels... , For foreground pixels, , ; It represents the pixel-by-pixel binary cross-entropy value.
[0037] Preferably, the gradient distillation loss in step S5 The cosine similarity loss is used for construction, and its calculation formula is as follows:
[0038] ,
[0039] in, This represents the total number of pixels in the feature map. To downsample the real SDF gradient field to a reference gradient field with the same resolution as the feature map.
[0040] Preferably, the joint loss function The expression is:
[0041] ,
[0042] in, To balance the basic segmentation loss hyperparameter coefficients, Weighted loss for boundary bandwidth hyperparameter coefficients, To balance the loss terms hyperparameter coefficients, Basic segmentation loss.
[0043] The beneficial effects of this invention are as follows: It innovatively introduces an SDF gradient-guided attention module and an implicit gradient distillation mechanism, enabling the network to directly perceive the boundary normal vector during the feature extraction stage and utilize this direction vector to control the anisotropic diffusion of features along a path parallel to the boundary, thus preventing feature smoothing contamination across different semantic regions. Furthermore, it constructs an adaptive focusing weight function based on dynamic decay of the distance field, allowing the model to automatically lock the optimization focus on difficult-to-distinguish and critical narrow-band boundary regions throughout the entire training lifecycle. Moreover, through deep structured coupling of the joint loss function, this scheme eliminates the need for any additional input of real distance field or gradient data during the actual deployment and inference stage. It achieves high-precision geometric topological constraints solely based on the image features extracted by the network itself, significantly enhancing the network's segmentation capabilities for small targets and fine-grained contours. Attached Figure Description
[0044] To more clearly illustrate the technical solutions in the embodiments of this application 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 this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0045] Figure 1 A schematic diagram of the semantic segmentation training method based on endogenous boundary and adaptive focusing mechanism provided by the present invention;
[0046] Figure 2 The graph shows the functional relationship between the distance field SDF image and pixel weights in the semantic segmentation training method based on endogenous boundary and adaptive focusing mechanism provided by this invention. Detailed Implementation
[0047] The following disclosure provides many different embodiments or examples for implementing various embodiments of the invention. To simplify the disclosure, specific embodiments are described below. Of course, these are merely examples and are not intended to limit the scope of the invention.
[0048] The embodiments of the invention will now be described in detail with reference to the accompanying drawings.
[0049] like Figure 1 As shown, the semantic segmentation training method based on endogenous boundaries and adaptive focusing mechanism includes the following steps:
[0050] S1: Obtain the training images and their corresponding real semantic segmentation labels;
[0051] S2: Convert the real semantic segmentation labels into a signed distance field SDF image, and calculate the spatial gradient of the signed distance field SDF image to obtain the real SDF gradient field;
[0052] S3: Input the training image into a semantic segmentation network containing an SDF gradient-guided attention module to extract image features; predict a pseudo gradient field based on the SDF gradient-guided attention module for the image features, and use the pseudo gradient field to perform anisotropic diffusion on the image features to obtain an enhanced feature map; output a predicted segmentation probability map based on the enhanced feature map.
[0053] S4: Based on the signed distance field SDF image, calculate the pixel weight matrix that dynamically changes with distance;
[0054] S5: Construct a joint loss function, calculate the total loss using the joint loss function, and update the parameters of the semantic segmentation network through backpropagation; the joint loss function includes: a basic segmentation loss based on the predicted segmentation probability map and the real label, an SDF intrinsic boundary loss based on the predicted segmentation probability map and the signed distance field SDF image, a boundary bandwidth weighted loss combined with the pixel weight matrix, and a gradient distillation loss used to constrain the pseudo gradient field to approximate the real SDF gradient field.
[0055] To address the issues of blurred contours caused by smoothing convolutional features across boundaries in traditional semantic segmentation, and the lack of deep geometric constraints, this invention first acquires training images containing the target object and discrete real semantic segmentation labels. Next, it uses Euclidean distance transformation to convert the real labels into a signed distance field (SDF) image, and employs a spatial difference operator to extract its spatial partial derivatives, constructing a spatial gradient field representing the real boundary normal vector. Subsequently, the training image is input into a decoding network with an SDF gradient-guided attention module to extract image features. This attention module directly predicts a pseudo-gradient field based on the current spatial features and uses this pseudo-gradient field as a directional guide for image segmentation. The features undergo anisotropic diffusion operation, specifically by suppressing spatial fusion of features in the direction parallel to the pseudo-gradient and promoting spatial smoothing of features in the direction perpendicular to the pseudo-gradient, thereby outputting an enhanced feature map and a predicted segmentation probability map with well-preserved high-frequency edge information. Simultaneously, a non-linearly decaying pixel weight matrix is constructed using the distance values from the signed distance field (SDF) image, assigning higher weights to pixels closer to the boundary. Finally, a joint loss function is calculated, consisting of the basic segmentation loss, SDF intrinsic boundary loss, bandwidth-weighted loss, and a cosine distillation loss that forces the predicted pseudo-gradient field to approximate the true gradient field. Backpropagation is then used to update the network parameters. The core principle of this design lies in sinking the concept of geometric normal vectors from physical topology to the feature extraction structure layer. An implicit knowledge distillation mechanism forces the network to develop a self-awareness of the target boundary orientation during the training phase, autonomously controlling the feature diffusion behavior through spatial direction vectors. Compared to existing technologies that only apply a distance scalar penalty at the output end, this implementation method fundamentally blocks cross-boundary smoothing contamination of heterogeneous semantic features through deep coupling of structure and method, significantly improving the edge resolution accuracy for complex high curvature topological targets, and does not require input of the real distance field during the inference stage, without adding any computational burden.
[0056] More specifically, the method for converting real semantic segmentation labels into a signed distance field SDF image in step S2 includes the following steps:
[0057] Calculate the Euclidean distance from each pixel in the image to its nearest boundary pixel;
[0058] The Euclidean distance of pixels inside the target region is defined as positive, the Euclidean distance of pixels outside the target region is defined as negative, and the Euclidean distance of pixels at the boundary is defined as zero, thus obtaining the original distance field.
[0059] The original range field is truncated using a truncation threshold and then linearly normalized to... The interval is used to obtain the signed range field SDF image. ,in For pixel index.
[0060] In this method, the SDF cutoff range A fixed value is set to ensure training stability. Furthermore, the truncation range can be dynamically adjusted based on the error distribution during training, thereby adaptively expanding the boundary constraint range. Specifically, after obtaining the training images and their corresponding ground truth segmentation labels, the Euclidean distance from each pixel in the image to the nearest boundary pixel is first calculated. Then, this Euclidean distance is assigned a corresponding sign characteristic, specifically defined as follows: the Euclidean distance of pixels inside the target region is positive, the Euclidean distance of external pixels is negative, and the Euclidean distance of boundary pixels is strictly zero, thus constructing the original distance field. Next, to ensure stability in the early stages of training and focus on the boundary region, a preset fixed truncation threshold is used to truncate the original distance field, filtering out redundant distance information that is too far from the boundary, and linearly normalizing the truncated distance values to... Within the interval, a standardized and uniform signed distance field SDF image is obtained. The core principle of this design is to accurately represent the geometric topology and internal / external relationships of the target in a continuous real-valued space. Simultaneously, truncation and normalization operations effectively limit the fluctuation range of distance values, preventing gradient explosion during backpropagation in deep networks and ensuring that the model focuses its optimization attention on difficult-to-segment narrow-band boundary regions. Compared to traditional techniques that rely solely on discrete labels and lack distance awareness, this implementation, through the construction of a continuous signed distance field, provides the network with rich pixel-level spatial location priors and boundary morphology information. This enables the model to significantly improve edge resolution accuracy and topological fidelity when processing segmented targets with complex high curvature features.
[0061] More specifically, the calculation of the true SDF gradient field in step S2 includes the following steps:
[0062] The first-order spatial partial derivatives of the signed distance field SDF image in the horizontal direction and the first-order spatial partial derivatives in the vertical direction are obtained using the Sobel operator.
[0063] By merging the first-order spatial partial derivatives in the horizontal and vertical directions of any pixel, the true SDF gradient vector is obtained. .
[0064] To address the problem of lost boundary spatial orientation information caused by relying solely on scalar distance fields in traditional semantic segmentation training, this invention first acquires a continuous signed distance field SDF image during segmentation. Then, using the Sobel discrete differential operator or the finite difference method, convolution operations are performed on the horizontal and vertical directions of this signed distance field SDF image to calculate its first-order spatial partial derivatives in an orthogonal coordinate system. Next, the separated horizontal and vertical partial derivatives at the same pixel are merged into tensors to synthesize a true SDF gradient vector with a clear direction and magnitude. The core mathematical principle behind this step is that the gradient direction at any spatial location in a continuous distance field strictly corresponds to the direction of the steepest numerical change. Therefore, the physical meaning of the obtained true SDF gradient vector is equivalent to the normal vector pointing to the nearest semantic boundary, providing the model with absolute geometric priors regarding the spatial orientation of the target contour. This allows the model to not only know the specific location of the boundary but also its geometric orientation, eliminating directional blindness during feature space aggregation.
[0065] More specifically, the execution process of the SDF gradient-guided attention module in step S3 includes the following steps:
[0066] The image features are mapped using a side-branch network consisting of convolutional layers and activation functions, outputting a pseudo-gradient field with the same resolution as the image features. ,in These are the spatial coordinates of the image features;
[0067] The pseudo gradient field As a guiding signal, the anisotropic diffusion is performed on the image features.
[0068] In practice, after inputting the training image into the semantic segmentation network and extracting image features, the image features are fed into the SDF gradient-guided attention module. Through a side branch network composed of several convolutional layers and nonlinear activation functions, the input image features are mapped to channels and spatial dimensions, directly predicting and outputting a pseudo gradient field with the same spatial resolution as the current image features. Subsequently, the generated pseudo gradient field As a directional guiding signal, it acts on the original image features, performing anisotropic diffusion operations on them. The core principle of this design lies in endowing the network structure with implicit geometric awareness. The pseudo-gradient field predicted by the side branch network using image features is essentially a simulation of the target boundary normal vector, which serves as a diffusion guide, enabling features to have directional selectivity when performing neighborhood fusion: suppressing feature exchange in the direction parallel to the pseudo-gradient vector (i.e., the direction across the boundary), and promoting feature smoothing in the direction perpendicular to the pseudo-gradient vector (i.e., along the direction of the boundary). Compared with the shortcomings of existing technologies that only apply scalar penalties to the terminal output without intervening in the internal feature extraction process, this implementation introduces an explicit diffusion mechanism based on directional vectors at the feature map level through deep coupling of structure and method. This directly blocks the cross-boundary fusion of heterogeneous semantic features, improves the model's edge resolution accuracy for complex high-curvature topological targets, and the pseudo-gradient field is predicted entirely by the network itself during the inference stage, without introducing a dependence on the real label.
[0069] More specifically, the mathematical expression for the anisotropic diffusion is as follows:
[0070] For any center pixel on the initial feature map Its enhanced features after diffusion The calculation formula is:
[0071] ,
[0072] in, For pixels The local spatial neighborhood, For neighboring pixels The original characteristics; The diffusion weight is calculated using the following formula:
[0073] ,
[0074] in, This is the scaling factor; when the neighborhood offset direction... With pseudo gradient vector When parallel, the diffusion weight approaches a minimum; when the neighborhood offset direction With pseudo gradient vector When vertical, the diffusion weight approaches its maximum value.
[0075] To address the issue that traditional convolutional operations can easily lead to the smooth fusion of heterogeneous semantic features across boundaries, resulting in blurred contours, when performing feature aggregation within the local receptive field. This invention, when processing irregularly shaped lesion edge segmentation tasks, for any central pixel in the initial feature map, its enhanced feature is obtained by weighted summation of the original features of all pixels in the local spatial neighborhood. In this process, the diffusion weight is calculated based on a preset scaling factor and the negative exponent of the squared dot product of the pseudo-gradient vector and the neighborhood spatial offset vector, after undergoing global neighborhood normalization. The core mathematical and physical principle of this design lies in utilizing the geometric projection properties of the vector dot product: since the pseudo-gradient vector implicitly represents the normal vector pointing to the nearest semantic boundary, the neighborhood offset direction... With pseudo gradient vector When parallel, i.e., attempting to cross semantic boundaries, the absolute value of the dot product reaches its maximum. After negative exponential mapping, the diffusion weights converge sharply to a minimum value, thus physically blocking the mutual penetration of cross-boundary features; conversely, when the neighborhood offset direction... With pseudo gradient vector When perpendicular to the target boundary, the dot product is zero, and the negative exponent term reaches its maximum, thus fully promoting efficient feature fusion within homogeneous semantic regions. Compared to existing technologies that employ isotropic convolution kernels or standard attention mechanisms lacking geometric direction guidance, this implementation directly internalizes the spatial topological orientation of the signed distance field as an aggregation barrier in the feature extraction stage, eliminating edge feature contamination and significantly improving the model's analytical sharpness and segmentation accuracy for complex, high-curvature contours.
[0076] More specifically, in step S4, the pixel weight matrix The calculation formula is:
[0077] ,
[0078] in, The values of the normalized signed range field SDF image. It is a nonlinear hyperparameter.
[0079] In specific segmentation tasks, based on a signed distance field image normalized to the positive and negative intervals, the absolute value of the distance to each pixel is first extracted to represent its absolute spatial span to the nearest semantic boundary. Then, this absolute distance value is subtracted by a unit value, and a nonlinear hyperparameter exponentiation operation is applied to the entire difference, thereby outputting a pixel weight matrix with spatial awareness. The core principle of this design lies in constructing a nonlinear spatial distance decay mapping function with the geometric topological boundary as its highest peak value. Pixels perfectly positioned on the boundary receive full maximum weight because their absolute distance is zero. As the pixel's spatial location extends into the target's core area or the vast external background, its weight in the loss calculation exhibits an exponential and rapid decay controlled by the nonlinear hyperparameter, such as... Figure 2 As shown. Compared to conventional approaches that apply equal error penalties to all pixels or use only static class weights in existing technologies, this implementation uses an adaptive focusing mechanism to precisely anchor and lock the gradient update momentum of the model during backpropagation within a narrow boundary region that is prone to confusion. This overcomes the edge blunting caused by the smoothing of regional features from the underlying mechanism, and significantly improves the model's analytical sharpness and topological fidelity for complex geometric shapes.
[0080] More specifically, the basic segmentation loss in step S5 Including binary cross-entropy loss and Dice loss The calculation formula is:
[0081] ,
[0082] in:
[0083] in, To predict the segmentation probability map, For real labels, The total number of pixels contained in the input image / feature map. To prevent the smoothing of extremely small constant terms with a denominator of zero.
[0084] When handling high-precision segmentation tasks, the basic segmentation loss term is first calculated. This term consists of a linear weighted sum of the binary cross-entropy loss and the Dice coefficient loss. The binary cross-entropy loss measures the global pixel-level classification error between the predicted segmentation probability map and the ground truth label, while the Dice loss focuses on optimizing the overlap between the predicted region and the ground truth target region and alleviating the class imbalance problem. Second, an SDF intrinsic boundary loss term is introduced, which forces the predicted probability distribution output by the network to be consistent with the standardized signed distance field in numerical space, thereby implicitly constraining the spatial location of the boundary in the continuous domain. At the same time, a boundary bandwidth weighted loss is constructed by combining the non-uniform pixel weight matrix derived from the signed distance field SDF image, giving higher optimization priority to pixels closer to the semantic boundary. Finally, a gradient distillation loss term is designed, which measures the directional consistency between the pseudo gradient field predicted by the network and the real SDF gradient field through cosine similarity, guiding the network to spontaneously learn the spatial distribution law of the boundary normal vector during the feature extraction stage. The core principle of this design lies in achieving precise control of the error propagation path through multi-level loss supervision: the base loss is responsible for overall region partitioning, the SDF loss establishes continuous spatial constraints, the weight matrix enables resource optimization, and gradient distillation injects geometric and topological priors into the latent space. Compared to existing technologies that rely solely on a single loss function or simple scalar distance enhancement schemes with discrete labels, this joint loss architecture, through deep coupling of mathematical form and physical meaning, enables the network to simultaneously optimize region coverage accuracy and boundary geometric fidelity during training, fundamentally solving the inherent defects of traditional methods in complex topological structures, such as boundary ambiguity and topological breaks.
[0085] More specifically, the SDF intrinsic boundary loss in step S5 and boundary bandwidth weighted loss The calculation formulas are as follows:
[0086] ,
[0087] ,
[0088] in, This is a penalty image, for the background pixels... , For foreground pixels, , ; It represents the pixel-by-pixel binary cross-entropy value.
[0089] After generating the predicted segmentation probability map, the SDF intrinsic boundary loss is first calculated. This loss maps the predicted probability values to the symbolic distance space and uses absolute error to measure the difference between the predicted probability map and the true SDF image. A predicted probability value close to 1 corresponds to a positive SDF region, and close to 0 corresponds to a negative SDF region. Next, the boundary bandwidth weighted loss is calculated. Based on the generated pixel weight matrix, the traditional binary cross-entropy loss is spatially modulated. That is, at each pixel location, the binary cross-entropy value is multiplied by the corresponding weight, forming enhanced supervision of the narrow boundary region. Finally, the basic segmentation loss, SDF intrinsic boundary loss, boundary bandwidth weighted loss, and gradient distillation loss are linearly combined according to preset weight coefficients to form a complete joint loss function to guide network parameter updates. The core principle of this design lies in constructing a multi-level geometric constraint system. The SDF intrinsic boundary loss transforms discrete category labels into continuous distance space supervision, forcing the network to learn the precise geometric shape of the target boundary. The boundary bandwidth weighted loss, through a non-linear weight function, concentrates optimization resources on the difficult-to-segment boundary regions, forming an adaptive focusing mechanism. Compared to existing technologies that rely solely on scalar segmentation loss, this implementation method integrates continuous geometric space constraints with adaptive weight allocation, enabling the network to simultaneously optimize global segmentation accuracy and local boundary sharpness during training. Taking building outline segmentation in remote sensing imagery as an example, this joint loss mechanism effectively suppresses jagged artifacts at building edges, improves edge continuity, and significantly enhances the boundary F1 score.
[0090] More specifically, the gradient distillation loss in step S5 The cosine similarity loss is used for construction, and its calculation formula is as follows:
[0091] ,
[0092] in, This represents the total number of pixels in the feature map. To downsample the real SDF gradient field to a reference gradient field with the same resolution as the feature map.
[0093] During training, a pseudo gradient field is first generated from the intermediate feature map through a side branch network. Simultaneously, the spatial gradient of the real SDF image is calculated after downsampling to the same scale as the feature map. The core principle of this design lies in internalizing explicit geometric topological knowledge into the network's implicit representation ability through a knowledge distillation mechanism. This forces the network to develop a deep understanding of the spatial distribution of boundary normals during the training phase, enabling it to autonomously predict boundary orientation based solely on the input image during the inference phase, without the assistance of any real SDF. Compared to existing technologies that only apply scalar distance constraints to the output layer, this implementation incorporates directional geometric priors at the source of feature extraction, significantly improving edge localization accuracy and topological connectivity when handling complex boundaries.
[0094] More specifically, the joint loss function The expression is:
[0095] ,
[0096] in, To balance the basic segmentation loss hyperparameter coefficients, Weighted loss for boundary bandwidth hyperparameter coefficients, To balance the loss terms hyperparameter coefficients, Basic segmentation loss.
[0097] After calculating the basic segmentation loss, SDF intrinsic boundary loss, boundary bandwidth weighted loss, and SDF gradient distillation loss during the model training phase, several independent hyperparameter coefficients are introduced. The aforementioned basic region supervision signals and multiple boundary geometric constraint signals are linearly weighted and summed to construct a joint loss function expression, which serves as the final source of the total gradient for network parameter backpropagation. The core principle of this design lies in establishing a multi-objective collaborative optimization framework. Different dimensions of loss terms are used to respectively handle region coverage measurement, continuous distance space regression, focusing on boundary-difficult regions, and feature-level anisotropic diffusion guidance. By balancing the order of magnitude of the error gradients through hyperparameters, the model ensures smooth convergence in the multi-task learning space. Compared to the boundary oversmoothing or topological breakage defects easily caused by single losses in existing technologies, this implementation provides the network with comprehensive and rigorous multimodal supervision information. Taking the segmentation of tiny scratches and defects on metal surfaces in industrial manufacturing scenarios as an example, this joint loss mechanism enables the model to not only accurately locate the defect area, but also precisely fit the slender and sharp edges of the scratch by relying on gradient guidance and distance field constraints, effectively preventing the omission of small branch structures and morphological distortion, and comprehensively improving the geometric fidelity of the overall invention in complex edge scenarios.
[0098] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be covered within the scope of the claims and specification of the present invention.
Claims
1. A semantic segmentation training method based on endogenous boundary and adaptive focusing mechanism, characterized in that, Includes the following steps: S1: Obtain the training image and its corresponding real semantic segmentation label; S2: Convert the real semantic segmentation label into a signed distance field (SDF) image, and calculate the spatial gradient of the signed distance field (SDF) image to obtain the real SDF gradient field; S3: Input the training image into a semantic segmentation network containing an SDF gradient-guided attention module to extract image features; predict a pseudo gradient field based on the SDF gradient-guided attention module for the image features, and use the pseudo gradient field to anisotropically diffuse the image features to obtain an enhanced feature map; output a predicted segmentation probability map based on the enhanced feature map; S4: calculate the pixel weight matrix that dynamically changes with distance based on the signed distance field SDF image; S5: construct a joint loss function, calculate the total loss using the joint loss function, and update the parameters of the semantic segmentation network through backpropagation; the joint loss function includes: a basic segmentation loss based on the predicted segmentation probability map and the real label, an SDF intrinsic boundary loss based on the predicted segmentation probability map and the signed distance field SDF image, a boundary bandwidth weighted loss combined with the pixel weight matrix, and a gradient distillation loss used to constrain the pseudo gradient field to approximate the real SDF gradient field.
2. The semantic segmentation training method based on endogenized boundary and adaptive focusing mechanism according to claim 1, characterized in that, Step S2, which converts the real semantic segmentation labels into a signed distance field SDF image, specifically includes the following steps: calculating the Euclidean distance from each pixel in the image to its nearest boundary pixel; defining the Euclidean distance of pixels inside the target region as positive, the Euclidean distance of external pixels as negative, and the Euclidean distance of boundary pixels as zero, to obtain the original distance field; truncating the original distance field using a truncation threshold and linearly normalizing it to... The interval is used to obtain the signed range field SDF image. ,in For pixel index.
3. The semantic segmentation training method based on endogenized boundaries and adaptive focusing mechanism according to claim 1, characterized in that, The method for calculating the true SDF gradient field in step S2 specifically includes the following steps: using the Sobel operator to obtain the first-order spatial partial derivatives of the signed distance field SDF image in the horizontal and vertical directions; merging the first-order spatial partial derivatives in the horizontal and vertical directions for any pixel to obtain the true SDF gradient vector. .
4. The semantic segmentation training method based on endogenized boundaries and adaptive focusing mechanism according to claim 1, characterized in that, The execution process of the SDF gradient-guided attention module in step S3 specifically includes the following steps: mapping the image features through a side-branch network composed of convolutional layers and activation functions, and outputting a pseudo-gradient field with the same resolution as the image features. ,in The spatial coordinates on the image features; the pseudo gradient field As a guiding signal, the anisotropic diffusion is performed on the image features.
5. The semantic segmentation training method based on endogenized boundaries and adaptive focusing mechanism according to claim 4, characterized in that, The mathematical expression for the anisotropic diffusion is as follows: For any center pixel on the initial feature map Its enhanced features after diffusion The calculation formula is: , in, For pixels The local spatial neighborhood, For neighboring pixels The original characteristics; The diffusion weight is calculated using the following formula: , in, This is the scaling factor; when the neighborhood offset direction... With pseudo gradient vector When parallel, the diffusion weight approaches a minimum; when the neighborhood offset direction With pseudo gradient vector When vertical, the diffusion weight approaches its maximum value.
6. The semantic segmentation training method based on endogenized boundaries and adaptive focusing mechanism according to claim 1, characterized in that, In step S4, the pixel weight matrix The calculation formula is: , in, The values of the normalized signed range field SDF image. It is a nonlinear hyperparameter.
7. The semantic segmentation training method based on endogenized boundaries and adaptive focusing mechanism according to claim 1, characterized in that, The basic segmentation loss in step S5 Including binary cross-entropy loss and Dice loss The calculation formula is: , in: ; in, To predict the segmentation probability map, For real labels, The total number of pixels contained in the input image / feature map. To prevent the smoothing of extremely small constant terms with a denominator of zero.
8. The semantic segmentation training method based on endogenous boundary and adaptive focusing mechanism according to claim 1, characterized in that, SDF intrinsic boundary loss in step S5 and boundary bandwidth weighted loss The calculation formulas are as follows: , , in, This is a penalty image, for the background pixels... , For foreground pixels, , ; It represents the pixel-by-pixel binary cross-entropy value.
9. The semantic segmentation training method based on endogenized boundaries and adaptive focusing mechanism according to claim 1, characterized in that, Gradient distillation loss in step S5 The cosine similarity loss is used for construction, and its calculation formula is as follows: , in, This represents the total number of pixels in the feature map. To downsample the real SDF gradient field to a reference gradient field with the same resolution as the feature map.
10. The semantic segmentation training method based on endogenized boundaries and adaptive focusing mechanism according to any one of claims 7 to 9, characterized in that, The joint loss function The expression is: ,in, To balance the basic segmentation loss hyperparameter coefficients, Weighted loss for boundary bandwidth hyperparameter coefficients, To balance the loss terms hyperparameter coefficients, Basic segmentation loss.