Defect image segmentation system based on CNN-transformer feature fusion and boundary constraint
The defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints, combined with lightweight design and semi-supervised training strategy, solves the problems of difficulty in capturing global contextual information and insufficient labeled data in underwater defect image segmentation, and achieves efficient and accurate defect segmentation results.
Patent Information
- Application Number
- CN202611318397.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-28
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2046-08-28
AI Technical Summary
Existing fully convolutional neural networks struggle to accurately capture the global contextual information of cracks in underwater defect image segmentation, leading to misjudgments or breakages. Furthermore, traditional methods rely too heavily on labeled data, making them difficult to apply effectively in underwater environments.
We employ a defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints. This system combines a UNet-like encoder-decoder structure with local and global feature extraction capabilities. Explicit boundary constraints are provided through parallel edge detection branches. A semi-supervised training strategy is used to leverage unlabeled data, and a lightweight module is designed to reduce computational overhead.
It achieves precise pixel-level segmentation of underwater cracks and corrosion defects, improving segmentation accuracy and computational efficiency, and is suitable for real-time on-site detection in underwater engineering projects.
Smart Images

Figure CN122867162B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and more specifically to a defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints. Background Technology
[0002] The underwater environment suffers from numerous degradation problems, and image enhancement can transform degraded underwater defect images into normal-quality defect images.
[0003] Cracks and corrosion on the surface of underwater structures are two common but distinct types of defects. Corrosion typically presents as diffuse, irregularly edged blocky areas, and its detection relies heavily on the precise capture of local color, texture, and other features. Cracks, on the other hand, appear as elongated, continuous, or even branching linear structures. For enhanced defect images, pixel-level segmentation of these two key defects—cracks and corrosion—is crucial. Accurate crack segmentation requires not only capturing local edge details but also understanding its overall topological structure and long-range dependencies. Traditional fully convolutional neural networks, through stacked convolutional layers, have limited receptive fields, making them prone to fragmentation or misjudgment when processing targets like cracks that require global contextual information to accurately determine continuity. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to overcome the shortcomings of the prior art and provide a defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints.
[0005] The present invention is achieved through the following technical solution: a defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints, including an image input module, a defect segmentation model TransHR-Net and an output module; The image input module is used to receive the defect image after underwater image enhancement processing, as the input feature map of the defect segmentation model TransHR-Net; The defect segmentation model TransHR-Net adopts a UNet-like encoder-decoder structure, which integrates the local feature extraction capabilities of CNN models and the global feature extraction capabilities of Transformer models. It provides explicit boundary constraints through parallel edge detection branch modules to segment defects in the input feature map. The output module is used to output the image after defect segmentation by the defect segmentation model TransHR-Net.
[0006] The encoder of the defect segmentation model TransHR-Net has 4 layers; The encoder has two hybrid residual modules in its first and second layers, respectively, to capture local details of the defect image; The third and fourth layers of the encoder each include two hybrid residual modules and a global feature extraction module, which are used to understand the global topological structure and long-range dependencies of the defective image.
[0007] In each layer of the encoder, the first hybrid residual module halves the size of the input feature map by setting a step size of 2, thus achieving downsampling; The second hybrid residual module is used for feature extraction on the downsampled feature map.
[0008] In the third and fourth layers of the encoder, after the first hybrid residual module downsamples the input feature map, it first performs global feature extraction through the global feature extraction module using a self-attention mechanism, and then the second hybrid residual module performs local information fusion and refinement.
[0009] The feature maps output by each layer of the encoder are denoted as follows: , , , Its input decoder and parallel edge detection branch module; The decoder fuses the features from each layer of the encoder by upsampling layer by layer; Parallel edge detection branch modules act on the feature map of the encoder. and This generates an independent edge map for supervising image edge information.
[0010] The hybrid residual module includes a three-stage operation process: dimensionality reduction, feature extraction, and dimensionality increase. In dimensionality reduction, a compression factor is introduced. ,use Standard convolution, by changing the channel dimension, compresses the input channel C to Cmid = C / e, thereby reducing the computational complexity of feature extraction operations. In the feature extraction operation, based on depthwise separable convolution, a lightweight depthwise convolution is first used to perform spatial filtering on each channel, and then a 1x1 pointwise convolution is used to complete the information exchange between channels. In the dimensionality upscaling operation, a standard 1x1 convolution is used to complete the channel dimensionality upscaling.
[0011] The global feature extraction module includes a pair of consecutive Transformer modules, which balance local feature extraction and global information interaction by alternately applying two different self-attention mechanisms. The first Transformer module employs windowed multi-head self-attention (W-MSA) to strictly limit computation to non-overlapping local windows; The second Transformer module uses Shift Window Multi-Head Self-Attention (SW-MSA) to establish a connection across the window boundary of the first Transformer module by strategically displacing the window mesh. The global feature extraction module follows a variant Transformer structure with pre-normalization.
[0012] The edge detection branch module first processes the feature map through two parallel 1x1 general convolutional modules. and ; then feature map After upsampling and The feature maps are concatenated along the channel dimension to generate a fused feature map. Finally, a 3x3 general convolutional module is used to perform deep fusion on the fused feature map, and a 1x1 convolutional head is used to generate a single-channel predicted edge map.
[0013] The defect segmentation model TransHR-Net uses a composite loss function. Including the primary segmentation loss and auxiliary edge loss It is represented as follows: ; in, These are weighting coefficients used to balance the contribution of edge loss.
[0014] The defect segmentation model TransHR-Net is trained using a semi-supervised training strategy.
[0015] Compared with the prior art, the beneficial effects of the present invention are: At the model design level, this application integrates the local feature extraction capabilities of CNNs and the global feature extraction capabilities of Transformers, and provides explicit boundary constraints through a parallel module. This enables it to accurately extract local details such as crack textures and rust edges, while also effectively modeling long-range dependencies of defects and global topological structures.
[0016] At the training strategy level, in order to reduce the dependence on labeled data, this application proposes a semi-supervised training strategy UD-SSL, which makes full use of a large amount of unlabeled data by adopting pseudo-labels and consistency strategies.
[0017] The model in this application adopts a lightweight modular design, reducing computational overhead while ensuring segmentation accuracy. Compared with traditional segmentation schemes, this invention has higher segmentation accuracy, more complete defect contours, and excellent computational efficiency, meeting the needs of real-time on-site detection in underwater engineering projects. Attached Figure Description
[0018] Figure 1 This is a network architecture diagram of the defect segmentation model TransHR-Net; Figure 2 This is a schematic diagram of the receptive field of a CNN model; Figure 3 This is a diagram of the hybrid residual module architecture; Figure 4 This is a schematic diagram of the standard convolution calculation process; Figure 5 This is a schematic diagram of the computation process for depthwise separable convolution; Figure 6 This is a schematic diagram illustrating the operating principle of the global feature extraction module; Figure 7 This is a schematic diagram illustrating the operating principle of multi-head self-attention; Figure 8 This is the architecture diagram of the global feature extraction module; Figure 9 This is a diagram of the edge detection branch architecture; Figure 10 This is a schematic diagram of the fully supervised training strategy. Figure 11 This is a schematic diagram of the operation of a semi-supervised training strategy; Figure 12 This is a schematic diagram of each operation in the weak disturbance strategy; Figure 13 This is a schematic diagram of each operation in the strong disturbance strategy; Figure 14 This is a schematic diagram of the CutMix output; Figure 15 The results are from the TransHR-Net defect segmentation model in Example 2, showing the segmentation results of cracks of different shapes. Detailed Implementation
[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0020] Example 1 Considering that accurate defect segmentation highly depends on the precise definition of its boundaries, introducing an explicit edge supervision mechanism into the network can effectively improve segmentation accuracy. Based on this, this embodiment proposes a defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints for pixel-level segmentation of underwater structural cracks and corrosion defects. The system is designed to simultaneously capture local details and global information. The system includes an image input module, a defect segmentation model (TransHR-Net), and an output module.
[0021] The image input module is used to receive the image-enhanced defect image as the input feature map of the defect segmentation model TransHR-Net.
[0022] Unlike underwater image enhancement tasks that focus on improving image quality, pixel-level defect segmentation tasks inherently require high computational density. Furthermore, the Transformer module used to extract global features also consumes a significant amount of computation, further exacerbating model complexity and training costs. Therefore, the design of defect segmentation networks should balance high performance and lightweight design. Based on this, this application incorporates numerous lightweight improvement strategies into the design of the defect segmentation model TransHR-Net, and its network architecture design is as follows: Figure 1 As shown.
[0023] At the model design level, the defect segmentation model TransHR-Net integrates the local feature extraction capabilities of CNN (Convolutional Neural Network) models with the global feature extraction capabilities of Transformer models, and provides explicit boundary constraints through a parallel module. At the training strategy level, to reduce the dependence on labeled data, this application proposes a semi-supervised training method UD-SSL, which makes full use of a large amount of unlabeled data by employing pseudo-labels and consistency strategies.
[0024] Furthermore, the overall structure of the defect segmentation model TransHR-Net in this application adopts a UNet-like encoder-decoder structure. Its encoder part is mainly divided into four layers, with the core modules being the Hybrid Residual Module (HRM, hereinafter referred to as the HRM module) representing CNN and the global feature extraction module (SwinTransformer Module, STM, hereinafter referred to as the STM module) representing Transformer. For example... Figure 1 As shown, the encoder's first and second layers (shallow layers) each include two HRM modules, and the third and fourth layers (deep layers) each include two HRM modules and one STM module.
[0025] To ensure the overall lightweight nature of the network, the encoder part of TransHR-Net adopted the lightweight design approach of ResNet, which involves downsampling before feature extraction.
[0026] Specifically, for each layer of the encoder, the first HRM module halves the size of the input feature map by setting a stride of 2, achieving a downsampling effect. The second HRM module then performs feature extraction on this downsampled feature map. This strategy effectively improves computational efficiency. For an input feature map... If the traditional post-downsampling method is used, its computational complexity is... Approximately: ; In the formula, B is the batch size, and H and W are the height and width of the input feature map, respectively. and is the number of channels in the input and output feature maps, and k is the kernel size.
[0027] If the improved approach of downsampling used in TransHR-Net is adopted, the length and width of the feature map are halved due to downsampling, while the number of input and output channels remains unchanged. Therefore, the computational complexity increases. This will reduce the cost to 1 / 4 of the original, which is beneficial for the lightweight design of TransHR-Net. The calculation formula is as follows: .
[0028] The TransHR-Net encoder in this application employs a hybrid hierarchical design and applies it to the problem of fusing local and global features. In the first two layers, representing the shallow stage, the network consists of efficient HRM modules, whose core task is to accurately capture the local high-frequency details of defects. In the last two layers, representing the deep stage, the network's task shifts to understanding the global topology and long-range dependencies of defects, which is something CNN models are not good at. This is because the receptive field formed by stacked convolutional layers in CNN models is static and uniform when aggregating long-range information. This means that to establish a connection between two distant points on a crack, the network must introduce a large number of background pixels as noise. This square receptive field based on spatial proximity is severely mismatched with the narrow, linear topology of cracks, thus diluting key features and increasing the risk of misjudgment. The receptive field of CNN models, such as... Figure 2 As shown.
[0029] To overcome the inherent limitation of the limited receptive field in CNN models, the TransHR-Net encoder employs a composite structure design of "HRM→STM→HRM" in the deep layers. The first HRM module is responsible for downsampling the input feature map to improve complexity. The design presents a lightweight structure; subsequently, the core STM module extracts global features through a self-attention mechanism; finally, a second HRM module further fuses and refines local information based on the globally weighted features. This design, which embeds the STM module into the CNN model workflow, allows the STM module to focus on its strength in global relational reasoning, while tasks such as local detail processing and feature smoothing are handled by the two efficient HRM modules, thus achieving an optimal combination of the advantages of CNN and Transformer models.
[0030] After layer-by-layer feature extraction by the hybrid encoder, the feature maps output from the first to the fourth layers are denoted as follows: , , , Multi-scale features The data is fed into the decoder and the parallel Edge Detection Branch (EDB) module. The decoder upsamples layer by layer, fusing the deepest features from the encoder, which contain global context, with shallow features from skip connections that retain high-resolution details. Simultaneously, the parallel edge detection branch module directly operates on the shallow features of the encoder. and This generates an independent edge map to supervise image edge information. This edge map will serve as an explicit boundary constraint during training, enhancing the network's ability to perceive defect contours, thereby ultimately improving the accuracy of the segmentation results.
[0031] As the core building block of the TransHR-Net architecture, the HRM module achieves the same receptive field with a computational complexity far lower than that of a standard 3x3 convolution through dual optimizations in structure and convolution operations. This lays the foundation for the lightweight design of the entire network. Its structural design is as follows: Figure 3 As shown.
[0032] The main path of the HRM module follows a three-stage process: dimensionality reduction, feature extraction, and dimensionality enhancement. Dimensionality reduction is achieved by introducing a compression factor. ,use Standard convolution, by only changing the channel dimension, compresses the input channels C into C1. mid (C mid =C / e), thereby reducing the computational complexity of intermediate feature extraction. To quantify its advantages, this embodiment compares the computational complexity difference of 3x3 convolution in the standard process and in the three-stage process.
[0033] Assuming the input feature map has a length of H and a width of W, and both input and output channels have C, then the computational complexity of a 3x3 convolution in the standard case is... as follows: ; Its computational complexity in the three-stage process for: ; The computational complexity under the three-stage process is reduced to the following ratio compared to the standard case. : ; When the compression factor e takes the minimum value of 4 Maximum, at this time Only 1 / 8 of that. In addition, due to dimensionality reduction, the 1x1 standard convolution used in the dimensionality increase operation does not change the receptive field. Therefore, the three-stage process can significantly reduce the computational complexity while ensuring that the receptive field remains unchanged, and achieves lightweighting of the HRM module at the design level.
[0034] Building upon the three-stage workflow design, the HRM module further optimizes its core feature extraction process by replacing standard convolutions with depthwise separable convolutions, which have lower computational costs. Figure 4 and Figure 5 The computation process of standard convolution and depthwise separable convolution is shown respectively.
[0035] Depthwise separable convolution decouples the spatial filtering and channel information fusion processes of standard convolution. First, a lightweight depthwise convolution is used to perform spatial filtering independently on each channel, and then a 1x1 pointwise convolution is used to complete the information exchange between channels.
[0036] To quantify the improved computational efficiency, the above assumptions are adopted, and for the feature extraction operation in the HRM module, both its input and output channels are... Given an input feature map with length H and width W, the computational complexity of a standard 3x3 convolution is... The calculation is shown in the following formula: ; The computational complexity of a 3x3 depth separable convolution is... The sum of two steps: ; By comparing the two formulas above, the computational complexity reduction ratio of 3x3 depth-separable convolution compared to standard convolution is shown. As shown in the following formula: .
[0037] In practical applications, The value of is much greater than 9, so depthwise separable convolution is used, which reduces the computational complexity to 1 / 9 of the original, while maintaining the same receptive field as the standard case. Therefore, by optimizing the core operator through depthwise separable convolution, the HRM module achieves further reduction in computational complexity. Combining the three-stage process and depthwise separable convolution optimization strategies, the final computational complexity of the HRM module is... as follows: ; When e is 4, the formula for calculating the computational complexity reduction ratio is as follows.
[0038] .
[0039] As can be seen, the HRM module can reduce the computational complexity to 1 / 16 of the original while ensuring the same receptive field. As the basic module that runs through the entire TransHR-Net, the lightweight improvement strategy of the HRM module lays the foundation for the overall lightweight design of the model.
[0040] To overcome the inherent bottleneck of CNN models in capturing long-range dependencies, TransHR-Net introduces an STM module in the deeper stages of the encoder. As a Transformer variant tailored for visual tasks, the STM module is designed to avoid the quadratic computational complexity and memory overhead issues caused by standard self-attention mechanisms when processing high-resolution feature maps. The functionality of the STM module relies on a self-attention mechanism, the principle of which is as follows... Figure 6 As shown in the diagram, this mechanism allows the network to evaluate the degree of interaction between elements in a sequence. By dynamically calculating the weight distribution, the network can allocate more computational resources to the features most relevant to the current task, thereby constructing an information-rich contextual representation.
[0041] As an extension of self-attention, multi-head self-attention (MSA) allows the network to learn information jointly across multiple parallel representation spaces. Specifically, the query (Q), key (K), and value (V) of the input sequence are first independently projected into multiple groups, each constituting an attention head. Each head is responsible for capturing a specific type of dependency pattern of the input features. Subsequently, these parallelly computed attention outputs are integrated to form a more dimensional feature representation, the principle of which is as follows: Figure 7 As shown.
[0042] Unlike multi-head self-attention mechanisms that perform computations across the entire feature map, the STM module employs a window-based, efficient attention strategy. Its basic computational unit consists of a pair of consecutive Transformer modules, with the overall architecture as follows: Figure 8 As shown, this pair of modules efficiently balances local feature extraction and global information interaction by alternately applying two different self-attention mechanisms. Specifically, the first module uses Window-based Multi-head Self-Attention (W-MSA), which strictly restricts computation to non-overlapping local windows, thus significantly reducing computational overhead. To compensate for the limited receptive field caused by W-MSA, the subsequent second module uses Shifted Window Multi-head Self-Attention (SW-MSA), which establishes connections across the window boundaries of the previous module by strategically shifting the window grid. Internally, the STM module follows a variant Transformer structure with pre-normalization, consisting of an (S)W-MSA module and a Multilayer Perceptron (MLP) for feature transformation as its core components. Each component is preceded by a normalization layer (LayerNorm), and residual connections are applied afterward to ensure effective gradient propagation.
[0043] In defect segmentation tasks, accurately defining the complex and ever-changing defect boundaries is crucial in determining the upper limit of the final detection accuracy. To further improve the boundary accuracy of defect segmentation, TransHR-Net introduces a parallel edge detection branch module. This module is a lightweight auxiliary network designed to provide an explicit edge supervision signal to the backbone network through multi-task learning, thereby enhancing TransHR-Net's ability to perceive and locate defect contours. The design concept of the EDB module is as follows: Figure 9 As shown. Considering the feature maps extracted by the backbone network in the shallow stage of the encoder. and The EDB module takes these two features as inputs to effectively preserve the high-frequency edge information of defects.
[0044] The EDB module, as an auxiliary branch, only needs to accept features extracted from the shallow stage of the main encoder, perform fusion, and make the final prediction; its function is relatively simple. Therefore, the design of the EDB module in this application is also relatively simple. This simple and efficient design principle ensures that the introduction of the EDB module as an auxiliary branch does not bring excessive training overhead. Furthermore, in the internal structure of the EDB module, it first processes the output features of the shallow stage of the main encoder through two parallel 1x1 general convolutional modules. and Due to different sizes, Upsampling is required before it can be used with The features are concatenated along the channel dimension to generate a fused feature map. Finally, a 3x3 general convolutional module is used to perform deep fusion of the fused features, and a 1x1 convolutional head generates a single-channel predicted edge map.
[0045] The EDB module plays several roles in network training. Firstly, through multi-task learning, it guides the network to learn high-quality feature representations more sensitive to contours in the shallow encoder stages. These features, through skip connections, benefit the final segmentation task. Secondly, the output of the EDB module co-calculates the loss with the edge reference labels, providing explicit boundary constraints for the final segmentation result. Notably, the EDB module is only activated during training, thus incurring no additional computational overhead. Through this efficient design, the EDB module significantly improves the segmentation accuracy of TransHR-Net for defect contours with minimal training cost. The ablation experiments later in this chapter will further quantify the accuracy improvement effect of the EDB module on TransHR-Net.
[0046] To effectively drive TransHR-Net to learn the complex mapping from the input image to pixel-level labels and to fully utilize the auxiliary supervision information provided by the edge detection branch EDB, this application designs a composite loss function. The loss function consists of the main segmentation loss. and auxiliary edge loss It consists of two weighted components, as defined in the following formula: ; in, These are weighting coefficients used to balance the contribution of edge loss.
[0047] Main segmentation loss The output of the main branch network of TransHR-Net is directly affected by Focal Loss (dynamic cross-entropy loss function, denoted as...). ) and Dice Loss (semantic segmentation loss function, denoted as Dice Loss) It consists of two parts, aiming to collaboratively solve two major problems in semantic segmentation: class imbalance and structural accuracy.
[0048] ; Traditional fully supervised learning-based training strategies heavily rely on large-scale, high-quality labeled data. In the specific industrial application scenario of underwater defect detection, the underwater environment makes it difficult to obtain defect images. Furthermore, pixel-level semantic segmentation and annotation is an extremely time-consuming and labor-intensive task. These two factors combined result in an inherent predicament of insufficient labeled data for underwater defect detection. If only a small amount of data is used for training, the model is prone to overfitting, thus limiting its generalization ability. Therefore, traditional fully supervised training strategies are not suitable for the application scenario described in this application. To overcome the limitation of insufficient labeled data, this application adopts a semi-supervised training strategy.
[0049] The core of semi-supervised training strategies lies in utilizing a large amount of unlabeled data to assist model training. For example... Figure 10 As shown, the fully supervised training strategy is limited to a single loop of "labeled data, model training, and loss calculation"; while... Figure 11 As shown, the semi-supervised training strategy adds a parallel loop of "unlabeled data, predicted pseudo-labels, and consistency constraints" to this approach. The consistency constraint refers to the model maintaining a high degree of consistency in its predictions for different perturbation versions of unlabeled data. By regularizing this consistency constraint, the network can learn more generalizable visual feature representations from unlabeled data, thus effectively improving the model's performance and generalizability without increasing the amount of labeled data.
[0050] To overcome the limitation of insufficient labeled data, this application proposes a semi-supervised training strategy called UD-SSL (Underwater Defect Semi-Supervised Learning), which combines the characteristics of cracks and corrosion. This strategy follows two widely validated core theories in the field of semi-supervised training: entropy minimization and consistency regularization. Entropy minimization theory refers to the ability to generate pseudo-labels by utilizing the model's high-confidence predictions on unlabeled data. Consistency regularization theory states that the model should produce the same prediction results for different perturbation versions of the same data, guiding the model to learn robust features insensitive to appearance changes. UD-SSL combines these two theories and, by designing data perturbation schemes tailored to the characteristics of cracks and corrosion defects, ultimately constructs an efficient semi-supervised training framework suitable for the underwater defect detection task in this study.
[0051] Semi-supervised training strategies require training on unlabeled data I uDifferent levels of data perturbation are applied to construct the learning signal required for the consistency regularization theory. The strength of the perturbation is a key trade-off. If the perturbation is too weak, the learning signal lacks challenge and has limited significance in improving the model's robustness; if the perturbation is too strong, it may destroy the original key features of the image, causing the model to learn incorrect mappings and degrading its performance. To address this issue, UD-SSL employs a strong-weak perturbation separation design. By constraining the model to maintain consistency in its predictions for both weakly and strongly perturbated versions of the same image, it simultaneously satisfies the requirements for the reliability of the supervision signal and the challenge of the learning objective.
[0052] Specifically, the weak perturbation strategy T adopted by UD-SSL w It mainly consists of three operations in sequence: scaling, cropping, and horizontal flipping, and its effect is as follows: Figure 12 As shown. T is a combination of purely geometric transformations. w Only the target's scale, position, and pose in the image are changed, without altering its color, texture, or internal structure. This design ensures the model's compatibility with weakly perturbated image data to the greatest extent possible. The predictions exhibit high stability and high confidence, thus providing high-quality pseudo-labels for subsequent consistency learning.
[0053] With weak perturbation strategy T w Correspondingly, the strong perturbation strategy T s It is responsible for generating challenging learning objectives. Its design philosophy is to maximize the visual variations of an image while keeping core features unchanged, thereby guiding the model to learn more fundamental, high-level semantic representations that are insensitive to changes in low-level visual features. For example... Figure 13 As shown, T in UD-SSL s In T w Building upon the geometric transformations it incorporates, it further integrates dramatic color and structural perturbations. Specifically, T s It consists of a random combination of operations such as color dithering, affine transformation, grayscale conversion, and Gaussian blur. By applying these strongly perturbative operations to unlabeled image data, a large number of visually distinct but semantically identical training samples can be generated. This provides challenging input for subsequent consistency regularization.
[0054] Typically, a set of images with varying degrees of perturbation This allows the construction of the learning signals required for consistency regularization theory. However, this constraint may cause the model to memorize mapping relationships under specific strong perturbation patterns rather than learn true semantic invariance; furthermore, it primarily focuses on pixel-level changes, which is detrimental to the model learning region-level contextual understanding and spatial smoothness. To address this, UD-SSL introduces a two-stream strong perturbation structure, which generates two independent strong perturbation versions of the same original image. and .in, It will be used for standard consistency learning, and This is then used for a more advanced CutMix consistency regularization.
[0055] CutMix consistency regularization is key to UD-SSL's implementation of multiple constraints. For example... Figure 14 As shown, this regularization mechanism will, based on a randomly generated binary matrix, Some of the prediction results were replaced with those from CutMix generates a hybrid prediction by providing a more reliable corresponding prediction. It simulates real-world scenarios where the target is partially occluded and information is incomplete. By encouraging the model to make judgments consistent with the original high-confidence pseudo-labels in its hybrid prediction, it breaks the assumption of pixel-level independent predictions, pushing the model to rely on neighboring contextual information during decision-making, thereby improving its understanding of the region's context. Furthermore, CutMix guides the model to generate spatially smoother and more continuous segmentation results, which is crucial for ensuring the integrity of continuous structures such as cracks and corrosion.
[0056] In summary, UD-SSL's dual-stream strong perturbation mechanism constructs a richly layered semi-supervised training framework through strong and weak perturbation separation, a dual-stream strong perturbation structure, and CutMix spatial perturbation. The various data perturbation strategies employed are as follows: For weakly perturbated data, scaling enhances the model's adaptability to the target scale; cropping enhances the model's adaptability to the target location; and horizontal flipping enhances the model's adaptability to mirror symmetry. For data with strong perturbations, affine transformation is used to simulate camera pose changes, improving geometric invariance; color dithering is used to simulate lighting and color changes, improving color invariance; grayscale conversion makes the model more dependent on texture and structural information; and Gaussian blur is used to simulate image sharpness loss, improving robustness to blur. For spatially perturbation-type data, CutMix is used to simulate target occlusion, enhancing the model's ability to understand regional context.
[0057] In the semi-supervised training framework of UD-SSL, the total loss function L of TransHR-Net is composed of two weighted parts: the supervised loss Lsup and the unsupervised loss Lunsup, as shown below: ; in, The calculation is performed on the labeled data. It is a weighting coefficient used to balance the contribution of unsupervised loss, which is introduced in this application as an unsupervised loss. Calculations are performed on unlabeled data, and it consists of a standard consistency loss term. Consistency loss term with CutMix It consists of two parts, as shown below: .
[0058] The calculation of both unsupervised loss terms relies on a set of weakly perturbed data. Generated high-confidence pseudo-labels This process will... The input is fed into the model, and the class with the highest softmax output probability is selected. The process is shown in the following formula: .
[0059] The aim is to constrain the model for strongly perturbated versions. Prediction and pseudo-labels The consistency between them is obtained by calculating the cross-entropy loss (LCE) between them, and its formula is defined as follows: ; Where n is the total number of pixels and C is the total number of categories. It is a one-hot vector, which is 1 if the true class of pixel i is c, and 0 otherwise. pi,c are the probabilities that the model predicts pixel i belongs to class c. Therefore, Lu is specifically calculated as follows: ; This loss term enables TransHR-Net to learn to handle drastic appearance changes T. s1 Insensitive, more essential semantic representation.
[0060] To further enhance the model's ability to understand regional context, A CutMix perturbation strategy is introduced in the prediction space. This process first obtains the second strongly enhanced version. Prediction Then, based on a randomly generated binary mask M... mix (Representing the CutMix area), will Part of the use The corresponding prediction result is replaced to obtain a hybrid prediction P. mix The overall process is shown in the following formula: .
[0061] That is, mixed prediction P mix With pseudo-tags The consistency loss between them is calculated as follows: .
[0062] This loss term guides the model to make correct predictions based on the neighboring context when information is incomplete, thereby improving the spatial smoothness and continuity of the segmentation results.
[0063] By minimizing simultaneously and TransHR-Net can learn key features from limited labeled data to distinguish between background pixels and defect pixels, and it also has strong generalization ability from unlabeled data.
[0064] The output module is used to output the image after defect segmentation by the defect segmentation model TransHR-Net.
[0065] Example 2 This embodiment constructs a defect segmentation dataset and trains and evaluates the defect segmentation model TransHR-Net described in Embodiment 1.
[0066] The defect segmentation dataset consists of images enhanced to eliminate underwater degradation. LabelMe annotation software was then used to perform fine pixel-level annotations on some of these images. Finally, a small number of publicly available high-quality defect images were combined to construct a labeled training dataset of 800 images with accurate segmentation labels. To complement the UD-SSL semi-supervised training strategy, this embodiment randomly selected 3200 defect images from the unlabeled data at a 1:4 ratio for auxiliary training. Additionally, 200 labeled images were selected to form a separate test set for model performance evaluation.
[0067] like Figure 15As shown in the figure, this embodiment demonstrates the segmentation results of the TransHR-Net defect segmentation model on cracks of different morphologies. It can be seen that the TransHR-Net defect segmentation model proposed in this application exhibits high segmentation accuracy and robustness in most cases. For fine cracks, even those with a width of only a few pixels and low contrast with the background, the model can still accurately capture and generate continuous and complete predicted masks. For robust cracks, the model's prediction results highly match the true labels in terms of contour, and no obvious breaks or adhesions are observed. When facing complex crack networks containing multiple branches, TransHR-Net can also accurately distinguish each independent crack branch and perform pixel-level precise localization.
[0068] To objectively evaluate the overall performance of the defect segmentation model TransHR-Net, this embodiment quantitatively compares it with various semantic segmentation models. The comparison models are divided into two categories: one category includes classic segmentation models such as FCN, UNet, and Deeplab, whose effectiveness has been widely validated in segmentation tasks across multiple domains. The second category consists of domain-specific models designed specifically for defect segmentation tasks, including CSModel, TransMUNet, CTCNet, and HrSegNet. The comparison with these models aims to measure the relative performance and advancement of TransHR-Net in the defect detection field. All models were trained and tested under a unified dataset and experimental configuration. Their performance in segmentation accuracy (primarily measured by IoU and F1-Score) and computational complexity (primarily measured by GFLOPs) is shown in Table 1.
[0069] Table 1. Quantitative Comparison of TransHR-Net and Various Semantic Segmentation Models
[0070] Referring to Table 1, TransHR-Net demonstrates an overwhelming performance advantage over classic models. In terms of segmentation accuracy, TransHR-Net achieves improvements of over 30% and 27% in IoU compared to FCN (IoU: 0.6520) and UNet (IoU: 0.6842), respectively. Even compared to Deeplab (IoU: 0.7832), which introduces dilated convolutions to expand the receptive field, TransHR-Net still surpasses FCN by over 17% in IoU. This shows that while classic models have a certain degree of versatility, their structural design struggles to effectively handle the complex topologies of cracks and corrosion defects. In terms of complexity, UNet, due to its simple symmetrical structure and efficient skip connection strategy, achieves the lowest computational complexity (GFLOPs: 648.42) among the three classic models. Therefore, TransHR-Net uses the UNet architecture as its baseline and, through a series of lightweight design features, achieves segmentation accuracy far exceeding that of UNet with significantly lower computational overhead.
[0071] TransHR-Net also demonstrated superior performance compared to domain-specific models designed for defect segmentation tasks. While domain-specific models generally achieved significant improvements in segmentation accuracy through targeted design, with IoU scores mostly ranging from 0.85 to 0.90, TransHR-Net achieved IoU of 0.9576 and an F1-Score of 0.9717, surpassing the domain-specific models used for comparison in segmentation accuracy. Furthermore, TransHR-Net also exhibited lower computational complexity than most domain-specific models, giving it a performance advantage.
[0072] The above description is merely an optional embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural transformations made using the content of the present invention under the concept of the present invention, or direct / indirect applications in other related technical fields, are included within the patent protection scope of the present invention.
Claims
1. A defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints, characterized in that, It includes an image input module, a defect segmentation model TransHR-Net, and an output module; The image input module is used to receive the defect image after underwater image enhancement processing, as the input feature map of the defect segmentation model TransHR-Net; The defect segmentation model TransHR-Net adopts a UNet-like encoder-decoder structure, which integrates the local feature extraction capabilities of CNN models and the global feature extraction capabilities of Transformer models. It provides explicit boundary constraints through parallel edge detection branch modules to segment defects in the input feature map. The encoder of the defect segmentation model TransHR-Net has 4 layers; The encoder has two hybrid residual modules in its first and second layers, respectively, to capture local details of the defect image; The third and fourth layers of the encoder each include two hybrid residual modules and a global feature extraction module, which are used to understand the global topological structure and long-range dependencies of the defect image. The hybrid residual module includes a three-stage operation process: dimensionality reduction, feature extraction, and dimensionality increase. In dimensionality reduction, a compression factor is introduced. ,use Standard convolution, by changing the channel dimension, compresses the input channel C to Cmid = C / e, thereby reducing the computational complexity of feature extraction operations. In the feature extraction operation, based on depthwise separable convolution, a lightweight depthwise convolution is first used to perform spatial filtering on each channel, and then a 1x1 pointwise convolution is used to complete the information exchange between channels. In the dimensionality upscaling operation, a standard 1x1 convolution is used to complete the channel dimensionality upscaling; The global feature extraction module includes a pair of consecutive Transformer modules, which balance local feature extraction and global information interaction by alternately applying two different self-attention mechanisms. The first Transformer module employs windowed multi-head self-attention (W-MSA) to strictly limit computation to non-overlapping local windows; The second Transformer module uses Shift Window Multi-Head Self-Attention (SW-MSA) to establish a connection across the window boundary of the first Transformer module by strategically displacing the window mesh. The global feature extraction module follows a variant Transformer structure with pre-normalization. The feature maps output by each layer of the encoder are denoted as follows: , , , Its input decoder and parallel edge detection branch module; The decoder fuses the features from each layer of the encoder by upsampling layer by layer; Parallel edge detection branch modules act on the feature map of the encoder. and Generate an independent edge map for supervising image edge information; The edge detection branch module first processes the feature map through two parallel 1x1 general convolutional modules. and ; then feature map After upsampling and The feature maps are concatenated along the channel dimension to generate a fused feature map. Finally, a 3x3 general convolutional module is used to perform deep fusion on the fused feature map, and a 1x1 convolutional head is used to generate a single-channel predicted edge map. The output module is used to output the image after defect segmentation by the defect segmentation model TransHR-Net.
2. The defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints according to claim 1, characterized in that, In each layer of the encoder, the first hybrid residual module halves the size of the input feature map by setting a step size of 2, thus achieving downsampling; The second hybrid residual module is used for feature extraction on the downsampled feature map.
3. The defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints according to claim 2, characterized in that, In the third and fourth layers of the encoder, after the first hybrid residual module downsamples the input feature map, it first performs global feature extraction through the global feature extraction module using a self-attention mechanism, and then the second hybrid residual module performs local information fusion and refinement.
4. The defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints according to claim 1, characterized in that, The defect segmentation model TransHR-Net uses a composite loss function. Including the primary segmentation loss and auxiliary edge loss It is represented as follows: ; in, These are weighting coefficients used to balance the contribution of edge loss.
5. The defect image segmentation system based on CNN-Transformer feature fusion and boundary constraints according to claim 1, characterized in that, The defect segmentation model TransHR-Net is trained using a semi-supervised training strategy.
Citation Information
Patent Citations
Medical image segmentation device based on global information perception
CN116258933A
Transform-CNN medical image segmentation method and system based on multi-scale fusion semantic enhancement
CN120318256A
