Highly efficient and precise methods and systems for segmenting surface defects in industrial products
By embedding CBAM and SENet modules into the U-Net network, efficient and accurate segmentation of surface defects in industrial products is achieved, solving the bottleneck of balancing efficiency and accuracy in existing technologies, and making it suitable for high-precision defect detection in complex backgrounds.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-03-30
- Publication Date
- 2026-06-26
AI Technical Summary
Existing U-Net-based methods for segmenting surface defects in industrial products struggle to balance high accuracy and efficiency while maintaining model simplicity. This is especially true in the context of small samples and complex textures, where existing solutions often lead to increased computational overhead and fail to effectively utilize attention mechanisms.
By embedding a combined channel-space attention module (CBAM) in the U-Net encoder and a squeeze and excitation network module (SENet) at the end of the decoder, a lightweight, staged attention layout strategy is adopted to improve defect segmentation accuracy and small sample generalization ability.
Without increasing the computational burden, it significantly improves the model's ability to identify small, irregular, or low-contrast defects, meeting the needs of smart manufacturing production lines for high accuracy, high real-time performance, and easy deployment.
Smart Images

Figure CN122290113A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision technology, and in particular to a highly efficient and accurate method and system for segmenting surface defects in industrial products. Background Technology
[0002] In the field of intelligent manufacturing, automatic detection of surface defects is a crucial step in ensuring product quality. In recent years, deep learning-based semantic segmentation methods, especially U-Net and its variants, have been widely applied in defect segmentation tasks due to their encoder-decoder symmetric structure and skip connection mechanism. To improve segmentation accuracy, researchers generally introduce attention mechanisms to enhance the model's ability to perceive key regions. However, existing solutions often employ a single attention module or stack it deep within the network. While this can improve performance to some extent, it often leads to a significant increase in model complexity and a decrease in inference speed, making it difficult to meet the practical demands of industrial environments for both high accuracy and high efficiency. Especially in the context of small sample sizes and complex textures, achieving the optimal balance between performance and efficiency through a sophisticated attention layout without significantly altering the backbone network remains a pressing technical challenge.
[0003] To address the aforementioned challenges, existing patents have proposed several improvement schemes. For example, CN119722666A discloses a strip steel surface defect detection method based on an attention mechanism and an improved UNet network. It introduces coordinate attention and an ASPP module into the encoder and embeds CBAM into the decoder to improve multi-scale feature fusion capabilities and positioning accuracy. CN117237370B proposes a tablet surface defect segmentation method combining feature fusion and an attention mechanism. It enhances the ability to identify minute defects by designing a novel downsampling module SAM and integrating SE attention in skip connections. Although these schemes have achieved certain results in specific scenarios, they share the common characteristic of requiring significant modifications to the network backbone or introducing multiple complex modules, leading to increased computational overhead. Furthermore, they do not consider the synergistic effect of the attention mechanism at different stages. None of these schemes solve the problem of how to achieve high-precision defect segmentation with extremely low computational increments through a lightweight, collaborative, and phased attention layout strategy while maintaining the simplicity of the original U-Net structure. Therefore, a new design approach is urgently needed to overcome the bottleneck of the trade-off between efficiency and accuracy in existing technologies. Summary of the Invention
[0004] In view of this, the present invention proposes an efficient and accurate method and system for industrial product surface defect segmentation. By embedding CBAM in the middle of the U-Net encoder and SENet at the end of the decoder, a lightweight, staged collaborative attention mechanism is constructed, which significantly improves the accuracy and small-sample generalization ability of industrial surface defect segmentation without increasing the computational burden.
[0005] This invention provides a highly efficient and accurate method for segmenting surface defects in industrial products, comprising the following steps: S1. Acquire a surface image of the industrial product to be inspected, and input the surface image into the encoder of the U-Net network for multi-scale feature extraction to obtain a first feature map; S2. After the encoder completes the initial N feature extractions, the first feature map is input into the combined channel-spatial attention module for processing to obtain the second feature map; S3. The second feature map is continued to be input into the subsequent layers of the encoder, and the feature maps of each layer of the encoder are passed to the decoder of the U-Net network through skip connections to obtain the third feature map; S4. The decoder upsamples and fuses the received third feature map to gradually restore the spatial resolution and obtain the fourth feature map; S5. After the decoder completes the last upsampling operation and before outputting the final segmentation result, the fourth feature map is input to the squeezing and excitation network module for processing to obtain the fifth feature map; S6. Pass the fifth feature map through a classification head to output a defect segmentation probability map with the same size as the input image.
[0006] Furthermore, the U-Net network adopts an encoder-decoder symmetric structure, wherein the encoder consists of consecutive convolutional blocks and downsampling operations, and the decoder consists of upsampling operations and convolutional blocks. The output feature map of the i-th layer of the encoder and the input feature map of the i-th layer of the decoder are concatenated through skip connections.
[0007] Furthermore, in the combined channel-spatial attention module, the input first feature map is first processed by the channel attention submodule to obtain an intermediate feature map; the intermediate feature map is then input into the spatial attention submodule for processing, and finally the second feature map is output.
[0008] Furthermore, the combined channel-spatial attention module processes the input feature map The processing includes the following steps: S21. Channel attention weighting, calculate the channel weight vector. : Where F is the input feature tensor of the convolutional block, It is an average pooling operation. It is a max pooling operation. MLP is a lightweight multilayer perceptron consisting of two fully connected layers. Using the Sigmoid activation function, we obtain the channel-weighted feature map. ,in Represents element-wise multiplication along the channel dimension; S22. Spatial attention weighting, calculating the spatial weight mask. : in It is an average pooling operation. It is a max pooling operation. Indicates channel splicing. This represents a convolution operation with a kernel size of 7×7; the output second feature map is... .
[0009] Furthermore, in the squeeze and excitation network module, the input fourth feature map is first squeezed to generate a global channel descriptor, then input to the excitation operation to generate a channel weight vector, and finally the fourth feature map is weighted by a scaling operation.
[0010] Furthermore, the squeezing and excitation network module processes the input feature map. The processing includes the following steps: S51. Extrusion Operation: ; in, Let H' be the global descriptor for the c-th channel, where C is the number of channels in the feature map, H' is the height of the feature map, and W' is the width of the feature map. It is a compression function that aggregates spatial dimensional information into channel-level descriptions; The value of the c-th channel at position (i,j) is given for the input feature map U. It is a two-dimensional matrix of the c-th channel; the global channel descriptor is obtained. ; S52. Stimulation Operation: ; in, This is the output channel weight vector. Here, g(z, W) is the activation function, and g(z, W) is the fully connected layer transformation during the activation process. To reduce the weights of the fully connected layer, The weights of the upgraded fully connected layer are δ, which is the ReLU function, σ, which is the Sigmoid function, and the reduction ratio is r=16. S53. Scaling Operation: Output the fifth feature map as follows ,in This represents element-wise multiplication of the channel dimension.
[0011] Furthermore, the method employs a binary cross-entropy loss function during the training phase: in For real labels, Here, N represents the probability predicted by the model, and N is the total number of pixels.
[0012] Furthermore, the training phase employs the Adam optimizer, with an initial learning rate set to... The batch size is 8, and the average intersection-union ratio is monitored on the validation set. If the ratio does not improve for 20 consecutive rounds, the training is terminated early.
[0013] Furthermore, the combined channel-spatial attention module is positioned after the fourth convolutional block of the encoder, and the squeezing and excitation network module is positioned after the last layer upsampling operation of the decoder.
[0014] Furthermore, the present invention also provides an efficient and accurate industrial product surface defect segmentation system, comprising: an image input module for acquiring a surface image of an industrial product to be inspected; an encoder module configured to perform multi-scale feature extraction on the surface image and output a first feature map after completing an initial N-fold feature extraction; a combined channel-spatial attention module for performing channel attention weighting and spatial attention weighting on the first feature map and outputting a second feature map; an encoder post-processing module for further feature extraction on the second feature map and outputting feature maps of each layer of the encoder through skip connections; a decoder module for upsampling and feature fusion of the received feature map to gradually restore spatial resolution and outputting a fourth feature map; a squeezing and excitation network module connected to the end of the decoder module and located after the final upsampling operation, for performing global channel recalibration on the fourth feature map and outputting a fifth feature map; and a segmentation output module for generating a defect segmentation probability map of the same size as the input image from the fifth feature map through a classification head.
[0015] The present invention has the following advantages over the prior art: After the encoder completes the initial feature extraction several times, a combined channel-space attention module (CBAM) is embedded, which enables the input feature map to be jointly weighted by the channel dimension and the spatial dimension in the early stage of feature abstraction. This effectively suppresses the interference caused by complex industrial backgrounds, strengthens the semantic response of potential defect areas, and prevents key details from being lost in subsequent downsampling processes.
[0016] Subsequently, before the decoder completes its final upsampling operation and is about to output the segmentation result, a squeeze and excitation network module SENet is introduced. It uses global average pooling to obtain the channel-level context information of the entire feature map and generates channel weights through a lightweight fully connected structure to globally calibrate the final feature representation, ensuring that the segmentation decision is based on the most discriminative channel.
[0017] Since both CBAM and SENet are plug-and-play modules with very few parameters, and this invention strictly retains the original encoder-decoder symmetric structure and skip connection mechanism of U-Net without making any structural changes to the backbone network, it significantly improves the model's ability to identify small, irregular or low-contrast defects without increasing the computational burden and inference latency.
[0018] Meanwhile, the improvements of this invention significantly reduce the model's dependence on the number of training samples, and it can still maintain stable and high-precision segmentation performance in industrial real-world scenarios with only a small number of labeled images, fully meeting the comprehensive requirements of intelligent manufacturing production lines for high accuracy, high real-time performance and easy deployment of online quality inspection systems. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is an example diagram of surface defect types in industrial products according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the RPC-U-Net network structure according to an embodiment of the present invention; Figure 3 This is the combined channel-space attention module structure according to an embodiment of the present invention; Figure 4 This is the extrusion and excitation network module structure according to an embodiment of the present invention; Figure 5 This is a comparison chart of segmentation results from different models in an embodiment of the present invention. Detailed Implementation
[0021] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. 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. It should be understood that the specific embodiments described herein are only used to explain the present invention, and not to limit the present invention.
[0022] This invention provides a highly efficient and accurate method for segmenting surface defects in industrial products, comprising the following steps: S1. Acquire a surface image of the industrial product to be inspected, and input the surface image into the encoder of the U-Net network for multi-scale feature extraction to obtain a first feature map; the U-Net network adopts an encoder-decoder symmetric structure, wherein the encoder consists of continuous convolutional blocks and downsampling operations, the decoder consists of upsampling operations and convolutional blocks, and the output feature map of the i-th layer of the encoder and the input feature map of the i-th layer of the decoder are concatenated by skip connections.
[0023] In one implementation, a surface image of the industrial product to be inspected is first acquired. The image originates from a high-resolution camera or scanning equipment on the industrial production line. Typical scenarios include surface quality inspection of products such as metal sheets, glassware, electronic chips, or pharmaceutical tablets. Figure 1 As shown, such images may contain various types of defects, such as scratches, stains, dents, cracks, holes, foreign objects, and bent, broken, or misaligned needles of electronic components. These defects vary significantly in shape, size, contrast, and background complexity, which places high demands on the robustness and generalization ability of the segmentation model.
[0024] The surface image is input into the encoder of the U-Net network to initiate the multi-scale feature extraction process. For example... Figure 2 As shown, the U-Net network employs a classic encoder-decoder symmetric structure. The encoder consists of four consecutive convolutional blocks, each containing two 3×3 convolutional layers, batch normalization (BatchNorm), and a ReLU activation function. A 2×2 max-pooling operation is then applied after each convolutional block to achieve downsampling, halving the spatial resolution of the feature map layer by layer while doubling the number of channels. This allows for the acquisition of highly abstract semantic information at deeper layers while preserving rich edge and texture details at shallower layers. After the encoder's first four feature extractions, the output feature map is the first feature map, approximately 1 / 16th the size of the original input. It contains preliminary semantic cues of defects without losing key spatial structures due to over-compression. Meanwhile, the decoder part of U-Net consists of a corresponding number of upsampling modules and convolutional blocks, which gradually restore the spatial resolution of the feature maps through transposed convolution or interpolation operations. Crucially, the output feature maps of each layer of the encoder are passed to the corresponding layer of the decoder through skip connections, and are concatenated with the upsampled feature maps at the input of the decoder in terms of channel dimension. For example, the 256-channel feature map output from the third layer of the encoder is merged with the 256-channel feature map upsampled from the third layer of the decoder to form a 512-channel fused feature map. This effectively integrates high-level semantics with low-level details, ensuring that the final segmentation result can accurately identify the defect category and precisely characterize its boundary shape.
[0025] S2. After the encoder completes the initial N feature extractions, the first feature map is input to the combined channel-spatial attention module for processing to obtain the second feature map. In the combined channel-spatial attention module, the input first feature map is first processed by the channel attention submodule to obtain an intermediate feature map. The intermediate feature map is then input to the spatial attention submodule for processing, and finally the second feature map is output. The combined channel-spatial attention module processes the input feature map... The processing includes the following steps: S21. Channel attention weighting, calculate the channel weight vector. : Where F is the input feature tensor of the convolutional block, It is an average pooling operation. It is a max pooling operation. MLP is a lightweight multilayer perceptron consisting of two fully connected layers. Using the Sigmoid activation function, we obtain the channel-weighted feature map. ,in Represents element-wise multiplication along the channel dimension; S22. Spatial attention weighting, calculating the spatial weight mask. : in It is an average pooling operation. It is a max pooling operation. Indicates channel splicing. This represents a convolution operation with a kernel size of 7×7; the output second feature map is... .
[0026] In one implementation, after the encoder completes the initial N feature extractions, the obtained first feature map is input into a combined channel-spatial attention module (CBAM) for processing to achieve adaptive enhancement of key defect regions and suppression of background noise. Here, N is a preset integer, typically 4, meaning this module is inserted after the encoder has completed the first four convolutional blocks and downsampling operations. At this point, the feature map size is approximately 1 / 16 of the original input, preserving sufficient spatial resolution to maintain local structural information while also possessing preliminary semantic expressive capabilities—an ideal stage for introducing an attention mechanism. Figure 2 As shown, the first feature map is output from the fourth convolutional block of the encoder and then fed into the combined channel-spatial attention module. This module is a lightweight plug-and-play component that does not change the U-Net backbone network structure. It only performs step-by-step weighted optimization of the feature map through two consecutive sub-modules, thereby significantly improving the model's ability to perceive industrial surface defects.
[0027] like Figure 3 As shown, the combined channel-spatial attention module first processes the input feature map. Channel attention weighting is performed. Specifically, the input feature map F is subjected to global average pooling (AvgPool(F)) and global max pooling (MaxPool(F)) along the spatial dimension to obtain two C-dimensional channel descriptors, reflecting the average and peak response intensities of each channel, respectively. These two descriptors are then input into a lightweight multilayer perceptron (MLP) consisting of two fully connected layers to learn the complex dependencies between channels and generate corresponding channel weight vectors. Finally, the outputs of the two MLPs are summed and normalized to the [0,1] interval using the sigmoid activation function σ to obtain the final channel attention weight vector. This represents the importance score of each channel. (The sentence is incomplete and requires more context to translate accurately.) Perform element-wise multiplication with the original feature map F along the channel dimension to obtain the channel-weighted intermediate feature map. This enables dynamic filtering of which channels are more important for defect identification. For example, when detecting metal scratches, the weight of edge-sensitive channels is amplified, while channels that mainly respond to background reflection are suppressed, thereby enhancing the expressive power of defect-related features in the channel dimension.
[0028] Next, the intermediate feature map The input is fed into the spatial attention submodule, which aims to identify which spatial locations in the image are of greater interest. Specifically, for Global average pooling and global max pooling are performed along the channel dimension to obtain two H×W spatial response maps, representing the average activation level and the strongest activation level at each location, respectively. These two maps are concatenated along the channel dimension to form an H×W×2 tensor, which is then passed through a 7×7 convolution kernel. Spatial modeling is performed to capture local contextual dependencies; finally, a spatial weight mask is generated using the Sigmoid activation function. Its value range is also [0,1], used to indicate the salience of each pixel position. By... and Perform element-wise multiplication in the spatial dimension to obtain the final output second feature map. This feature map highlights the response of potential defect areas in the spatial dimension, while reducing the contribution of uniform background or texture interference.
[0029] The design logic of the entire combined channel-spatial attention module follows a collaborative mechanism of channel-first, then spatial attention. Channel attention starts with "which features are important," prioritizing semantic channels related to defects; spatial attention further answers "where is more important," focusing on the specific location of the defect. This phased, multi-dimensional attention guidance strategy enables the model to achieve early localization and enhancement of defect regions in the mid-encoder stage, avoiding the loss of key information during subsequent downsampling, and is particularly suitable for low-contrast, small-sized defect detection scenarios. Compared to existing single attention mechanisms or late-stage stacked designs, this solution, by embedding CBAM in the mid-encoder stage, achieves dual enhancement of feature maps with almost no increase in computational overhead, significantly improving the model's robustness and segmentation accuracy, demonstrating the innovation and practicality of this invention in attention mechanism deployment strategy.
[0030] S3. The second feature map is continued to be input into the subsequent layers of the encoder, and the feature maps of each layer of the encoder are passed to the decoder of the U-Net network through skip connections to obtain the third feature map.
[0031] In one implementation, the second feature map obtained after processing by the combined channel-spatial attention module is further input into subsequent layers of the encoder for deeper feature extraction. During this process, each layer performs convolution, nonlinear transformations, and downsampling on the input feature map to capture high-level semantic information in the image. Meanwhile, a key design feature of this invention in the U-Net network architecture is the use of skip connections. These connections directly pass the feature maps generated by each layer of the encoder to the corresponding layers of the decoder.
[0032] Since each layer of the encoder contains information at different scales and levels, skip connections can directly pass the rich spatial details from shallow layers to the decoder. This helps to preserve edge and other detailed features while restoring image resolution. Furthermore, skip connections can effectively alleviate the vanishing gradient problem in deep networks, making training more stable and efficient.
[0033] Specifically, as the second feature map continues to propagate down the encoder, it undergoes multiple downsampling processes, generating a series of feature maps at different scales. These feature maps are then directly transmitted to the corresponding upsampling layers in the decoder via skip connections. In the decoder, each upsampling layer first upsamples the input low-resolution feature map, and then merges it with the feature map of the same scale from the encoder through element-wise addition or concatenation to form the third feature map.
[0034] pass Figure 2It's understandable that, assuming the second feature map is located in the middle of the encoder, it will sequentially pass through several convolutional and downsampling layers. Each downsampling iteration generates a feature map that is directly connected to the corresponding upsampling layer in the decoder via skip connections. In the decoder, as upsampling progresses, the feature map size gradually increases. Simultaneously, due to the presence of skip connections, the decoder can retrieve lost spatial information from the encoder, thus helping the model better reconstruct the high-resolution output.
[0035] S4. The decoder upsamples and fuses the received third feature map to gradually restore the spatial resolution and obtain the fourth feature map.
[0036] In one implementation, the decoder receives the third feature map generated in step S3 and uses it as a starting point to initiate a gradual spatial resolution recovery process. For example... Figure 2 As shown, the decoder adopts a hierarchical structure symmetrical to the encoder, containing multiple upsampling modules and convolutional blocks. Each layer performs upsampling operations and fuses feature information from the corresponding layer of the encoder.
[0037] Specifically, the third feature map is first used as input to the deepest layer of the decoder. It then undergoes an upsampling operation, typically using a 2×2 transposed convolution or bilinear interpolation followed by a 3×3 convolution to double its spatial resolution. Simultaneously, according to U-Net's skip connection mechanism, the feature map output by the encoder at the corresponding layer has been cached and concatenated with the upsampled feature map along the channel dimension to form a fused feature tensor. For example, if the upsampled feature map has 512 channels and the feature map from the skip connection also has 512 channels, the concatenation results in a 1024-channel fused feature map. This fused feature map then passes through one or more 3×3 convolutional layers to eliminate redundancy from the concatenation and learn cross-scale feature representations, ultimately outputting the decoded feature map for the current layer. This process is repeated layer by layer in the decoder; each time upsampling is completed, a layer of high-resolution details from the encoder is fused, gradually restoring the spatial size of the feature map to the original input size while continuously refining the semantic information. After processing through all decoding layers, the final output feature map is the fourth feature map. Its spatial resolution is consistent with the original input image, and it incorporates multi-scale contextual information from shallow to deep layers, containing both global semantics and preserving local details. The design mechanism of upsampling + skip connections + channel concatenation is the key to U-Net's high-precision boundary segmentation.
[0038] S5. After the decoder completes the last upsampling operation and before outputting the final segmentation result, the fourth feature map is input to the squeezing and excitation network module for processing to obtain the fifth feature map. In the squeezing and excitation network module, the input fourth feature map is first processed by a squeezing operation to generate a global channel descriptor, then input to an excitation operation to generate a channel weight vector, and finally weighted by a scaling operation. The squeezing and excitation network module processes the input feature map... The processing includes the following steps: S51. Extrusion Operation: ; in, Let H' be the global descriptor for the c-th channel, where C is the number of channels in the feature map, H' is the height of the feature map, and W' is the width of the feature map. It is a compression function that aggregates spatial dimensional information into channel-level descriptions; The value of the c-th channel at position (i,j) is given for the input feature map U. It is a two-dimensional matrix of the c-th channel; the global channel descriptor is obtained. ; S52. Stimulation Operation: ; in, This is the output channel weight vector. Here, g(z, W) is the activation function, and g(z, W) is the fully connected layer transformation during the activation process. To reduce the weights of the fully connected layer, The weights of the upgraded fully connected layer are δ, which is the ReLU function, σ, which is the Sigmoid function, and the reduction ratio is r=16. S53. Scaling Operation: Output the fifth feature map as follows ,in This represents element-wise multiplication of the channel dimension.
[0039] The combined channel-spatial attention module is positioned after the fourth convolutional block of the encoder, and the squeezing and excitation network module is positioned after the last layer upsampling operation of the decoder.
[0040] In one implementation, after the decoder completes the final upsampling operation and before outputting the final segmentation result, the fourth feature map is input to the Squeeze and Excitement Network (SENet) module for processing to achieve global adaptive calibration of channel-level features. Figure 2As shown, this step is located at the end of the U-Net decoder, after the last layer of upsampling and before the classification head, serving as the final quality gate before model output. At this point, the spatial resolution of the fourth feature map has been restored to match that of the original input image. It contains fine spatial structure information passed from the shallow layers of the encoder and rich semantic content extracted from the deep layers. However, there may still be an imbalance in response between different channels. Some channels may have overly strong responses due to noise or redundant information, while channels that truly play a crucial role in defect detection are suppressed. To address this issue, the SENet module is introduced to reweight the channel dimensions of the fourth feature map, thereby enhancing the expressive power of important channels and suppressing the influence of irrelevant channels.
[0041] like Figure 4 As shown, the squeezing and excitation network module first performs a squeezing operation. Specifically, for the input fourth feature map... For each channel c in the image, global average pooling is performed along the spatial dimensions (height H and width W) to calculate the average response value of that channel over the entire image region. ,in This represents the pixel value of the c-th channel at position (i,j). This operation compresses the spatial information of each channel into a scalar descriptor. This ultimately yields a vector of length C. This is called the global channel descriptor. This process achieves information aggregation from the spatial domain to the channel domain, enabling the model to perceive the overall activity level of each channel across the entire image.
[0042] Next, the excitation operation begins. The global channel descriptor z is input into a lightweight fully connected network. The network consists of two fully connected layers, and its structural design follows a pattern of dimensionality reduction → activation → dimensionality increase. Specifically, it first uses a dimensionality-reducing fully connected layer. (r=16 is the reduction ratio) The C-dimensional vector is compressed to C / r dimensions, then nonlinearity is introduced by the ReLU activation function δ, followed by an up-dimensional fully connected layer. It is restored to C dimensions, and finally normalized to the [0,1] interval by the Sigmoid activation function σ to generate the channel weight vector. Each element in the weight vector s The importance score corresponding to the c-th channel in the original feature map reflects the discriminative value of that channel in the current task.
[0043] Finally, a scaling operation is performed, multiplying the generated channel weight vector s with the original fourth feature map U element-wise along the channel dimension, thus outputting the fifth feature map. This operation amplifies the responses of high-weight channels and suppresses the responses of low-weight channels, thus achieving global channel recalibration of the feature map. The design logic of the entire SENet module lies in its independent use of complex convolutional operations. Instead, it dynamically adjusts the contribution of each channel through a channel attention mechanism driven by global context information, enabling the model to focus more on the feature channels that are truly crucial for defect identification. Compared to traditional methods that treat all channels equally, SENet significantly improves the model's feature selection ability, exhibiting stronger robustness, especially when facing complex backgrounds or minor defects. Furthermore, since SENet contains only a small number of learnable parameters, its computational cost is extremely low, fully meeting the real-time requirements of industrial scenarios. In summary, this step, by embedding the SENet module at the end of the decoder, achieves refined channel optimization of the fourth feature map, ensuring higher accuracy and reliability of the defect segmentation probability map output by the subsequent classification head, demonstrating the innovation and practicality of this invention in improving segmentation accuracy.
[0044] S6. Pass the fifth feature map through a classification head to output a defect segmentation probability map with the same size as the input image.
[0045] In one implementation, the fifth feature map, processed by the compression and excitation network module, is input into a lightweight classification head to generate the final defect segmentation result. This lightweight classification head typically consists of a 1×1 convolutional layer, which maps the number of channels of the fifth feature map to an output dimension suitable for pixel-level binary classification tasks without changing the spatial resolution of the feature map. In the industrial surface defect detection scenario targeted by this scheme, the number of output channels is 1, representing the confidence level of each pixel belonging to the defect category. Since the fifth feature map has been restored to the exact same size as the original input image through the stepwise upsampling operation of the decoder before entering this step, the classification head can directly perform pixel-by-pixel prediction without additional spatial transformation. Subsequently, the output of the 1×1 convolution undergoes a nonlinear transformation via the Sigmoid activation function, compressing the real value of each pixel to the [0,1] interval, forming a grayscale probability map with the same size as the input image, i.e., the defect segmentation probability map. The pixel value at any position (i,j) in the figure... This indicates the probability that the location belongs to a surface defect area: the closer the value is to 1, the more certain the model is that a defect exists at this location; the closer the value is to 0, the more likely it is to be considered normal background. This defect segmentation probability map can be directly used for visualization, either as a heatmap or overlaid on the original image as a red overlay, or it can be converted into a binary mask by setting a threshold for subsequent automatic quality inspection systems to perform defect counting, area measurement, or alarm decisions.
[0046] The method employs a binary cross-entropy loss function during the training phase: in For real labels, Here, N represents the probability predicted by the model, and N is the total number of pixels.
[0047] In one implementation, the method employs a binary cross-entropy loss function (BCE) as the optimization objective during the training phase to guide the updating of model parameters and improve the accuracy of defect segmentation. The loss function directly affects the difference between the model's output defect segmentation probability map and the corresponding ground truth mask, measuring the difference between the predicted and true values pixel by pixel. Specifically, for each input industrial product surface image, after processing through steps S1 to S6, a predicted probability map with the same dimensions as the original image is generated, where the predicted value at each pixel position i is... This indicates the probability that the location belongs to a defect region; simultaneously, the training dataset provides a binary label map, either manually annotated or generated by a high-precision sensor, as a supervision signal, where the true label for each pixel is... , This indicates that the location is a defect. This represents a normal background. Assuming the entire image contains N pixels, the binary cross-entropy loss function is defined as:
[0048] In actual training, the loss function calculates its gradient through backpropagation and, in conjunction with the optimizer Adam, performs end-to-end joint optimization of all learnable parameters in the U-Net backbone network, the Combined Channel-Spatial Attention Module (CBAM), and the Squeeze and Excitement Network Module (SENet). Since industrial defects typically constitute a very small proportion of an image, a weighted strategy could be introduced on top of the standard BCE to improve the model's sensitivity to sparse defects. However, this approach prioritizes the original BCE form due to its simple structure, stable convergence, and the fact that the attention mechanisms of CBAM and SENet effectively mitigate the performance degradation caused by class imbalance. The entire training process iterates on datasets containing hundreds to thousands of labeled images until the segmentation metrics on the validation set stabilize. Guided by this loss function, the model gradually learns to accurately locate minute defect regions in complex industrial contexts, ultimately achieving highly robust and generalizable surface defect segmentation.
[0049] In one implementation, the Adam optimizer is used during the model's training phase to adaptively adjust the network parameters, thereby efficiently and stably optimizing the aforementioned binary cross-entropy loss function. Specifically, the initial learning rate is set to... This value has been proven in practice to ensure convergence speed while avoiding severe oscillations in the early stages of training. During training, each batch contains 8 images of the surface of industrial products and their corresponding pixel-level defect labels, i.e., the batch size is set to 8. This configuration balances memory usage and gradient estimation stability and is suitable for most mainstream GPU devices. The training data is preprocessed using lightweight data augmentation strategies such as random cropping and horizontal flipping to improve the model's generalization ability.
[0050] Throughout the training process, the system continuously monitors model performance on independent validation sets. The core evaluation metric used is the mean intersection-over-union ratio (mIoU), which effectively reflects the spatial overlap between predicted and actual defect regions, making it particularly suitable for industrial quality inspection scenarios where the foreground area is minimal. To prevent overfitting and improve training efficiency, an early stopping mechanism is introduced: if the mIoU metric on the validation set does not improve within 20 consecutive training epochs, training is automatically terminated, and the model parameters are rolled back to the optimal performance level during validation. This strategy not only significantly saves computational resources but also ensures that the final saved model possesses the best generalization and segmentation capabilities. The entire training process is implemented using mainstream deep learning frameworks such as PyTorch or TensorFlow, and all hyperparameters are determined based on ablation experiments, ensuring that the solution is efficient, robust, and reproducible in actual industrial deployments.
[0051] This invention also provides a highly efficient and accurate industrial product surface defect segmentation system. This system is constructed in a modular manner, and its overall process strictly corresponds to the aforementioned method. The system first acquires a surface image of the industrial product to be inspected through an image input module and sends it to an encoder module. The encoder module uses the encoder portion of the U-Net architecture to perform multi-scale feature extraction on the input image. After completing the initial N convolutions and downsampling operations, it outputs a first feature map. Subsequently, this first feature map is sent to a combined channel-spatial attention module. This module sequentially performs channel attention weighting and spatial attention weighting. First, it generates channel weights through global pooling and a lightweight MLP to enhance discriminative feature channels. Then, it generates a spatial weight mask through 7×7 convolution to focus on the defect region, finally outputting a second feature map optimized by double weighting. Next, the encoder's subsequent processing module receives the second feature map and continues to perform feature compression at the remaining levels, and at each layer, it uses skip connections to... The feature maps at the corresponding scales are passed to the decoder. The decoder module then sequentially upsamples and performs channel-by-channel feature fusion on the received multi-scale feature maps to gradually restore spatial resolution, ultimately outputting the fourth feature map. After the decoder completes its final upsampling and before outputting the result, the squeezing and excitation network module intervenes, performing global average pooling on the fourth feature map to generate channel descriptors. Channel weights are then calculated using a dimensionality reduction-upgrading fully connected structure, and the original feature map is scaled channel-by-channel, outputting a fifth feature map that has undergone global channel recalibration. Finally, the segmentation output module maps the fifth feature map to a single-channel probability map using a 1×1 convolutional classification head, and outputs a defect segmentation probability map with the same size as the original input image after passing through a Sigmoid activation function, for direct use by the quality inspection system. While maintaining the simplicity of the U-Net structure, the entire system achieves synergistic optimization of accuracy and efficiency by embedding CBAM in the middle of the encoder and SENet at the end of the decoder, making it suitable for online high-precision defect detection in various industrial scenarios such as metal, glass, chips, and tablets.
[0052] In one implementation, to verify the performance advantages of the proposed efficient and accurate industrial product surface defect segmentation method, a systematic comparative experiment was conducted. The experiment selected three representative benchmark models in the current semantic segmentation field as comparison objects: DeepLabV3+, PSPNet, and U-Net. U-Net serves as the basic architecture of this scheme, while the other two represent advanced network designs based on dilated convolution and pyramid pooling structures, respectively. All models were trained and tested on four publicly available industrial defect detection datasets, including MVTec-AD, MSD, Frequency Division Duplex (FDD), and ECDD, to comprehensively evaluate their generalization ability under different materials, defect types, and background complexities.
[0053] In terms of performance evaluation, the average intersection-union ratio (Avg-IoU) and average accuracy (Avg-M) are used as core indicators to measure the model's accuracy in delineating the boundaries of defect areas and the overall classification accuracy; at the same time, the inference frame rate (FPS) is recorded to reflect the real-time performance of the algorithm in actual deployment.
[0054] Table 1: Performance comparison of the proposed method with existing methods on the multi-texture defect dataset
[0055] As shown in Table 1, on the MVTec-AD dataset, the method of this invention achieves Avg-IoU and Avg-M metrics of 0.883 and 0.950, respectively, which are 1.6% and 0.7% higher than U-Net, and outperform DeepLabV3+ and PSPNet. Moreover, the inference speed reaches 10.5 FPS, which is significantly higher than other models. On the MSD dataset, the Avg-IoU reaches 96.3%, which is close to the theoretical optimal value, demonstrating strong robustness and feature extraction capabilities. It also maintains a leading position on the FDD and ECDD datasets, proving that the method has good cross-scene adaptability.
[0056] Furthermore, the superiority of the invention was further verified through visual analysis. For example... Figure 5 The figure shows a comparison of segmentation results for typical samples: the first row is the original image, the second row is the ground truth label, the third to fifth rows are the prediction results of DeepLabV3+, PSPNet, and U-Net, respectively, and the sixth row is the output of the method of this invention. As can be seen from the figure, traditional models often exhibit blurred boundaries, missed detections, or false detections, especially performing poorly on complex defects such as fine scratches and low-contrast stains; while the method of this invention can more accurately restore the defect contours, effectively suppress background interference, and achieve segmentation results closer to the ground truth label. For example, in the detection of microcracks on metal surfaces, this method successfully captures subtle fracture edges, avoiding misjudgments caused by texture confusion; in the identification of electronic component pin offsets, it also demonstrates stronger spatial consistency and local sensitivity.
[0057] In summary, this invention achieves early enhancement and global calibration of defect features by embedding a combined channel-space attention module (CBAM) in the middle of the U-Net encoder and introducing a squeeze and excitation network module (SENet) at the end of the decoder. It outperforms existing mainstream methods on multiple standard datasets, and has the advantages of high accuracy, high efficiency and strong generalization ability, making it suitable for practical applications in the field of industrial quality inspection.
[0058] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A highly efficient and accurate method for segmenting surface defects in industrial products, characterized in that, Includes the following steps: S1. Acquire a surface image of the industrial product to be inspected, and input the surface image into the encoder of the U-Net network for multi-scale feature extraction to obtain a first feature map; S2. After the encoder completes the initial N feature extractions, the first feature map is input into the combined channel-spatial attention module for processing to obtain the second feature map; S3. The second feature map is continued to be input into the subsequent layers of the encoder, and the feature maps of each layer of the encoder are passed to the decoder of the U-Net network through skip connections to obtain the third feature map; S4. The decoder upsamples and fuses the received third feature map to gradually restore the spatial resolution and obtain the fourth feature map; S5. After the decoder completes the last upsampling operation and before outputting the final segmentation result, the fourth feature map is input to the squeezing and excitation network module for processing to obtain the fifth feature map; S6. Pass the fifth feature map through a classification head to output a defect segmentation probability map with the same size as the input image.
2. The method according to claim 1, characterized in that, The U-Net network adopts an encoder-decoder symmetric structure, where the encoder consists of consecutive convolutional blocks and downsampling operations, and the decoder consists of upsampling operations and convolutional blocks. The output feature map of the i-th layer of the encoder is concatenated with the input feature map of the i-th layer of the decoder through skip connections.
3. The method according to claim 1, characterized in that, In the combined channel-spatial attention module, the input first feature map is first processed by the channel attention submodule to obtain an intermediate feature map; the intermediate feature map is then input into the spatial attention submodule for processing, and finally the second feature map is output.
4. The method according to claim 3, characterized in that, The combined channel-spatial attention module processes the input feature map The processing includes the following steps: S21. Channel attention weighting, calculate the channel weight vector. : Where F is the input feature tensor of the convolutional block, It is an average pooling operation. It is a max pooling operation. MLP is a lightweight multilayer perceptron consisting of two fully connected layers. Use the Sigmoid activation function; Obtain the channel-weighted feature map ,in Represents element-wise multiplication along the channel dimension; S22. Spatial attention weighting, calculating the spatial weight mask. : in It is an average pooling operation. It is a max pooling operation. Indicates channel splicing. This represents a convolution operation with a kernel size of 7×7; The output of the second feature map is .
5. The method according to claim 1, characterized in that, In the squeeze and excitation network module, the input fourth feature map is first squeezed to generate a global channel descriptor, then input to the excitation operation to generate a channel weight vector, and finally the fourth feature map is weighted by a scaling operation.
6. The method according to claim 5, characterized in that, The squeezing and excitation network module processes the input feature map. The processing includes the following steps: S51. Extrusion Operation: ; in, Let H' be the global descriptor for the c-th channel, where C is the number of channels in the feature map, H' is the height of the feature map, and W' is the width of the feature map. It is a compression function that aggregates spatial dimensional information into channel-level descriptions; The value of the c-th channel at position (i,j) is given for the input feature map U. It is a two-dimensional matrix with the c-th channel; Get the global channel descriptor ; S52. Stimulation Operation: ; in, This is the output channel weight vector. Here, g(z, W) is the activation function, and g(z, W) is the fully connected layer transformation during the activation process. To reduce the weights of the fully connected layer, The weights of the upgraded fully connected layer are δ, which is the ReLU function, σ, which is the Sigmoid function, and the reduction ratio is r=16. S53. Scaling Operation: Output the fifth feature map as follows ,in This represents element-wise multiplication of the channel dimension.
7. The method according to claim 1, characterized in that, The method employs a binary cross-entropy loss function during the training phase: in For real labels, Here, N represents the probability predicted by the model, and N is the total number of pixels.
8. The method according to claim 7, characterized in that, The training phase employs the Adam optimizer, with an initial learning rate set to... The batch size is 8, and the average intersection-union ratio is monitored on the validation set. If the ratio does not improve for 20 consecutive rounds, the training is terminated early.
9. The method according to claim 1, characterized in that, The combined channel-spatial attention module is positioned after the fourth convolutional block of the encoder, and the squeezing and excitation network module is positioned after the last layer upsampling operation of the decoder.
10. A highly efficient and precise industrial product surface defect segmentation system, characterized in that, include: Image input module, used to acquire surface images of industrial products to be inspected; The encoder module is configured to perform multi-scale feature extraction on the surface image and output a first feature map after completing the initial N feature extractions. A combined channel-spatial attention module is used to perform channel attention weighting and spatial attention weighting on the first feature map and output a second feature map. The encoder post-processing module is used to continue feature extraction from the second feature map and output the feature maps of each layer of the encoder through skip connections. The decoder module is used to upsample and fuse the received feature map to gradually restore the spatial resolution and output the fourth feature map. The squeezing and excitation network module, connected to the end of the decoder module and located after the final upsampling operation, is used to perform global channel recalibration on the fourth feature map and output the fifth feature map; The segmentation output module is used to generate a defect segmentation probability map with the same size as the input image from the fifth feature map through a classification head.
Citation Information
Patent Citations
A tablet surface defect segmentation method combining feature fusion and attention mechanism
CN117237370B
Strip steel surface defect detection method based on attention mechanism and improved UNet network
CN119722666A