Industrial product surface defect detection method based on feature coupling
Through the feature coupling detection method, combined with the self-attention mechanism and depth-wise separable convolution, efficient and accurate detection of surface defects of industrial products is achieved, which solves the detection difficulties of traditional methods in complex backgrounds and variable defect forms, and improves detection accuracy and robustness.
Patent Information
- Application Number
- CN202511247708.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-03
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2045-09-03
AI Technical Summary
Traditional surface defect detection methods for industrial products have difficulty maintaining high efficiency and high precision when dealing with complex backgrounds and variable defect morphologies. In particular, when the defect scales are unevenly distributed and the difference from the background is slight, existing methods are difficult to detect effectively.
A detection method based on feature coupling is adopted, combining the self-attention mechanism with a dual-branch module design of depthwise separable convolution. Multi-scale feature extraction is performed through dilated pyramid shared convolution, and global information understanding and local detail capture are achieved through structured pruning optimization.
It improves the accuracy and robustness of surface defect detection for industrial products, can effectively deal with complex backgrounds and multi-scale defects, and reduces computational complexity and labeling costs.
Smart Images

Figure CN120766047A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of defect detection technology, and in particular to a method for detecting surface defects of industrial products requiring both speed and precision. Background Art
[0002] In today's era of the Industrial Internet, with the rapid development of artificial intelligence and deep learning technologies, some manufacturing industries are undergoing profound transformations. Industrial intelligence, as a key driver, is leading the manufacturing industry to new heights. Within this process, surface defect detection technology for industrial products has garnered significant attention due to its importance for product quality control. Traditional defect detection methods primarily rely on manual visual inspection and rule-based automated systems. While manual inspection can adapt to diverse product types and complex defect morphologies, it is inefficient and susceptible to subjective factors, making it difficult to ensure consistent and accurate detection. Furthermore, long hours can lead to operator fatigue, further increasing the risk of missed or false detections. To improve detection efficiency and consistency, rule-based automated inspection systems have emerged. These systems typically utilize image processing techniques, such as edge detection, threshold segmentation, and texture analysis, to identify specific defect types. However, because these methods rely heavily on predefined features and parameter settings, they often struggle with complex background environments and variations in defect morphology, resulting in limited detection accuracy. For example, traditional methods cannot provide satisfactory results when dealing with irregularly shaped or low-contrast defects. Therefore, a new defect detection method is urgently needed to overcome these limitations and meet the rapidly changing design and production requirements of industrial product surface defects. Therefore, a defect detection method based on feature coupling in the present invention improves the efficiency of multi-scale context information extraction by improving the global-local feature fusion capability, thereby improving the accuracy of industrial product surface defect detection. Summary of the Invention
[0003] The purpose of the present invention is to overcome the shortcomings and deficiencies of the prior art and provide a defect detection method based on feature coupling, which breaks through the traditional industrial product surface defect detection method, such as the insufficient capture of fine-grained information by the C3k2 module, the easy blurring of local features by the SPPF module, and the high computational complexity of the deep learning model. By integrating the self-attention mechanism and the dual-branch module design of the depthwise separable convolution, the multi-scale feature extraction of the expanded pyramid shared convolution, and the lightweight optimization of the structured pruning, it can simultaneously maintain the global information understanding and the capture of local details, thereby achieving the improvement of detection accuracy while being lightweight.
[0004] To achieve the above object, the present invention is implemented through the following technical solution: a defect detection method based on feature coupling, comprising the following steps:
[0005] 1) Design a backbone network consisting of four stages, in which Stage1 and Stage2 use CBS modules and C3k2_SCGF modules for shallow feature extraction. The deep convolution is specifically responsible for capturing the feature patterns of the spatial dimension, and the point-by-point convolution is responsible for integrating the feature information between different channels, and realizing the deep coupling of spatial-channel features through series connection. Stage3 and Stage4 use CBS modules and C3k2_NAGF modules for deep feature extraction. The C3k2_NAGF module fuses the global modeling features based on the self-attention mechanism with the local features of the traditional convolution operation, and realizes the complementary coupling of different feature extraction methods through feature weighting and residual connection. Finally, the DPSC module and C2PSA module are integrated, and the dilated convolution extracts features at different receptive field scales respectively. These multi-scale features are then spliced and coupled in the channel dimension to achieve progressive feature learning from local details to global semantics;
[0006] 2) Based on the multi-scale features extracted in step 1), a feature fusion network is constructed. The Neck structure is designed to adopt an FPN structure. The concatenation operation, upsampling, and C3k2_SCGF module are used to effectively fuse features of different scales. High-level semantic information is concatenated with low-level detail information through upsampling, and the C3k2_SCGF module further optimizes feature expression.
[0007] 3) Based on the fused features from step 2), a multi-scale detection head is constructed: three detection branches of different scales are designed. Each branch contains a Conv2d convolutional layer, a BatchNorm2d normalization layer, and a Detect detection head. These branches are responsible for detecting defects of different sizes, achieving comprehensive coverage of small, medium, and large-scale defects.
[0008] 4) Based on the network architecture completed in step 3), perform end-to-end training and LAMP pruning optimization: The network is trained using a dataset of industrial product surface defects. Then, the LAMP pruning strategy is applied to calculate weight importance scores and remove connection parameters with small contributions. This significantly reduces the number of model parameters and computational complexity while maintaining detection performance.
[0009] In step 1), there are four stages:
[0010] a. In Stage 1 and Stage 2, the input image first undergoes initial feature extraction through the CBS (Conv+BatchNorm+SiLU) module. This module combines convolution operations, batch normalization, and SiLU activation functions to effectively extract the basic texture information of the image. The feature map is then input into the C3k2_SCGF (Separable Convolution Gated Former) module, which uses a depthwise separable convolution structure to focus on capturing the spatial features of each channel through depthwise convolution Dconv, and then performs cross-channel feature fusion through point-by-point convolution Pconv. The calculation formula is as follows:
[0011] ,
[0012] Among them, PwConv is a point-by-point convolution, which enables each spatial position of the feature map to combine features from all channels, thereby effectively enhancing information expression. Act is an activation function, which enables the network to express more complex patterns and prevents the model from simply performing linear combinations. DwConv is a depthwise convolution, which can independently convolve each channel, helping to capture the spatial features of each channel, which is especially beneficial when processing complex images. Combined with the two, the depthwise convolution is responsible for capturing the spatial features of each channel, while the point-by-point convolution is responsible for integrating these spatial features across channels, thereby providing a richer and more comprehensive feature representation, and avoiding the calculation of unnecessary cross-channel features, thereby reducing computational costs. The C3k2_SCGF module achieves deep coupling of spatial-channel features through a series connection.
[0013] b. When entering the deep feature extraction stage of Stage 3 and Stage 4, a combination of the CBS module and the C3k2_NAGF (Neighborhood Aware Gated Former) module is used. The C3k2_NAGF module introduces a self-attention mechanism and implements global context modeling by calculating the query, key, and value matrices. Its calculation formula is as follows:
[0014] ,
[0015] Here, Q, K, and V are the query, key, and value extracted from the input feature map, respectively. d is the dimension of the input key vector. Softmax is used to normalize the attention scores. The C3k2_NAGF module uses a self-attention mechanism to capture dependencies between distant pixels in the feature map, providing richer context for defect detection. Simultaneously, the C3k2_SCGF module uses depthwise separable convolutions to capture local detail features. The two are deeply coupled through parallel processing and residual connections, ensuring that local detail information is preserved while obtaining global semantic information.
[0016] c. In the final stage of the backbone network, the DPSC (Dilated Pyramid Shared Conv) module is integrated to replace the traditional SPPF module. The DPSC module processes feature maps in parallel by applying dilated convolutions with different dilation rates (d=1, 3, 5). Its calculation formula is as follows:
[0017] ,
[0018] Where d is the dilation rate, which is 1, 3, 5..., and then all the dilated convolution results are spliced along the channel dimension. The calculation formula is as follows:
[0019] ,
[0020] where Y1, Y3, and Y5 are the dilation rates for values of 1, 3, and 5, respectively. Finally, the concatenated feature map is mapped to the final number of output channels via a 1x1 convolution to produce the output. The DPSC module fuses these feature maps with different receptive fields in series along the channel axis, constructing a multi-level feature representation encompassing everything from fine-grained local textures to coarse-grained global patterns. This allows for comprehensive capture and unified modeling of defect information at different scales.
[0021] d. Finally, the C2PSA module is used. This module combines cross-stage partial connections and self-attention mechanisms to achieve position-sensitive feature enhancement through PSABlock. Shortcut connections are used within the module to ensure gradient flow, and Conv2d convolution operations are used to adjust feature dimensions. Finally, a Concat operation is used to fuse feature representations from different paths.
[0022] In step 2), the specific implementation process of constructing a feature fusion network based on the multi-scale features extracted in step 1) is as follows:
[0023] a. The Feature Pyramid Network (FPN) architecture serves as the core structure of the Neck component, implementing a top-down feature fusion path. First, the P5 high-level features output by the backbone network are used as a starting point. These features contain rich semantic information but have low spatial resolution. Upsampling is used to double the spatial size of the P5 features to align them with the spatial dimensions of the P4 feature map. Bilinear interpolation is used for upsampling to ensure a smooth transition of feature information.
[0024] b. The upsampled P5 features are concatenated with the features extracted in the P4 stage using a concat operation, channel-wise. This concatenation effectively combines high-level semantic information with mid-level feature representations. The fused features are then fed into the C3k2_SCGF module for further feature optimization and information integration. This module refines the fused features using depthwise separable convolution and gating mechanisms, enhancing their expressiveness and discriminability.
[0025] c. Continuing along the top-down fusion path, the optimized P4 features are scaled up to a spatial size matching the P3 features through the same Upsample operation. A Concat operation is then performed to combine the fused P4 features with the original P3 features. This process ensures that semantic information from deep layers is effectively transferred to shallow layers while preserving the detailed representation of shallow features. The fused P3 features are also processed by the C3k2_SCGF module, which further optimizes feature quality through local feature enhancement and cross-channel information exchange.
[0026] d. The processed P3 features are further upsampled to align their spatial dimensions with the P2 features, and final feature fusion is performed. This fusion combines feature information from all levels, from P5 to P2, to form a comprehensive feature representation that includes multi-scale semantics and detail information. The fused P2 features undergo final optimization processing in the C3k2_SCGF module, generating multi-scale fused features with strong expressive power.
[0027] In step 3), the specific implementation process of constructing a multi-scale detection head based on the features fused in step 2) is as follows:
[0028] a. Design three parallel detection branches, corresponding to small-scale, medium-scale, and large-scale defect detection tasks, respectively. Each branch is optimized for targets within a specific size range. The small-scale detection branch receives the fused features from the P2 layer as input. This feature map has the highest spatial resolution, which is 1 / 4 of the input image. It can retain rich detail information and is particularly suitable for detecting tiny defects such as pinholes and fine scratches. The medium-scale detection branch processes the fused features of the P3 layer, which has a spatial resolution of 1 / 8 of the input image. While maintaining certain detail information, it has a larger receptive field and is mainly responsible for detecting medium-sized defects such as spots and small-scale corrosion. The large-scale detection branch receives the fused features of the P4 layer, which has a spatial resolution of 1 / 16 of the input image. It has the largest receptive field and the strongest semantic expression ability and is specifically used to detect large-scale defects such as cracks and large-area stains.
[0029] b. Each detection branch uses the same internal structure. It first performs further feature transformation and dimensionality adjustment on the input fused features through a Conv2d convolutional layer. This convolutional layer uses a 3×3 convolution kernel with a stride of 1 and padding of 1, ensuring that the feature map size remains unchanged while enhancing the expressiveness of the features. The number of output channels of the convolutional layer is set according to the specific detection task requirements to provide sufficient feature representation dimensions.
[0030] c. The features of each branch are processed by the BatchNorm2d batch normalization layer. The batch normalization layer performs normalization on each channel of the feature map independently. The calculation formula is:
[0031] ,
[0032] where μ and σ² are the mean and variance of the features within the batch, respectively, and γ and β are learnable scaling and bias parameters, is a small constant to prevent division by zero. This normalization operation can accelerate network convergence, improve training stability, and to a certain extent play a role in regularization to prevent overfitting.
[0033] d. Each branch completes the final object detection task using a specially designed Detect head. The Detect head utilizes a decoupled design approach, handling classification and regression tasks separately. The classification branch predicts whether each candidate region contains a defect and the specific defect category. The output dimension is (num_classes + 1) × anchor_num, where num_classes is the number of defect categories and "+1" represents the background category. The regression branch predicts the precise location and size of the defect bounding box. The output dimension is 4 × anchor_num, corresponding to the bounding box's center coordinate offset (Δx, Δy) and width and height scaling factors (Δw, Δh), respectively.
[0034] Each Detect head also integrates a confidence prediction mechanism, outputting a confidence score for each prediction result. The final detection results are post-processed using the non-maximum suppression (NMS) algorithm to eliminate duplicate detection frames and retain the detection results with the highest confidence. The outputs of the three scale detection branches are merged to form the final detection result, achieving comprehensive coverage and precise location of defects of different sizes.
[0035] In step 4), the specific implementation process of end-to-end training and LAMP pruning optimization based on the network architecture completed in steps 2) and 3) is as follows:
[0036] a. First, an end-to-end training phase is conducted, using an industrial product surface defect dataset to train the complete detection network. The training process uses a multi-task loss function that combines classification loss, bounding box regression loss, and confidence loss. The total loss function is expressed as:
[0037] ,
[0038] in 、 、 is the weight coefficient. The classification loss uses Focal Loss to reduce the impact of simple samples on training. The specific formula is:
[0039] ,
[0040] Where α is the balance factor, γ is the focus parameter, and p is the prediction probability. The bounding box regression loss uses GIoU Loss to improve positioning accuracy. The specific formula is:
[0041] ,
[0042] Where C is the smallest rectangle containing the predicted box A and the true box B, and IoU is the intersection over union ratio. The cosine annealing learning rate scheduling strategy is used during training, and the learning rate calculation formula is:
[0043] ,
[0044] Ensure the stability of model convergence.
[0045] b. After training is complete, the LAMP (Layer-Adaptive Magnitude-based Pruning) pruning strategy is implemented for model compression optimization. The LAMP pruning algorithm introduces a global pruning importance scoring mechanism that considers not only the absolute magnitude of weights but also the importance differences between weights across layers. First, the weight tensor W of each layer in the network is processed. These weights may come from fully connected layers or convolutional layers. Each layer's weight tensor is typically a two-dimensional matrix. This matrix is flattened and sorted by weight to form a one-dimensional weight vector for subsequent importance evaluation.
[0046] The calculation of the LAMP score is based on the importance of each weight, that is, the size of the weight, and not only considers the size of a single weight, but also evaluates the relative importance of the weight in the global context. The calculation formula of the LAMP score is as follows:
[0047] ,
[0048] Where W[u] represents the u-th weight, and the denominator represents the sum of the squares of all weights from index u to the end of the weight list in that layer. Larger weights correspond to higher LAMP scores, while relatively low LAMP scores will be pruned.
[0049] In order to further quantify the importance of weights, a weight comparison mechanism is introduced. The specific formula is as follows:
[0050] ,
[0051] like , then the corresponding LAMP score satisfies , indicating that connections with larger weights contribute more significantly to model performance and are therefore more likely to be retained during pruning. This quantification method enables the LAMP score to effectively measure the local importance of each weight and its global impact, thereby formulating more precise pruning strategies. By calculating the LAMP score for each connection, we can more accurately determine which connections to retain and which unimportant connections to prune until global sparsity constraints are met.
[0052] Evaluate model performance after pruning by testing the detection accuracy of the pruned model on the validation set to ensure that the pruning process does not significantly damage model performance. Performance evaluation metrics include mAP, inference speed, and model size. If performance drops by more than a preset threshold, revert to the previous pruning state and adjust the pruning strategy.
[0053] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0054] 1. This invention implements modeling of global-local multi-level feature dependency relationships in industrial product surface defect detection. While enhancing the model's ability to discriminate complex backgrounds, it also retains key local detail feature information, effectively solving the problem of detecting defects with uneven defect scale distribution and subtle differences from the background.
[0055] 2. This invention combines the advantages of the self-attention mechanism and the gated linear unit, expands the receptive field by dilated convolution without reducing spatial resolution, and uses the LAMP method for pruning, significantly reducing the annotation cost and time;
[0056] 3. The method of the present invention has a wide range of applications in surface defect detection of industrial products, is highly practical, and has broad prospects in many fields such as medical imaging and remote sensing target detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a logical flow diagram of the present invention.
[0058] Figure 2This is a framework diagram of the method of the present invention.
[0059] Figure 3 This is the structural diagram of C3k2_NAGF and C3k2_SCGF of the present invention. DETAILED DESCRIPTION
[0060] The present invention will be described in further detail below with reference to the embodiments and drawings, but the embodiments of the present invention are not limited thereto.
[0061] This embodiment discloses a defect detection method based on feature coupling, such as Figure 1 As shown; the method is implemented logically as Figure 2 As shown in the figure, this method feeds the image into a cross-scale feature fusion network for multi-level feature extraction and global-local information modeling. The C3k2_NAGF and C3k2_SCGF modules emphasize global context dependencies and local detail features, thereby fully utilizing the self-attention mechanism of MetaFormer and the gated information screening capability of CGLU. Considering that the surface defects of industrial products are highly similar to the background and that the traditional SPPF module suffers from detail information loss, DPSC (dilated pyramid shared convolution) multi-scale feature extraction is performed to retain high-resolution fine-grained spatial features. The PSABlock position-sensitive attention mechanism and C2PSA module are used to enhance feature discrimination and defect location accuracy, further improving the accuracy of the final detection. Specifically, the following steps are included:
[0062] 1) In Figure 2 Given an image, send the image to the backbone;
[0063] a. In Stage 1 and Stage 2, the input image first undergoes initial feature extraction through the CBS (Conv+BatchNorm+SiLU) module. This module combines convolution operations, batch normalization, and SiLU activation functions to effectively extract the basic texture information of the image. The feature map is then input into the C3k2_SCGF (Separable Convolution Gated Former) module, which uses a depthwise separable convolution structure to focus on capturing the spatial features of each channel through depthwise convolution Dconv, and then performs cross-channel feature fusion through point-by-point convolution Pconv. The calculation formula is as follows:
[0064] ,
[0065] Among them, PwConv is a point-by-point convolution, which enables each spatial position of the feature map to combine features from all channels, thereby effectively enhancing information expression. Act is an activation function, which enables the network to express more complex patterns and prevents the model from simply performing linear combinations. DwConv is a depthwise convolution, which can independently convolve each channel, helping to capture the spatial features of each channel, which is especially beneficial when processing complex images. Combined with the two, the depthwise convolution is responsible for capturing the spatial features of each channel, while the point-by-point convolution is responsible for integrating these spatial features across channels, thereby providing a richer and more comprehensive feature representation, and avoiding the calculation of unnecessary cross-channel features, thereby reducing computational costs. The C3k2_SCGF module achieves deep coupling of spatial-channel features through a series connection.
[0066] b. When entering the deep feature extraction stage of Stage 3 and Stage 4, a combination of the CBS module and the C3k2_NAGF (Neighborhood Aware Gated Former) module is used. The C3k2_NAGF module introduces a self-attention mechanism and implements global context modeling by calculating the query, key, and value matrices. Its calculation formula is as follows:
[0067] ,
[0068] Here, Q, K, and V are the query, key, and value extracted from the input feature map, respectively. d is the dimension of the input key vector. Softmax is used to normalize the attention scores. The C3k2_NAGF module uses a self-attention mechanism to capture dependencies between distant pixels in the feature map, providing richer context for defect detection. Simultaneously, the C3k2_SCGF module uses depthwise separable convolutions to capture local detail features. The two are deeply coupled through parallel processing and residual connections, ensuring that local detail information is preserved while obtaining global semantic information.
[0069] c. In the final stage of the backbone network, the DPSC (Dilated Pyramid Shared Conv) module is integrated to replace the traditional SPPF module. The DPSC module processes feature maps in parallel by applying dilated convolutions with different dilation rates (d=1, 3, 5). Its calculation formula is as follows:
[0070] ,
[0071] Where d is the dilation rate, which is 1, 3, 5..., and then all the dilated convolution results are spliced along the channel dimension. The calculation formula is as follows:
[0072] ,
[0073] where Y1, Y3, and Y5 are the dilation rates for values of 1, 3, and 5, respectively. Finally, the concatenated feature map is mapped to the final number of output channels via a 1x1 convolution to produce the output. The DPSC module fuses these feature maps with different receptive fields in series along the channel axis, constructing a multi-level feature representation encompassing everything from fine-grained local textures to coarse-grained global patterns. This allows for comprehensive capture and unified modeling of defect information at different scales.
[0074] d. Finally, the C2PSA module is used. This module combines cross-stage partial connections and self-attention mechanisms to achieve position-sensitive feature enhancement through PSABlock. Shortcut connections are used within the module to ensure gradient flow, and Conv2d convolution operations are used to adjust feature dimensions. Finally, a Concat operation is used to fuse feature representations from different paths.
[0075] 2) The specific implementation process of constructing a feature fusion network using the extracted multi-scale features is as follows:
[0076] a. The Feature Pyramid Network (FPN) architecture serves as the core structure of the Neck component, implementing a top-down feature fusion path. First, the P5 high-level features output by the backbone network are used as a starting point. These features contain rich semantic information but have low spatial resolution. Upsampling is used to double the spatial size of the P5 features to align them with the spatial dimensions of the P4 feature map. Bilinear interpolation is used for upsampling to ensure a smooth transition of feature information.
[0077] b. The upsampled P5 features are concatenated with the features extracted in the P4 stage using a concat operation, channel-wise. This concatenation effectively combines high-level semantic information with mid-level feature representations. The fused features are then fed into the C3k2_SCGF module for further feature optimization and information integration. This module refines the fused features using depthwise separable convolution and gating mechanisms, enhancing their expressiveness and discriminability.
[0078] c. Continuing along the top-down fusion path, the optimized P4 features are scaled up to a spatial size matching the P3 features through the same Upsample operation. A Concat operation is then performed to combine the fused P4 features with the original P3 features. This process ensures that semantic information from deep layers is effectively transferred to shallow layers while preserving the detailed representation of shallow features. The fused P3 features are also processed by the C3k2_SCGF module, which further optimizes feature quality through local feature enhancement and cross-channel information exchange.
[0079] d. The processed P3 features are further upsampled to match the spatial dimensions of the P2 features and undergo a final feature fusion. This stage combines feature information from all levels from P5 to P2, resulting in a comprehensive feature representation that includes multi-scale semantic and detail information. The fused P2 features are further optimized by the C3k2_SCGF module to generate multi-scale fusion features with strong expressive power.
[0080] 3) The implementation process of the multi-scale detection head based on the fused features is as follows:
[0081] a. Three parallel detection branches are designed to correspond to small, medium, and large scale defect detection tasks, respectively. Each branch is optimized for a specific size range of targets. The small-scale detection branch receives the fused features from the P2 layer as input, which has the highest spatial resolution of 1 / 4 of the input image, retaining rich detail information, especially suitable for detecting small defects such as pinholes, fine scratches, etc. The medium-scale detection branch processes the fused features from the P3 layer, with a spatial resolution of 1 / 8 of the input image, maintaining certain detail information while having a larger receptive field, mainly responsible for detecting medium-sized defects such as spots, small-scale corrosion, etc. The large-scale detection branch receives the fused features from the P4 layer, with a spatial resolution of 1 / 16 of the input image, having the largest receptive field and strongest semantic expression ability, specifically used for detecting large-sized defects such as cracks, large-area stains, etc.
[0082] b. Each detection branch uses the same internal structure design. First, the Conv2d convolution layer is used to further transform and adjust the dimensions of the input fused features. The convolution layer uses a 3x3 convolution kernel with a stride of 1 and a padding of 1, ensuring that the feature map size remains unchanged while enhancing the feature expression ability. The number of output channels of the convolution layer is set according to the specific detection task requirements to provide sufficient feature expression dimensions.
[0083] c. The features of each branch are processed by the BatchNorm2d batch normalization layer. The batch normalization layer independently normalizes each channel of the feature map, with the formula:
[0084] ,
[0085] where μ and σ² are the mean and variance of the features within the batch, γ and β are the learnable scaling and offset parameters, is a small constant to prevent division by zero. This normalization operation can accelerate network convergence, improve training stability, and to some extent, act as a regularization function to prevent overfitting.
[0086] d. Each branch completes the final object detection task using a specially designed Detect head. The Detect head utilizes a decoupled design approach, handling classification and regression tasks separately. The classification branch predicts whether each candidate region contains a defect and the specific defect category. The output dimension is (num_classes + 1) × anchor_num, where num_classes is the number of defect categories and "+1" represents the background category. The regression branch predicts the precise location and size of the defect bounding box. The output dimension is 4 × anchor_num, corresponding to the bounding box's center coordinate offset (Δx, Δy) and width and height scaling factors (Δw, Δh), respectively.
[0087] Each Detect head also integrates a confidence prediction mechanism, outputting a confidence score for each prediction result. The final detection results are post-processed using the non-maximum suppression (NMS) algorithm to eliminate duplicate detection frames and retain the detection results with the highest confidence. The outputs of the three scale detection branches are merged to form the final detection result, achieving comprehensive coverage and precise location of defects of different sizes.
[0088] 4) The specific implementation process of end-to-end training and LAMP pruning optimization of the completed network architecture is as follows:
[0089] a. First, an end-to-end training phase is conducted, using an industrial product surface defect dataset to train the complete detection network. The training process uses a multi-task loss function that combines classification loss, bounding box regression loss, and confidence loss. The total loss function is expressed as:
[0090] ,
[0091] in 、 、 is the weight coefficient. The classification loss uses Focal Loss to reduce the impact of simple samples on training. The specific formula is:
[0092] ,
[0093] Where α is the balance factor, γ is the focus parameter, and p is the prediction probability. The bounding box regression loss uses GIoU Loss to improve positioning accuracy. The specific formula is:
[0094] ,
[0095] Where C is the smallest rectangle containing the predicted box A and the true box B, and IoU is the intersection over union ratio. The cosine annealing learning rate scheduling strategy is used during training, and the learning rate calculation formula is:
[0096] ,
[0097] Ensure the stability of model convergence.
[0098] b. After training is complete, the LAMP (Layer-Adaptive Magnitude-based Pruning) pruning strategy is implemented for model compression optimization. The LAMP pruning algorithm introduces a global pruning importance scoring mechanism that considers not only the absolute magnitude of weights but also the importance differences between weights across layers. First, the weight tensor W of each layer in the network is processed. These weights may come from fully connected layers or convolutional layers. Each layer's weight tensor is typically a two-dimensional matrix. This matrix is flattened and sorted by weight to form a one-dimensional weight vector for subsequent importance evaluation.
[0099] The calculation of the LAMP score is based on the importance of each weight, that is, the size of the weight, and not only considers the size of a single weight, but also evaluates the relative importance of the weight in the global context. The calculation formula of the LAMP score is as follows:
[0100] ,
[0101] Where W[u] represents the u-th weight, and the denominator represents the sum of the squares of all weights from index u to the end of the weight list in that layer. Larger weights correspond to higher LAMP scores, while relatively low LAMP scores will be pruned.
[0102] In order to further quantify the importance of weights, a weight comparison mechanism is introduced. The specific formula is as follows:
[0103] ,
[0104] like , then the corresponding LAMP score satisfies , indicating that connections with larger weights contribute more significantly to model performance and are therefore more likely to be retained during pruning. This quantification method enables the LAMP score to effectively measure the local importance of each weight and its global impact, thereby formulating more precise pruning strategies. By calculating the LAMP score for each connection, we can more accurately determine which connections to retain and which unimportant connections to prune until global sparsity constraints are met.
[0105] Evaluate model performance after pruning by testing the detection accuracy of the pruned model on the validation set to ensure that the pruning process does not significantly damage model performance. Performance evaluation metrics include mAP, inference speed, and model size. If performance drops by more than a preset threshold, revert to the previous pruning state and adjust the pruning strategy.
[0106] To sum up, after adopting the above scheme, the present invention realizes global-local collaborative feature modeling through C3k2_NAGF and C3k2_SCGF modules in the existing industrial product surface defect detection when the defect and the background are highly similar and the scale distribution is uneven. Combined with the DPSC multi-scale receptive field expansion, it can effectively break through the traditional convolution local receptive field limitation, capture long-distance pixel dependencies and multi-scale contextual information, retain high-resolution fine-grained spatial features and local detail information, and improve the accuracy, robustness and adaptability of industrial product surface defect detection to complex backgrounds. It has practical promotion value and is worthy of promotion.
[0107] The above-described embodiments are only preferred embodiments of the present invention and are not intended to limit the scope of implementation of the present invention. Therefore, any changes made based on the shape and principle of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for detecting surface defects of industrial products based on feature coupling, characterized in that: It includes four stages of backbone network, feature fusion network construction, multi-scale detection head construction, end-to-end training and LAMP pruning optimization: 1) A four-stage backbone network. Stages 1 and 2 use the CBS module and C3k2_SCGF module for shallow feature extraction, while Stages 3 and 4 use the CBS module and C3k2_NAGF module for deep feature extraction. The C3k2_NAGF module fuses global modeling features based on the self-attention mechanism with local features from traditional convolution operations, achieving complementary coupling of different feature extraction methods through feature weighting and residual connections. Finally, the DPSC module and C2PSA module are integrated, and dilated convolutions are used to extract features at different receptive field scales. These multi-scale features are then spliced and coupled in the channel dimension to achieve progressive feature learning from local details to global semantics. 2) Based on the multi-scale features extracted in step 1), a feature fusion network is constructed. The Neck structure is designed to adopt an FPN structure. The concatenation operation, upsampling, and C3k2_SCGF module are used to effectively fuse features of different scales. High-level semantic information is concatenated with low-level detail information through upsampling, and the C3k2_SCGF module further optimizes feature expression. 3) Based on the fused features from step 2), a multi-scale detection head is constructed: three detection branches of different scales are designed. Each branch contains a Conv2d convolutional layer, a BatchNorm2d normalization layer, and a Detect detection head. These branches are responsible for detecting defects of different sizes, achieving comprehensive coverage of small, medium, and large-scale defects. 4) Based on the network architecture completed in step 3), perform end-to-end training and LAMP pruning optimization: The network is trained using a dataset of industrial product surface defects. Then, the LAMP pruning strategy is applied to calculate weight importance scores and remove connection parameters with smaller contributions. This significantly reduces the number of model parameters and computational complexity while maintaining detection performance.
2. The method for detecting surface defects of industrial products based on feature coupling according to claim 1, characterized in that: The four-stage backbone network includes the following steps: a. In Stage 1 and Stage 2, the input image first undergoes initial feature extraction through the CBS (Conv+BatchNorm+SiLU) module. This module combines convolution operations, batch normalization, and SiLU activation functions to effectively extract the basic texture information of the image. The feature map is then input into the C3k2_SCGF (Separable Convolution Gated Former) module, which uses a depthwise separable convolution structure to focus on capturing the spatial features of each channel through depthwise convolution Dconv, and then performs cross-channel feature fusion through point-by-point convolution Pconv. The calculation formula is as follows: , Among them, PwConv is a point-by-point convolution, which enables each spatial position of the feature map to combine features from all channels, thereby effectively enhancing information expression. Act is an activation function, which enables the network to express more complex patterns and prevents the model from performing only linear combinations. DwConv is a depthwise convolution, which can independently convolve each channel, helping to capture the spatial features of each channel, which is especially beneficial when processing complex images. The combination of the two, deep convolution is responsible for capturing the spatial features of each channel, while point-by-point convolution is responsible for integrating these spatial features across channels, thereby providing richer and more comprehensive feature representations and avoiding the calculation of unnecessary cross-channel features, thereby reducing computational costs. The C3k2_SCGF module achieves deep coupling of spatial-channel features through series connection. b. When entering the deep feature extraction stage of Stage 3 and Stage 4, a combination of the CBS module and the C3k2_NAGF (Neighborhood Aware Gated Former) module is used. The C3k2_NAGF module introduces a self-attention mechanism and implements global context modeling by calculating the query, key, and value matrices. Its calculation formula is as follows: , Where Q, K, and V are the query, key, and value extracted from the input feature map, respectively. d is the dimension of the input key vector. The Softmax operation is used to normalize the attention score. The C3k2_NAGF module captures the dependencies between distant pixels in the feature map through the self-attention mechanism, providing richer contextual information for defect detection. At the same time, the depthwise separable convolution of the C3k2_SCGF module captures local detail features. The two are deeply coupled through parallel processing and residual connections, ensuring that local detail information is retained while obtaining global semantic information. c. In the final stage of the backbone network, the Dilated Pyramid Shared Conv (DPSC) module is integrated to replace the traditional SPPF module. The DPSC module processes feature maps in parallel by applying dilated convolutions with different dilation rates (d=1, 3, 5). Its calculation formula is as follows: , Where d is the dilation rate, which is 1, 3, 5..., and then all the dilated convolution results are spliced along the channel dimension. The calculation formula is as follows: , Where Y1, Y3, and Y5 are the expansion rates when 1, 3, and 5 respectively; finally, the concatenated feature map is mapped to the final output channel number through a 1x1 convolution to obtain the output; d. Finally, the C2PSA module is used, which combines cross-stage partial connections and self-attention mechanisms to achieve position-sensitive feature enhancement through PSABlock. Shortcut connections are used within the module to ensure gradient flow, and the feature dimension is adjusted through Conv2d convolution operations. Finally, the feature representations of different paths are fused through the Concat operation. The DPSC module fuses these feature maps with different receptive field ranges in series along the channel axis to construct a multi-level feature representation ranging from fine-grained local textures to coarse-grained global patterns, thereby achieving comprehensive capture and unified modeling of defect information at different scales.
3. The method for detecting surface defects of industrial products based on feature coupling according to claim 1, characterized in that: Building a feature fusion network includes the following steps: a. The Feature Pyramid Network (FPN) architecture is used as the core structure of the Neck component to implement a top-down feature fusion path. First, the P5 high-level features output by the backbone network are used as the starting point. These features contain rich semantic information but have low spatial resolution. The spatial size of the P5 features is doubled through upsampling to keep them consistent with the spatial dimensions of the P4 feature map. Bilinear interpolation is used for upsampling to ensure a smooth transition of feature information. b. The upsampled P5 features are concatenated with the features extracted in the P4 stage through the Concat operation in the channel dimension. This concatenation method can effectively combine high-level semantic information and mid-level feature representation. The fused features are then input into the C3k2_SCGF module for further feature optimization and information integration. This module refines the fused features through depthwise separable convolution and gating mechanisms to enhance the expressiveness and discriminability of the features. c. Continuing along the top-down fusion path, the optimized P4 features are scaled up to a spatial size that matches the P3 features through the same Upsample operation. A Concat operation is then performed to combine the fused features of the P4 layer with the original features of the P3 layer. This process ensures that deep semantic information can be effectively transferred to shallow layers while maintaining the detail expression capability of shallow features. The fused P3 features are also processed by the C3k2_SCGF module to further optimize feature quality through local feature enhancement and cross-channel information interaction. d. The processed P3 features are further upsampled to keep their spatial size consistent with the P2 features, and the final feature fusion is performed. This stage of fusion combines the feature information of all levels from P5 to P2 to form a comprehensive feature representation containing multi-scale semantics and detail information. The fused P2 features are finally optimized by the C3k2_SCGF module to generate multi-scale fused features with strong expressive power.
4. The method for detecting surface defects of industrial products based on feature coupling according to claim 1, characterized in that: Building a multi-scale detection head includes the following steps: a. Design three parallel detection branches, corresponding to small-scale, medium-scale, and large-scale defect detection tasks, respectively. Each branch is optimized for targets within a specific size range. The small-scale detection branch receives the fused features from the P2 layer as input. This feature map has the highest spatial resolution, which is 1 / 4 of the input image. It can retain rich detail information and is particularly suitable for detecting small defects such as pinholes and fine scratches. The medium-scale detection branch processes the fused features of the P3 layer, which has a spatial resolution of 1 / 8 of the input image. While maintaining certain detail information, it has a larger receptive field and is mainly responsible for detecting medium-sized defects such as spots and small-scale corrosion. The large-scale detection branch receives the fused features of the P4 layer, which has a spatial resolution of 1 / 16 of the input image. It has the largest receptive field and the strongest semantic expression ability and is specifically used to detect large-scale defects such as cracks and large-area stains. b. Each detection branch uses the same internal structure design. First, the input fusion features are further transformed and dimensionally adjusted through the Conv2d convolution layer. This convolution layer uses a 3×3 convolution kernel, a stride of 1, and a padding of 1 to ensure that the feature map size remains unchanged while enhancing the feature expression capability. The number of output channels of the convolution layer is set according to the specific detection task requirements to provide sufficient feature expression dimensions. c. The features of each branch are processed by the BatchNorm2d batch normalization layer. The batch normalization layer independently normalizes each channel of the feature map. The calculation formula is: , where μ and σ² are the mean and variance of the features within the batch, respectively, and γ and β are learnable scaling and bias parameters, It is a small constant to prevent division by zero; this normalization operation can accelerate network convergence, improve training stability, and to a certain extent play a role in regularization to prevent overfitting; d. Each branch completes the final object detection task through a specially designed Detect detection head. The Detect detection head adopts a decoupled design approach, handling classification and regression tasks separately. The classification branch is responsible for predicting whether each candidate region contains a defect and the specific defect category. The output dimension is (num_classes + 1) × anchor_num, where num_classes is the number of defect categories and "+1" represents the background category. The regression branch is responsible for predicting the precise location and size of the defect bounding box. The output dimension is 4 × anchor_num, corresponding to the center coordinate offset (Δx, Δy) and width and height scaling factors (Δw, Δh) of the bounding box, respectively. e. Each Detect head also integrates a confidence prediction mechanism, outputting a confidence score for each prediction result. The final detection result is post-processed using the non-maximum suppression (NMS) algorithm to eliminate duplicate detection frames and retain the detection result with the highest confidence. The outputs of the three scale detection branches are merged to form the final detection result, achieving comprehensive coverage and precise positioning of defects of different sizes.
5. The method for detecting surface defects of industrial products based on feature coupling according to claim 1, characterized in that: Perform end-to-end training and LAMP pruning optimization, including the following steps: a. First, an end-to-end training phase is conducted, using an industrial product surface defect dataset to train the complete detection network. The training process uses a multi-task loss function that combines classification loss, bounding box regression loss, and confidence loss. The total loss function expression is: , in 、 、 is the weight coefficient; the classification loss uses Focal Loss to reduce the impact of simple samples on training. The specific formula is: , Among them, α is the balance factor, γ is the focus parameter, and p is the prediction probability; the bounding box regression loss uses GIoU Loss to improve the positioning accuracy. The specific formula is: , Where C is the smallest rectangle containing the predicted box A and the true box B, and IoU is the intersection over union ratio. The cosine annealing learning rate scheduling strategy is used during training, and the learning rate calculation formula is: , Ensure the stability of model convergence; b. After training is complete, the LAMP (Layer-Adaptive Magnitude-based Pruning) pruning strategy is implemented to optimize model compression. The LAMP pruning algorithm introduces a global pruning importance scoring mechanism that considers not only the absolute magnitude of weights but also the importance differences between layers. First, the weight tensor W of each layer in the network is processed. These weights may come from fully connected layers or convolutional layers. The weight tensor of each layer is typically a two-dimensional matrix, which is flattened and sorted by weight to form a one-dimensional weight vector for subsequent importance evaluation. The calculation of the LAMP score is based on the importance of each weight, that is, the size of the weight, and not only considers the size of a single weight, but also evaluates the relative importance of the weight in the global context; the calculation formula of the LAMP score is as follows: , Where W[u] represents the u-th weight, and the denominator represents the sum of the squares of all weights from index u to the end of the weight list in this layer; larger weights correspond to higher LAMP scores, while relatively low LAMP scores will be pruned; In order to further quantify the importance of weights, a weight comparison mechanism is introduced. The specific formula is as follows: , like , then the corresponding LAMP score satisfies , which indicates that connections with larger weights contribute more significantly to model performance, so they are more likely to be retained during pruning; this quantification method enables the LAMP score to effectively measure the local importance of each weight and its global impact, thereby formulating a more accurate pruning strategy; by calculating the LAMP score of each connection, it is possible to more accurately decide which connections need to be retained and which unimportant connections can be pruned until the global sparsity constraint is met; the performance of the model after pruning is evaluated by testing the detection accuracy of the pruned model on the validation set to ensure that the pruning process does not significantly damage the model performance; performance evaluation indicators include mAP, inference speed, model size, etc.; if the performance degradation exceeds the preset threshold, it falls back to the previous pruning state and adjusts the pruning strategy.
Citation Information
Patent Citations
Traffic flow prediction method based on global diffusion convolution residual network
CN112071065A
Cross-scale defect detection method
CN117094999A
Metal surface defect detection and classification method for multi-scale learning task
CN117576095A
Photovoltaic panel surface defect detection method based on pruning multi-scale feature fusion network
CN120278992A
Image defect detection system, training method, defect detection method and electronic equipment
CN120298321A
Cited By
Photovoltaic module defect identification method
CN120931634A
Defect detection method and system for X-ray welding seam image
CN121437509A
A method and system for defect detection oriented to X-ray weld seam images
CN121437509B
Insulator defect detection method based on super-resolution reconstruction and deep learning fusion
CN122023410A
Insulator defect detection method based on fusion of super-resolution reconstruction and deep learning
CN122023410B