A feature coupling-based industrial product surface defect detection method
By employing a feature-coupled detection method, combined with a self-attention mechanism and depthwise separable convolution, high efficiency and high accuracy in detecting surface defects in industrial products are achieved. This method overcomes the difficulties of traditional methods in detecting defects in complex backgrounds and is applicable to the detection of industrial products, medical images, and remote sensing targets.
Patent Information
- Application Number
- CN202511247708.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-03
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2045-09-03
AI Technical Summary
Traditional methods for detecting surface defects in industrial products struggle to maintain high efficiency and accuracy when dealing with complex backgrounds and varied defect morphologies. In particular, when the defect scale distribution is uneven and the difference from the background is slight, existing methods are unable to provide satisfactory detection results.
We employ a feature-coupled detection method that integrates a self-attention mechanism with a dual-branch module design of depthwise separable convolutions, multi-scale feature extraction using dilated pyramid shared convolutions, and structured pruning optimization. Combined with feature fusion networks and detection head design, this approach achieves global information understanding and local detail capture, enhancing multi-scale contextual information extraction.
It improves the accuracy and robustness of surface defect detection in industrial products, effectively handles complex backgrounds and multi-scale defects, reduces computational complexity and annotation costs, and is suitable for the detection of industrial products, medical images, and remote sensing targets.
Smart Images

Figure CN120766047B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of defect detection, in particular to an industrial product surface defect detection method requiring coexistence of speed and accuracy. BACKGROUND
[0002] In today's industrial internet era, with the rapid development of artificial intelligence and deep learning technology, some manufacturing industries are undergoing profound changes. Among them, industrial intelligence as a key driving force is leading the manufacturing industry to a new height. In this process, industrial product surface defect detection technology is attracting attention due to its importance to product quality control. Traditional defect detection methods mainly rely on manual visual inspection and rule-based automated systems. Although manual inspection can adapt to various product types and complex defect shapes, it is inefficient and easily affected by subjective factors, making it difficult to ensure the consistency and accuracy of detection. In addition, long hours of work can cause fatigue for operators, further increasing the risk of missed or false detections. In order to improve detection efficiency and consistency, rule-based automated detection systems have emerged. Such systems usually use image processing techniques such as edge detection, threshold segmentation, texture analysis, etc. to identify specific types of defects. However, since these methods highly depend on pre-defined features and parameter settings, they often struggle to cope with complex background environments and changes in defect shapes, resulting in limited detection accuracy. For example, when dealing with defects with irregular shapes or low contrast, traditional methods cannot provide satisfactory detection results. Therefore, there is an urgent need for a new defect detection method aimed at overcoming these limitations to meet the rapidly changing design and production needs of industrial product surface defects. Therefore, the defect detection method based on feature coupling in the present application improves the multi-scale context information extraction efficiency by improving the global-local feature fusion capability, thereby improving the detection accuracy of industrial product surface defects. SUMMARY
[0003] The purpose of the present application is to overcome the shortcomings and deficiencies of the prior art, and to provide a defect detection method based on feature coupling, which breaks through the traditional industrial product surface defect detection method C3k2 module to capture insufficient fine-grained information, SPPF module to blur local features, and deep learning model with high computational complexity. Through the design of a double-branch module integrating self-attention mechanism and deep separable convolution, multi-scale feature extraction of an inflation pyramid shared convolution, and lightweight optimization of structured pruning, it can simultaneously maintain global information understanding and local detail capture, while achieving detection accuracy improvement while being lightweight.
[0004] To achieve the above purpose, the present application realizes the following technical scheme: a defect detection method based on feature coupling, comprising the following steps:
[0005] 1) Design a backbone network containing four stages, where Stage1 and Stage2 use CBS modules and C3k2_SCGF modules for shallow feature extraction. The deep convolution is responsible for capturing spatial feature patterns, and the pointwise convolution is responsible for integrating feature information between different channels. The spatial-channel feature depth coupling is achieved through a series of connections. Stage3 and Stage4 use CBS modules and C3k2_NAGF modules for deep feature extraction. The C3k2_NAGF module fuses global modeling features based on self-attention mechanisms with local features from traditional convolution operations. The complementary coupling of different feature extraction methods is achieved through feature weighting and residual connection. Finally, integrate the DPSC module and the C2PSA module. Dilated convolution extracts features at different receptive field scales, then couples these multi-scale features in the channel dimension to achieve progressive feature learning from local details to global semantics.
[0006] 2) According to the multi-scale features extracted in step 1), construct a feature fusion network: design the Neck part using the FPN structure, and realize the effective fusion of different scale features through Concat operation, Upsample up-sampling and C3k2_SCGF module. High-level semantic information is spliced with low-level detail information through up-sampling, and the feature expression is further optimized through the C3k2_SCGF module.
[0007] 3) According to the fused features in step 2), construct a multi-scale detection head: design three detection branches of different scales, each branch contains Conv2d convolution layer, BatchNorm2d normalization layer and Detect detection head, which are responsible for detecting different size defect targets, and realize the comprehensive coverage of small, medium and large scale defects.
[0008] 4) According to the network architecture completed in step 3), perform end-to-end training and LAMP pruning optimization: use the industrial product surface defect dataset to train the network, then apply the LAMP pruning strategy to calculate the weight importance score, delete the connection parameters with small contribution, and significantly reduce the model parameter quantity and computational complexity while maintaining the detection performance.
[0009] In step 1), there are four stages:
[0010] a、Stage1 and Stage2 stage, the input image is first extracted by the CBS (Conv+BatchNorm+SiLU) module for initial feature extraction, which combines convolution operation, batch normalization and SiLU activation function, effectively extracting the basic texture information of the image; then the feature map is input into the C3k2_SCGF (Separable Convolution Gated Former) module, which adopts a deep separable convolution structure, focusing on capturing spatial features of each channel through deep convolution Dconv, and then performing cross-channel feature fusion through pointwise convolution Pconv, whose calculation formula is as follows:
[0011] ,
[0012] Wherein, PwConv is pointwise convolution, which enables each spatial position of the feature map to combine features from all channels, thereby effectively enhancing information expression. Act is the activation function, which enables the network to express more complex patterns and prevents the model from merely performing linear combination. DwConv is deep convolution, which can help capture spatial features of each channel through independent convolution of each channel, which is particularly beneficial when processing complex images. The combination of the two, deep convolution is responsible for capturing spatial features of each channel, while pointwise convolution is responsible for integrating these spatial features across channels, thereby providing richer and more comprehensive feature representation, and avoiding unnecessary cross-channel features, thereby reducing computational cost. The C3k2_SCGF module realizes the deep coupling of spatial-channel features through a series of ways.
[0013] b、When entering the deep feature extraction stage of Stage3 and Stage4, the combination of CBS module and C3k2_NAGF (Neighborhood Aware Gated Former) module is adopted. The C3k2_NAGF module introduces a self-attention mechanism to realize global context modeling by calculating Query, Key and Value matrices, whose calculation formula is as follows:
[0014] ,
[0015] Wherein, Q, K, and V are Query, Key and Value extracted from the input feature map, d is the dimension of the input key vector, and the Softmax operation is used to normalize the attention score. The C3k2_NAGF module captures the dependency relationship between distant pixels in the feature map through the self-attention mechanism, providing more rich context information for defect detection, while capturing local detail features through the deep separable convolution of the C3k2_SCGF module. The two realize deep coupling through parallel processing and residual connection, ensuring that global semantic information is obtained while local detail information is retained.
[0016] c、In the last 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), and its calculation formula is as follows:
[0017] ,
[0018] where d is the dilation rate, respectively 1, 3, 5..., and then the results of all dilated convolutions are spliced along the channel dimension, and its calculation formula is as follows:
[0019] ,
[0020] where Y1, Y3, Y5 are the dilation rates when 1, 3, 5 respectively. Finally, the spliced feature map is mapped to the final output channel number through a 1x1 convolution to get the output. The DPSC module concatenates these feature maps with different receptive field ranges along the channel axis to build a multi-level feature representation containing from fine-grained local texture to coarse-grained global pattern, thereby realizing comprehensive capture and unified modeling of defect information of different scales.
[0021] d、Finally, the C2PSA module is used, which combines cross-stage partial connection and self-attention mechanism to realize position-sensitive feature enhancement through PSABlock. Shortcut connection is used inside the module to ensure gradient flow, and Conv2d convolution operation is used to adjust the feature dimension, and finally Concat operation is used to fuse the feature representations of different paths.
[0022] In step 2), the specific implementation process of the feature fusion network is as follows according to the multi-scale features extracted in step 1):
[0023] a、The feature pyramid network (FPN) architecture is used as the core structure of the Neck part to realize the top-down feature fusion path. First, the P5 high-level feature output by the backbone network is taken as the starting point, which contains rich semantic information but low spatial resolution. Through the Upsample up-sampling operation, the spatial size of the P5 feature is enlarged by one time, so that it is consistent with the spatial dimension of the P4 feature map. The bilinear interpolation method is used for up-sampling to ensure smooth transition of feature information.
[0024] b. The upsampled P5 features are concatenated and fused with the features extracted in the P4 stage using a Concat operation along the channel dimension. This concatenation method effectively combines high-level semantic information and mid-level feature representations. 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, enhancing the expressive power and discriminative power of the features.
[0025] c. Continuing along the top-down fusion path, the optimized P4 features are amplified to a spatial size matching the P3 features using the same Upsample operation. Then, a Concat operation is performed to combine the fused P4 layer features with the original P3 layer features. This process ensures that deep semantic information is effectively transmitted to the shallow layer while preserving the detailed expressive power of the shallow features. The fused P3 features are also processed by the C3k2_SCGF module, further optimizing feature quality through local feature enhancement and cross-channel information interaction.
[0026] d. The processed P3 features are further upsampled to maintain their spatial dimensions consistent with the P2 features, and then final feature fusion is performed. This fusion stage combines feature information from all levels from P5 to P2, forming a comprehensive feature representation containing multi-scale semantics and detailed information. The fused P2 features undergo final optimization processing by the C3k2_SCGF module to generate multi-scale fused features with strong expressive power.
[0027] In step 3), the specific implementation process of constructing the multi-scale detection head based on the fused features from 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 fused features from layer P2 as input. This feature map has the highest spatial resolution, being 1 / 4 of the input image, and can retain rich detail information, making it particularly suitable for detecting tiny defects such as pinholes and minor scratches. The medium-scale detection branch processes fused features from layer P3, with a spatial resolution of 1 / 8 of the input image. While maintaining some detail information, it has a larger receptive field and is mainly responsible for detecting medium-sized defects such as spots and small-area corrosion. The large-scale detection branch receives fused features from layer P4, with 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 for detecting large-sized defects such as cracks and large-area stains.
[0029] b. Each detection branch adopts the same internal structure design. Firstly, the input fusion features are further transformed and dimensionally adjusted through a Conv2d convolution layer. The convolution layer uses a 3x3 convolution kernel, a stride of 1, and a padding of 1, ensuring that the feature map size remains unchanged while enhancing the expression ability of the features. The output channel number of the convolution layer is set according to the specific detection task requirements to provide sufficient feature expression dimensions.
[0030] c. The features of each branch are processed through a BatchNorm2d batch normalization layer. The batch normalization layer independently normalizes each channel of the feature map, and the calculation formula is:
[0031] ,
[0032] where μ and σ 2 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, play a role in regularization, preventing overfitting.
[0033] d. Each branch completes the final target detection task through a specially designed Detect detection head. The Detect detection head adopts a decoupled design idea, which separately processes the classification task and the regression task. The classification branch is responsible for predicting whether each candidate region contains defects and the specific category of the defects, with an output dimension of (num_classes + 1) x 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 position and size of the defect bounding box, with an output dimension of 4 x anchor_num, corresponding to the center coordinate offset (Δx, Δy) and the width-height scaling factor (Δw, Δh) of the bounding box, respectively.
[0034] e. Each Detect detection head also integrates a confidence prediction mechanism, outputting the confidence score of each prediction result. The final detection results are post-processed through the non-maximum suppression (NMS) algorithm to eliminate duplicate detection boxes and retain the detection result with the highest confidence. The outputs of the three scale detection branches are combined to form the final detection results, achieving comprehensive coverage and precise positioning of defects of different sizes.
[0035] In step 4), the specific implementation process of end-to-end training and LAMP pruning optimization according to the network architecture completed in steps 2) and 3) is as follows:
[0036] a、First, an end-to-end training phase is performed, and an industrial product surface defect dataset is used to train the complete detection network. The training process adopts a multi-task loss function, combining classification loss, bounding box regression loss and confidence loss, and the total loss function expression is:
[0037] ,
[0038] wherein , , is the weight coefficient. The classification loss adopts Focal Loss to reduce the influence of simple samples on training, and the specific formula is:
[0039] ,
[0040] wherein α is the balance factor, γ is the focusing parameter, and p is the prediction probability. The bounding box regression loss adopts GIoU Loss to improve the positioning accuracy, and the specific formula is:
[0041] ,
[0042] wherein C is the smallest rectangle containing the predicted box A and the real box B, and IoU is the intersection over union. During the training process, a cosine annealing learning rate scheduling strategy is adopted, and the learning rate calculation formula is:
[0043] ,
[0044] to ensure the stability of model convergence.
[0045] b、After training, 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, which not only considers the absolute magnitude of the weights, but also combines the weight importance differences between layers. First, the weight tensor W of each layer in the network is processed, which may come from the fully connected layer or the convolutional layer. The weight tensor of each layer is usually a two-dimensional matrix, which is flattened and sorted according to the weight size to form a one-dimensional weight vector for subsequent importance evaluation.
[0046] The calculation of LAMP score is based on the importance of each weight, i.e. 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. The calculation formula of LAMP score is as follows:
[0047] ,
[0048] where W[u] represents the u-th weight, and the denominator represents the sum of squares of all weights from index u to the end of the weight list in that layer. Larger weights correspond to higher LAMP scores, and relatively lower LAMP scores will be pruned.
[0049] To further quantify the importance of weights, a comparison mechanism of weight size is introduced, and the specific formula is as follows:
[0050] ,
[0051] If , the corresponding LAMP score satisfies , which indicates that connections with larger weights contribute more significantly to model performance, and therefore 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 impact in the global, thereby developing a more accurate pruning strategy. By calculating the LAMP score of each connection, it can more accurately determine which connections need to be retained and which unimportant connections can be pruned, until the global sparsity constraint condition is met.
[0052] Performance evaluation of the pruned model, by testing the detection accuracy of the pruned model on the validation set, ensures that the pruning process does not significantly harm the model performance. Performance evaluation indicators include mAP, inference speed, model size, etc. If the performance decreases 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 application has the following advantages and beneficial effects:
[0054] 1. The present application realizes the modeling of global-local multi-level feature dependency in industrial product surface defect detection, enhances the model's ability to distinguish complex backgrounds, and retains key local detail feature information, effectively solving the problem of defect detection with uneven defect size distribution and weak background difference.
[0055] 2. The present application can combine the advantages of self-attention mechanism and gated linear units, expand the receptive field through dilated convolution without reducing spatial resolution, and use LAMP method for pruning, significantly reducing the annotation cost and time.
[0056] 3. The method of the present application has wide application space in industrial product surface defect detection and strong practicality, and has broad prospects in medical image, remote sensing target detection and many other fields. BRIEF DESCRIPTION OF DRAWINGS
[0057] Figure 1 The figure is a schematic diagram of the logic flow of the present application.
[0058] Figure 2The framework of the method of the present application.
[0059] Figure 3 The structure diagram of C3k2_NAGF and C3k2_SCGF of the present application. DETAILED DESCRIPTION
[0060] The present application will be further described in detail below in conjunction with examples and drawings, but the embodiments of the present application are not limited thereto.
[0061] The present embodiment discloses a defect detection method based on feature coupling, as shown in Figure 1 ; the method is logically implemented, as shown in Figure 2 ; the method sends the image into the cross-scale feature fusion network for multi-level feature extraction and global-local information modeling; through the C3k2_NAGF and C3k2_SCGF modules, the global context dependency and local detail features are emphasized, so as to fully utilize the self-attention mechanism of MetaFormer and the gating information screening ability of CGLU; considering that the surface defects of industrial products are highly similar to the background and the traditional SPPF module has the problem of loss of detail information, DPSC (Dilated Pyramid Shared Convolution) multi-scale feature extraction is performed to retain high-resolution fine-grained spatial features; through the PSABlock position-sensitive attention mechanism and the C2PSA module, the feature discrimination ability and defect positioning accuracy are improved, and the final detection accuracy is further improved. Specifically, the following steps are included:
[0062] 1) In Figure 2 , a given image is sent into the backbone;
[0063] a, Stage1 and Stage2 stages, the input image is first subjected to initial feature extraction through the CBS (Conv+BatchNorm+SiLU) module, which combines convolution operation, batch normalization and SiLU activation function, effectively extracting the basic texture information of the image; then the feature map is input into the C3k2_SCGF (Separable Convolution Gated Former) module, which adopts a deep separable convolution structure, focusing on capturing spatial features of each channel through deep convolution Dconv, and then performing cross-channel feature fusion through point-wise convolution Pconv, whose calculation formula is as follows:
[0064] ,
[0065] where PwConv is point-wise convolution, which enables each spatial location of the feature map to combine features from all channels, thus effectively enhancing information expression. Act is the activation function, which enables the network to express more complex patterns and prevents the model from simply performing linear combinations. DwConv is depth-wise convolution, which can help capture spatial features of each channel by independent convolution of each channel, which is particularly advantageous when processing complex images. The combination of the two, depth-wise convolution is responsible for capturing spatial features of each channel, while point-wise convolution is responsible for integrating these spatial features across channels, thus providing a richer and more comprehensive feature representation, and avoiding unnecessary cross-channel features, thus reducing computational cost. The C3k2_SCGF module realizes the deep coupling of spatial-channel features through a series of cascaded connections.
[0066] b. When entering the deep feature extraction stage of Stage 3 and Stage 4, the combination of CBS module and C3k2_NAGF (Neighborhood Aware Gated Former) module is adopted. The C3k2_NAGF module introduces a self-attention mechanism to realize global context modeling by calculating Query, Key and Value matrices, and its calculation formula is as follows:
[0067] ,
[0068] where Q, K, and V are Query, Key and Value extracted from the input feature map, d is the dimension of the input key vector, and the Softmax operation is used to normalize the attention score. The C3k2_NAGF module captures the dependency between distant pixels in the feature map through the self-attention mechanism, providing more rich context information for defect detection, while capturing local detail features through the depth separable convolution of the C3k2_SCGF module. The two are deeply coupled through parallel processing and residual connection to ensure that global semantic information is obtained while local detail information is preserved.
[0069] c. In the last stage of the backbone network, the DPSC (Dilated Pyramid Shared Conv) module is integrated instead of the traditional SPPF module. The DPSC module processes the feature map in parallel by applying dilated convolutions with different dilation rates (d = 1, 3, 5), and its calculation formula is as follows:
[0070] ,
[0071] where d is the dilation rate, respectively 1, 3, 5, and the results of all dilated convolutions are concatenated along the channel dimension, and its calculation formula is as follows:
[0072] ,
[0073] The expansion rate when Y1, Y3, Y5 are 1, 3, 5 respectively. Finally, the spliced feature map is mapped to the final output channel number through a 1x1 convolution to obtain the output. The DPSC module serially fuses these feature maps with different receptive field ranges along the channel axis to construct a multi-level feature representation containing local texture from fine granularity to global pattern from coarse granularity, thereby realizing comprehensive capture and unified modeling of defect information at different scales.
[0074] d, finally, a C2PSA module is used, which combines cross-stage partial connection and self-attention mechanism to realize position-sensitive feature enhancement through PSABlock. Shortcut connection is used inside the module to ensure gradient flow, and Conv2d convolution operation is used to adjust the feature dimension, and finally Concat operation is used to fuse the feature representations of different paths.
[0075] 2) The specific implementation process of the feature fusion network constructed by the extracted multi-scale features is as follows:
[0076] a, the feature pyramid network (FPN) architecture is used as the core structure of the Neck part to realize the top-down feature fusion path. First, the P5 high-level feature output by the backbone network is taken as the starting point, which contains rich semantic information but low spatial resolution. The spatial size of the P5 feature is doubled through the Upsample upsampling operation to make it consistent with the spatial dimension of the P4 feature map. The bilinear interpolation method is used for upsampling to ensure smooth transition of feature information.
[0077] b, the P5 feature after upsampling is concatenated with the feature extracted in the P4 stage through the Concat operation to realize the channel dimension splicing and fusion. This splicing method can effectively combine high-level semantic information and middle-level feature representation. The fused feature is then input into the C3k2_SCGF module for further feature optimization and information integration. The module uses depthwise separable convolution and gating mechanism to finely process the fused feature, enhancing the expression ability and discriminability of the feature.
[0078] c, continue along the top-down fusion path, and enlarge the optimized P4 feature to the spatial size matching the P3 feature through the same Upsample upsampling operation. Then perform Concat splicing operation to realize the combination of P4 layer fused feature and P3 layer original feature. This process ensures that the deep semantic information can be effectively transmitted to the shallow layer while maintaining the detail expression ability of the shallow feature. The fused P3 feature also undergoes C3k2_SCGF module processing, further optimizing the feature quality through local feature enhancement and cross-channel information interaction.
[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 target detection task through a specially designed Detect head. The Detect head adopts a decoupled design idea to handle classification and regression tasks separately. The classification branch is responsible for predicting whether each candidate region contains defects and the specific category of defects, with an output dimension of num_classes + 1) x 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 position and size of the defect bounding box, with an output dimension of 4 x anchor_num, corresponding to the center coordinate offset (Δx, Δy) and the width-height scaling factor (Δw, Δh) of the bounding box, respectively.
[0087] e、Each Detect head also integrates a confidence prediction mechanism, outputting a confidence score for each prediction result. The final detection results are post-processed by the Non-Maximum Suppression (NMS) algorithm to eliminate duplicate detection boxes and retain the highest confidence detection results. The outputs of the three scale detection branches are combined to form the final detection results, achieving comprehensive coverage and precise positioning of defects of different sizes.
[0088] 4) The specific implementation process of the completed network architecture for end-to-end training and LAMP pruning optimization is as follows:
[0089] a、First, the end-to-end training phase is performed, and the complete detection network is trained using an industrial product surface defect dataset. The training process uses a multi-task loss function combining classification loss, bounding box regression loss, and confidence loss, and the total loss function expression is:
[0090] ,
[0091] where 、 、 are the weight coefficients. The classification loss uses Focal Loss to reduce the impact of simple samples on training, and its specific formula is:
[0092] ,
[0093] where α is the balance factor, γ is the focus parameter, and p is the predicted probability. The bounding box regression loss uses GIoU Loss to improve positioning accuracy, and its specific formula is:
[0094] ,
[0095] where C is the smallest rectangle containing the predicted box A and the real box B, and IoU is the intersection over union. During training, a cosine annealing learning rate scheduling strategy is used, and the learning rate calculation formula is:
[0096] ,
[0097] Ensure the stability of model convergence.
[0098] b. After training, implement the LAMP (Layer-Adaptive Magnitude-based Pruning) pruning strategy for model compression optimization. LAMP pruning algorithm introduces a global pruning importance scoring mechanism, which not only considers the absolute magnitude of weights, but also combines the weight importance difference between layers. First, process the weight tensor W of each layer in the network, which may come from fully connected layers or convolutional layers. The weight tensor of each layer is usually a two-dimensional matrix, which is flattened and sorted by weight size to form a one-dimensional weight vector for subsequent importance evaluation.
[0099] The calculation of LAMP score is based on the importance of each weight, i.e. 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. The calculation formula of LAMP score is as follows:
[0100] ,
[0101] where W[u] represents the u-th weight, and the denominator represents the sum of squares of all weights from index u to the end of the weight list in the layer. Larger weights correspond to higher LAMP scores, while relatively lower LAMP scores will be pruned.
[0102] To further quantify the importance of weights, a weight size comparison mechanism is introduced, with the specific formula as follows:
[0103] ,
[0104] If , the corresponding LAMP score satisfies , which indicates that larger weight connections contribute more significantly to model performance, so they are more likely to be retained during pruning. This quantification method enables LAMP scores to effectively measure the local importance of each weight and its impact in the global, thereby developing a more accurate pruning strategy. By calculating the LAMP score of each connection, it can more accurately determine which connections to retain and which unimportant connections to prune, until the global sparsity constraint is met.
[0105] Performance evaluation of the pruned model, by testing the detection accuracy of the pruned model on the validation set, to ensure that the pruning process does not significantly harm the model performance. Performance evaluation indicators include mAP, inference speed, model size, etc. If the performance drops more than the preset threshold, revert to the previous pruning state and adjust the pruning strategy.
[0106] In summary, after adopting the above scheme, the application can effectively break through the limitation of traditional convolution local receptive field, capture long-distance pixel dependence and multi-scale context information, retain high-resolution fine-grained spatial features and local detail information, improve the precision, robustness and adaptability to complex background of the industrial product surface defect detection, has practical popularization value, and is worth popularizing.
[0107] The above-described embodiments are only the preferred embodiments of the present application, and do not limit the scope of the application. Any changes made in shape or principle according to the present application should be covered within the scope of protection of the present application.
Claims
1. A feature coupling-based method for detecting surface defects of an industrial product, characterized in that, The backbone network includes four stages, a feature fusion network is constructed, a multi-scale detection head is constructed, end-to-end training is performed, and LAMP pruning optimization is performed: S1: a four-stage backbone network, wherein Stage 1 and Stage 2 adopt a CBS module and a C3k2_SCGF module for shallow feature extraction, the C3k2_SCGF (Separable Convolution Gated Former) module adopts a deep separable convolution structure, focuses on capturing spatial features of each channel through a deep convolution DwConv, and then performs cross-channel feature fusion through a point-wise convolution PwConv, and the calculation formula is as follows: , wherein Act is an activation function; Stage 3 and Stage 4 adopt a CBS module and a C3k2_NAGF module for deep feature extraction, the C3k2_NAGF (Neighborhood Aware Gated Former) module introduces a self-attention mechanism, and global context modeling is achieved by calculating Query, Key and Value matrices, and the calculation formula is as follows: , wherein Q, K, and V are Query, Key and Value extracted from the input feature map, and a Softmax operation is used for normalizing attention scores; finally, a DPSC module and a C2PSA module are integrated, the DPSC (Dilated Pyramid Shared Conv) module processes feature maps in parallel by applying dilated convolutions with different dilation rates, and the calculation formula is as follows: , wherein d is the dilation rate, and is 1, 3, 5, respectively, and the results of all dilated convolutions are spliced along the channel dimension, and the calculation formula is as follows: , wherein Y1, Y3, and Y5 are feature maps with dilation rates of 1, 3, and 5, respectively; finally, the spliced feature map is mapped to the final output through a 1x1 convolution; dilated convolutions extract features at different receptive field scales, and then these multi-scale features are spliced and coupled in the channel dimension to achieve progressive feature learning from local details to global semantics; S2: constructing a feature fusion network: the neck network adopts a FPN structure, and different scale features are effectively fused through Concat operation, Upsample up-sampling and C3k2_SCGF module, wherein high-level semantic information is spliced with low-level detail information through up-sampling, and the feature expression is further optimized through the C3k2_SCGF module; S3: constructing a multi-scale detection head: three detection branches of different scales are designed, each branch includes a Conv2d convolution layer, a BatchNorm2d normalization layer and a Detect detection head, and is responsible for detecting defects of different sizes, and realizes comprehensive coverage of small, medium and large scale defects; S4: End-to-end training and LAMP pruning optimization: The network is trained using an industrial product surface defect dataset, and then the LAMP pruning strategy is applied to calculate the weight importance score, delete the connection parameters with small contribution, and significantly reduce the model parameter quantity and computational complexity while maintaining detection performance.
2. The feature coupling-based industrial product surface defect detection method according to claim 1, characterized in that, The feature fusion network is constructed, including the following steps: S21: A feature pyramid network (FPN) architecture is adopted as the core structure of the neck network to realize a top-down feature fusion path; first, the P5 deep layer feature output by the backbone network is taken as the starting point, and the P5 deep layer feature contains rich semantic information but low spatial resolution; the spatial size of the P5 feature is doubled through Upsample up-sampling operation to make it consistent with the spatial dimension of the P4 feature map, and the bilinear interpolation method is used for up-sampling to ensure smooth transition of feature information; S22: The P5 feature after up-sampling is spliced and fused with the feature extracted at the P4 stage through Concat operation in the channel dimension; the fused feature is input into the C3k2_SCGF module for further feature optimization and information integration, and the fused feature is finely processed through depth separable convolution and gating mechanism to enhance the expression ability and discriminativeness of the feature; S23: Continue along the top-down fusion path, the optimized P4 feature is enlarged to match the spatial size of the P3 feature through the same Upsample up-sampling operation; then the Concat splicing operation is performed to realize the combination of the P4 layer fusion feature and the P3 layer original feature; ensure that the deep semantic information can be effectively transmitted to the shallow layer, while maintaining the detail expression ability of the shallow feature; the fused P3 feature is also processed by the C3k2_SCGF module, and the feature quality is further optimized through local feature enhancement and cross-channel information interaction; S24: The processed P3 feature is continuously up-sampled to make its spatial size consistent with that of the P2 feature, and the final feature fusion is performed; the fusion of this stage combines the feature information of all levels from P5 to P2, forming a comprehensive feature representation containing multi-scale semantic and detail information; the fused P2 feature is finally optimized by the C3k2_SCGF module to generate multi-scale fusion features with strong expression ability.
3. The feature coupling-based industrial product surface defect detection method according to claim 1, characterized in that, The multi-scale detection head is constructed, including the following steps: S31: Three parallel detection branches are designed, which correspond to the optimization design of small, medium and large scale defect detection tasks respectively; the small scale detection branch receives the fusion feature from the P2 layer as input, the fusion feature of the P2 layer has the highest spatial resolution, which is 1 / 4 of the input image, and can retain rich detail information, which is suitable for detecting small defects; the medium scale detection branch processes the fusion feature of the P3 layer, which has a spatial resolution of 1 / 8 of the input image, and has a larger receptive field while maintaining the detail information, which is responsible for detecting medium-sized defects; the large scale detection branch receives the fusion feature of the P4 layer, which has a spatial resolution of 1 / 16 of the input image, has the largest receptive field and the strongest semantic expression ability, and is used for detecting large-sized defects; S32: The internal structure design of the branch is detected, and the fused features are further transformed and dimensionally adjusted by a Conv2d convolutional layer first. The convolutional layer uses a 3x3 convolution kernel, a step of 1, and a padding of 1, ensuring that the feature map size remains unchanged while enhancing the expression ability of the features. The output channel number of the convolutional layer is set according to the specific detection task requirements to provide the feature expression dimension; S33: The features of each branch are processed by a BatchNorm2d batch normalization layer. The batch normalization layer independently normalizes each channel of the feature map, and the calculation formula is: , where μ and σ2are the mean and variance of the features within a batch, and a' and β are learnable scaling and shift parameters, is a small constant to prevent division by zero; the normalization operation can accelerate network convergence, improve training stability, and act as a regularization to prevent overfitting. S34: Each branch completes the final target detection task through a designed Detect detection head. The Detect detection head adopts a decoupled design idea, which processes the classification task and the regression task separately. The classification branch is responsible for predicting whether each candidate region contains defects and the specific category of the defects, and the output dimension is (num_classes + 1) x 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 accurate position and size of the defect bounding box, and the output dimension is 4 x anchor_num, corresponding to the center coordinate offset (Δx, Δy) and the width-height scaling factor (Δw, Δh) of the bounding box, respectively; S35: Each Detect detection head also integrates a confidence prediction mechanism, outputting the confidence score of each prediction result. The final detection result is post-processed by the non-maximum suppression (NMS) algorithm to eliminate duplicate detection boxes and retain the detection result with the highest confidence. The outputs of the three scale detection branches are combined to form the final detection result, achieving comprehensive coverage and accurate positioning of defects of different sizes.
4. The feature coupling-based industrial product surface defect detection method according to claim 1, characterized by, End-to-end training and LAMP pruning optimization, including the following steps: S41: First, the end-to-end training stage is performed, and the complete detection network is trained using an industrial product surface defect dataset. The training process uses a multi-task loss function, combining classification loss, bounding box regression loss, and confidence loss. The total loss function expression is: , wherein , , are weight coefficients; the classification loss adopts Focal Loss to reduce the influence of simple samples on training, and the specific formula is: , where α is the balance factor, γ is the focus parameter, and p is the predicted probability. The bounding box regression loss uses GIoU Loss to improve the positioning accuracy, and the specific formula is: , where C is the smallest rectangle containing the predicted box A and the real box B, and IoU is the intersection over union. During the training process, a cosine annealing learning rate scheduling strategy is used, and the learning rate calculation formula is: , to ensure the stability of model convergence; S42: Implementing LAMP (Layer-Adaptive Magnitude-based Pruning) pruning strategy for model compression optimization; LAMP pruning algorithm introduces a global pruning importance scoring mechanism, which not only considers the absolute magnitude of the weight, but also combines the weight importance difference between layers; First, the weight tensor W of each layer in the network is processed, which comes from the fully connected layer and the convolutional layer; The weight tensor of each layer is a two-dimensional matrix, which is flattened and sorted according to the weight size to form a one-dimensional weight vector for subsequent importance evaluation; The calculation of LAMP score is based on the importance of each weight, i.e. the size of the weight, and not only considers the size of a single weight, but also evaluates the importance of each weight in the global; The calculation formula of LAMP score is as follows: , Where W[u] represents the u-th weight; large weights correspond to high LAMP scores, while low LAMP score weights will be pruned; In order to further quantify the importance of the weight, a weight size comparison mechanism is introduced, and the specific formula is as follows: , If then the corresponding LAMP score satisfies This indicates that the connections with large weights contribute more significantly to the model performance, and therefore they are retained during the pruning process; this quantification method enables the LAMP score to effectively measure the local importance of each weight and its impact in the global, thereby developing a more accurate pruning strategy; by calculating the LAMP score of each connection, it is more accurate to determine which connections need to be retained and which unimportant connections are pruned until the global sparsity constraint is met; the performance evaluation of the pruned model ensures that the pruning process does not significantly compromise the model performance by testing the detection accuracy of the pruned model on the validation set; performance evaluation indicators include mAP, inference speed, and model size; if the performance drops exceed the pre-set threshold, revert to the previous pruning state and adjust the pruning strategy.
Citation Information
Patent Citations
Photovoltaic panel surface defect detection method based on pruning multi-scale feature fusion network
CN120278992A