Industrial surface defect detection method based on ter-yolo and related device

By using the TER-YOLO method and leveraging PGD adversarial training and multi-scale collaborative enhancement modules, the problem of insufficient model robustness in industrial defect detection is solved, achieving high-precision and high-stability detection in complex environments.

CN122391129APending Publication Date: 2026-07-14SUQIAN COLLEGE

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SUQIAN COLLEGE
Filing Date
2026-04-16
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Existing industrial defect detection technologies lack robustness when facing complex industrial scenarios, making it difficult to adapt to complex factors such as changes in lighting, background texture interference, and imaging noise while ensuring detection accuracy, resulting in unstable detection results.

Method used

An industrial surface defect detection method based on TER-YOLO is adopted. Robust pre-trained weights are generated through PGD adversarial training. An edge-guided multi-scale collaborative enhancement module and a parallel multi-branch deep convolutional feature enhancement module are introduced to construct an improved detection model, which enhances the model's ability to resist perturbations and its multi-scale feature fusion capability.

Benefits of technology

It improves the model's detection stability and accuracy in complex environments, enhances its ability to identify minute and multi-scale defects, and strengthens the model's robustness and detection accuracy under perturbation conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122391129A_ABST
    Figure CN122391129A_ABST
Patent Text Reader

Abstract

The application discloses a TER-YOLO industrial surface defect detection method and a related device. The method comprises the following steps: obtaining a to-be-detected image; inputting the to-be-detected image into a TER-YOLO model improved based on a YOLOv11n baseline model to obtain a recognition result. The application has strong effectiveness in robustness, micro-defect detection and multi-scale feature fusion, and provides an effective solution for high-reliability industrial surface defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of visual processing technology, and in particular to a method and related apparatus for detecting industrial surface defects based on TER-YOLO. Background Technology

[0002] In the context of intelligent manufacturing, surface defect detection of industrial products is a crucial link in ensuring product quality consistency and reliability. With the increasing precision and complexity of products and processes, subtle defects (cracks, scratches, short circuits, burrs, etc.) introduced by material differences, parameter fluctuations, and equipment status changes in the production line, if not detected in time, may lead to product functional degradation or even batch failures. Therefore, the industry has placed higher demands on the accuracy, efficiency, and stability of defect detection. With the development of automated inspection technology, machine vision has gradually become a core support means for industrial quality inspection, driving the continuous development of industrial defect detection methods towards intelligence. Currently, vision-based industrial defect detection technologies mainly include methods based on traditional image processing and intelligent detection models based on deep learning. Traditional methods typically rely on manually designed features and detection rules, resulting in limitations such as low detection efficiency, high false positive and false negative rates, and insufficient environmental adaptability. In contrast, deep learning methods can automatically learn multi-level feature representations from a large number of samples, effectively reducing reliance on human experience and exhibiting stronger representation capabilities and higher detection accuracy in scenarios such as complex backgrounds, minute defects, and multi-scale target detection.

[0003] However, when faced with complex factors in real-world industrial scenarios, such as varying lighting, background texture interference, imaging noise, defect scale distribution shifts, and differences in data distribution across scenarios, it is often difficult to maintain stable performance, revealing problems such as insufficient generalization ability and weak anti-interference capability. The fundamental reason lies in the insufficient robustness of the model; it has not yet fully learned the key information that can stably represent the essential characteristics of defects, making it susceptible to external disturbances and scene changes. Therefore, how to systematically improve the robustness of the model while ensuring detection accuracy has become a critical problem that urgently needs to be solved in the current intersection of industrial artificial intelligence and machine vision. Summary of the Invention

[0004] To address the aforementioned technical problems, this invention proposes a TER-YOLO-based industrial surface defect detection method and related device, which demonstrates strong effectiveness in robustness, detection of minute defects, and multi-scale feature fusion, providing an effective solution for highly reliable industrial surface defect detection.

[0005] To achieve the above objectives, the technical solution of the present invention is as follows:

[0006] The TER-YOLO-based industrial surface defect detection method includes the following steps:

[0007] Acquire the image to be detected;

[0008] The image to be detected is input into the TER-YOLO model to obtain the recognition result.

[0009] Preferably, the training process of the TER-YOLO model includes the following:

[0010] PGD ​​adversarial training was performed on the YOLOv11n baseline model to obtain pre-trained weights;

[0011] The last C3k2 module in the backbone network of the YOLOv11n baseline model is replaced with an edge-guided multi-scale collaborative enhancement module. Some C3k2 modules in the neck network of the YOLOv11n baseline model are replaced with edge-guided multi-scale collaborative enhancement modules, and a parallel multi-branch deep convolutional feature enhancement module is introduced to construct an improved detection model. The pre-trained weights are then transferred to the improved detection model for optimized training to obtain the TER-YOLO model.

[0012] Preferably, the processing procedure of the edge-guided multi-scale collaborative enhancement module is as follows:

[0013] Input features of the main branch Perform depthwise convolution and pointwise convolution to obtain an edge intensity map; calculate a dynamic threshold based on a preset fractional q on the pixel distribution of the edge intensity map; normalize and crop the edge intensity map based on the dynamic threshold; and generate a spatial adaptive gating weight map G by performing 3×3 convolution smoothing and Sigmoid activation.

[0014] Input features into the main branch Features are obtained by inputting parallel branches of the Win Transformer with different window sizes. and characteristics Based on the spatial adaptive gating weight map G, the features are... and characteristics Perform dynamic gating fusion to obtain preliminary fusion features. ;

[0015] Utilizing depthwise convolution to input features in the main branch Perform local transformations to obtain intermediate features. Average pooling is performed on the intermediate features to obtain local low-frequency smoothing results, and the intermediate features are then processed. By subtracting the local low-frequency smoothing results, high-frequency features are obtained. ; High-frequency characteristics are analyzed using preset gain coefficients and spatially adaptive gated weighting graph G. To conduct spatial control and integrate initial features Combine to obtain fusion features ;

[0016] For the fusion features Global average pooling is performed to extract the global feature representation of each channel, and the basic channel weights are generated through a channel transformation module consisting of two 1×1 convolutional layers. Global average pooling is performed on the edge intensity map to obtain the global edge response intensity. Based on the edge global response strength Basic channel weights Modulation is performed to obtain edge-aware channel weights. ; the channel weights With fusion features Multiply the main elements to obtain the main branch output. ;

[0017] Output the main branch The features from the bypass branches are concatenated along the channel dimension and then fused through a convolutional layer to obtain the output feature map. .

[0018] Preferably, the Swing Transformer branch includes layer normalization, multi-head self-attention for windows, multi-layer perceptron, and residual connection; or the Swing Transformer branch includes layer normalization, multi-head self-attention for shifted windows, multi-layer perceptron, and residual connection.

[0019] Preferably, the processing procedure of the parallel multi-branch deep convolutional feature enhancement module is as follows:

[0020] The input feature Y is compressed using a 1x1 convolution to obtain the feature. ;

[0021] The compressed features are processed in parallel using two depthwise convolutions with different kernel sizes. Spatial information at different scales is extracted to obtain features. and characteristics ;

[0022] Features and characteristics The concatenation is performed along the channel dimension, and then fusion and channel recovery are performed through a 1×1 convolution to obtain feature X;

[0023] The feature X is residually connected to the input feature Y, and the final result is output through the SiLU activation function.

[0024] Preferably, the method further includes the following steps:

[0025] Obtain a dataset, which includes images and corresponding defect category annotations. Divide the dataset into a training set, a validation set, and a test set according to a preset ratio. Use a single perturbation factor to perturb the test set to obtain several perturbation subsets. The number of images in each perturbation subset is the same as the number of images in the test set.

[0026] The model's performance is evaluated using a test set and several perturbation subsets, with evaluation metrics including precision, recall, and mean precision.

[0027] Preferably, the perturbation single factor includes Gaussian blur, a subset of motion blur, low illumination, and pixel transformation.

[0028] Based on the above, the present invention also discloses a TER-YOLO-based industrial surface defect detection system, comprising:

[0029] The acquisition module is used to acquire the image to be detected;

[0030] The recognition module is used to input the image to be detected into the TER-YOLO model to obtain the recognition result.

[0031] Based on the foregoing, the present invention also discloses a computer device, comprising: a memory for storing a computer program; and a processor for executing the computer program to implement any of the methods described above.

[0032] Based on the above, the present invention also discloses a readable storage medium storing a computer program, which, when executed by a processor, implements any of the methods described above.

[0033] Based on the above technical solution, the beneficial effects of the present invention are:

[0034] (1) In view of the problem that disturbances and non-defect noise in complex imaging environments in industrial sites can easily lead to unstable detection results, this invention constructs a PGD adversarial training mechanism for robust feature learning. By generating adversarial samples to approximate the actual interference distribution, it enhances the anti-disturbance capability of the model feature representation and suppresses false responses caused by non-defect factors, thereby improving the detection stability and robustness in complex environments.

[0035] (2) In view of the problem that the boundaries of small defects are weak and the texture details are easily decayed, the present invention designs an edge-guided multi-scale collaborative enhancement module (EGMCEM), which explicitly integrates edge priors into the dual-branch feature interaction process, guides the collaborative update of semantic features and detail features with edge information, strengthens the expression of defect contours, and improves the integrity and distinguishability of fine-grained texture information.

[0036] (3) In view of the problem that the defect scale span is large and a single receptive field is difficult to take into account both local details and global structure, the present invention constructs a parallel multi-branch deep convolution feature enhancement module (PMDCFEM). Through parallel multi-scale feature extraction and static fusion, the spatial information of different receptive fields is effectively integrated, and the model’s ability to cover multi-scale defects is improved while controlling computational overhead.

[0037] (4) In view of the problem that it is difficult to balance detection accuracy and robustness, this invention proposes a collaborative optimization paradigm of first strengthening robustness and then enhancing accuracy. It decouples the implementation of adversarial robust pre-training and high-precision structural optimization. First, robust feature learning is completed on the basic model, and then the obtained weights are transferred to the high-precision model for joint optimization, thereby improving the stability and reliability of the model under complex perturbation conditions while improving detection accuracy.

[0038] Experimental results show that the proposed method achieves good overall detection performance on the PKU-Market-PCB industrial surface defect dataset, demonstrating strong effectiveness in robustness, detection of small defects, and multi-scale feature fusion, providing an effective solution for high-reliability industrial surface defect detection. Attached Figure Description

[0039] Figure 1 This is a schematic diagram of a TER-YOLO-based industrial surface defect detection method in one embodiment;

[0040] Figure 2 This is a schematic diagram of the structure of the TER-YOLO model in one embodiment;

[0041] Figure 3 This is a schematic diagram of PGD adversarial training in one embodiment;

[0042] Figure 4 This is a schematic diagram of the structure of a Swing transformer branch in one embodiment;

[0043] Figure 5 This is a schematic diagram of the edge-guided multi-scale collaborative enhancement module in one embodiment;

[0044] Figure 6 This is a schematic diagram of the structure of a parallel multi-branch deep convolutional feature enhancement module in one embodiment;

[0045] Figure 7 This is a schematic diagram of the structure of the DWconv module in one embodiment;

[0046] Figure 8 This is a schematic diagram of a self-built interference test dataset in one embodiment;

[0047] Figure 9 This is a graph showing the changes in various metrics of the TER-YOLO model and the YOLOv11n baseline model during the training phase in one embodiment.

[0048] Figure 10 This is a visualization analysis chart comparing the TER-YOLO model with the YOLOv11n baseline model in one embodiment. Detailed Implementation

[0049] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0050] like Figure 1 As shown, this embodiment provides a TER-YOLO-based method for detecting industrial surface defects, including the following steps:

[0051] Step 1: Obtain the image to be detected;

[0052] Step 2: Input the image to be detected into the TER-YOLO model to obtain the recognition result.

[0053] In this embodiment, to balance the requirements of detection accuracy and robustness in complex environments during industrial surface defect detection, this invention proposes a phased collaborative optimization framework, TER-YOLO. First, PGD adversarial training is implemented on the standard YOLOv11n baseline model to learn robust feature representations with strong anti-interference capabilities and obtain corresponding pre-trained weights. Then, high-precision enhancement modules (Edge-Guided Multi-Scale Collaborative Enhancement Module EGMCEM and Parallel Multi-Branch Deep Convolutional Feature Enhancement Module PMDCFEM) are introduced on the YOLOv11n baseline structure to construct an improved detection model. The aforementioned robust pre-trained weights are then transferred to this model for optimization training, thereby achieving a synergistic improvement in detection accuracy and robustness, resulting in the TER-YOLO model. (See [link to relevant documentation]). Figure 2 .

[0054] 1.1 Robust Pre-training Method for PGD-based Adversarial Training

[0055] In industrial surface defect detection, images are easily affected by noise disturbances, texture changes, and imaging environment fluctuations, leading to problems such as decreased confidence, location shifts, and even missed detections in the detection model. Traditional training methods mainly optimize based on clean samples, and the model's adaptability to perturbation inputs is limited, making it difficult to meet the robust detection requirements in complex industrial scenarios. To improve the detection stability of the YOLOv11n baseline model under perturbation conditions, this invention introduces an adversarial training strategy based on Projected Gradient Descent (PGD). Without changing the original network structure, adversarial examples are constructed and joint loss is optimized to improve the model's adaptability to noise interference, environmental changes, and distribution shifts, thereby obtaining robust pre-trained weights with strong anti-interference capabilities. The optimization process can be represented as the following minimum-maximum optimization problem:

[0056]

[0057] in Here, (x, y) represents the model parameters, and (x, y) represents the input image and the ground truth annotation set, respectively. L is the loss function. For the applied disturbance, To disturb space, This represents the upper limit of the disturbance.

[0058] In the adversarial example generation stage, the input images are first normalized to the interval [0, 1]. Let the normalized input be... Then, the disturbance is randomly initialized within the disturbance range. And constrain it to a legal pixel space, represented as:

[0059]

[0060]

[0061] In the formula, This represents the maximum disturbance amplitude.

[0062] Based on this, a multi-step PGD iteration is used to continuously update the perturbation, causing it to change in the direction of increasing loss. The update process is as follows:

[0063]

[0064] in, For single-step update step size, Π is the projection operation used to ensure that the disturbance always meets the amplitude constraint.

[0065] Finally, the adversarial examples were obtained:

[0066]

[0067] Where T is the number of PGD iterations. This serves as the input for the adversarial training branch. Compared to single-step perturbation, multi-step PGD can generate stronger adversarial examples, thus more fully exploiting the model's vulnerability under perturbation conditions.

[0068] Regarding loss construction, we first use clean samples for forward propagation to calculate the original detection loss:

[0069]

[0070] Then, the generated adversarial examples are input into the model to calculate the adversarial example loss:

[0071]

[0072] in, Let represent the YOLOv11 detection model, and y represent the set of ground truth annotations, i.e., the supervision information for the current batch. This invention directly calls the native loss function within YOLOv11n for calculation; therefore, the generation and optimization process of adversarial examples always revolves around the detection task itself.

[0073] To balance clean sample detection capability with robustness under perturbation conditions, this invention employs a weighted summation method to construct the total loss function:

[0074]

[0075] In the formula, λ is the adversarial loss weighting coefficient.

[0076] This design primarily utilizes clean sample supervision while introducing a certain proportion of adversarial loss constraints. This allows the model to learn features from both standard and perturbed samples during parameter updates, thereby improving overall detection robustness. In implementation, a custom trainer, AdvDetectionTrainer, is built based on the Detection Trainer in the Ultralytics framework. The training_step function is rewritten to integrate clean sample forward propagation, PGD adversarial example generation, adversarial example loss calculation, and joint loss backward update into a unified training process. The training process can be summarized as follows:

[0077]

[0078]

[0079]

[0080]

[0081] Where θ is the model parameter and η is the learning rate.

[0082] Furthermore, this invention employs an automatic mixed-precision training strategy during the parameter update phase, using a gradient scaler to complete loss backpropagation and optimizer updates, thereby ensuring the numerical stability of the training process.

[0083] In summary, see Figure 3 By introducing a PGD adversarial training mechanism into the training process of the standard YOLOv11n model, explicit modeling of input perturbations is achieved. This method does not change the original detection network structure, only adding adversarial example generation and joint loss optimization processes during the training phase. It has advantages such as simple implementation, strong compatibility, and easy embedding into existing detection frameworks. This "adversarial perturbation generation-joint loss optimization" training approach effectively enhances the model's stability in industrial surface defect detection scenarios. Furthermore, the model parameters obtained through adversarial training will serve as robust pre-training weights for initializing subsequent high-precision improved models, thus providing a more stable feature representation foundation for the phased collaborative optimization of accuracy and robustness.

[0084] 1.2 Network Architecture Improvement

[0085] YOLOv11n, as a target detection model that balances detection accuracy and real-time performance, demonstrates strong performance advantages in general target detection tasks. However, in industrial surface defect detection scenarios, due to the characteristics of defects such as small scale, complex shape, unclear boundaries, and strong background interference, standard YOLOv11n still has certain shortcomings in feature extraction and multi-scale information fusion.

[0086] Specifically, while shallow features contain rich spatial details, their semantic expressive power is relatively limited; deep features, although possessing strong semantic representation capabilities, are prone to losing fine-grained texture and edge information during layer-by-layer downsampling, thus affecting the model's ability to identify minor and weakly textured defects. Furthermore, in the face of noise disturbances and texture confusion in complex industrial environments, the standard model's feature response capability for key regions still needs further enhancement.

[0087] To address the aforementioned issues, a novel defect detection algorithm is developed based on the standard YOLOv11n architecture. This algorithm introduces an edge-guided multi-scale collaborative enhancement module and a parallel multi-branch deep convolution feature enhancement module. The former primarily enhances the model's ability to perceive multi-scale defects, edge details, and high-frequency texture information by guiding the dynamic fusion of features at different scales through edge priors, thereby improving the model's representation of minute defects and defects with blurred boundaries. The latter, based on the parallel multi-branch deep convolution structure, extracts complementary features from different receptive fields and different branch paths, further enhancing the expressive power of deep features and improving the model's sensitivity to complex defect textures and local structural changes.

[0088] 1.2.1 Edge-guided multi-scale collaborative enhancement module

[0089] Traditional single-path Transformers often struggle to simultaneously achieve both broad-ranging contextual semantic modeling and local detail preservation in visual tasks. On the one hand, broader feature interactions enhance structural information representation; on the other hand, fine-grained structural and textural information relies on high spatial resolution feature representations. To address this contradiction, the SwinTransformer introduces window attention and shifted window mechanisms, enabling local modeling and cross-window information interaction within a computationally controllable framework. Specifically, its basic unit constrains self-attention to computation within a local region through window partitioning, and promotes information flow between adjacent windows by alternating between window multi-head self-attention (W-MSA) and shifted window multi-head self-attention (SW-MSA), thus balancing computational efficiency and feature representation capabilities.

[0090] Within the aforementioned window attention modeling framework, the Swin Transformer further constructs its basic computational unit around multi-head window self-attention. Specifically, a Swin Transformer block consists of Layer Normalization (LN), window multi-head self-attention (W-MSA), or shifted window multi-head self-attention (SW-MSA), a multilayer perceptron (MLP), and residual connections. Residual connections can improve the gradient propagation process to some extent, enhancing the training stability of deep networks. The structure of the Swin Transformer is as follows: Figure 4 As shown.

[0091] It should be noted that although the window attention mechanism can effectively model feature relationships within a local region, attention computation within the same branch is still limited by a fixed window size. This may lead to limited representation in industrial surface defect detection scenarios with large defect scales and complex morphological changes: a single window scale cannot simultaneously take into account large-scale structural information and minute defect details. To further enhance the model's adaptability to defects of different scales, this invention introduces a multi-branch parallel structure on the C3 structure main branch to construct a multi-scale attention mechanism, that is, setting Swing Transformer branches with different window sizes to extract complementary features. Among them, the large window branch models the contextual relationships within a wider neighborhood and the structural features of larger-scale defects through a larger local window range; the small window branch strengthens the ability to express local patterns and minute defect details with a finer-grained spatial division. This parallel multi-scale attention strategy can obtain richer and more complementary feature representations at different scale levels, providing a more powerful representation foundation for the subsequent edge-guided feature fusion module.

[0092] Let the characteristics after C3 main branch preprocessing be: The two-branch processing procedure can then be represented as:

[0093]

[0094]

[0095] in and These represent window sizes of 1 and 2 respectively. and ( The Swing Transformer blocks, where the former carries a larger local context information and the latter preserves finer local details, are used for subsequent use of EdgeMap to extract information from the local context. The generated edge map E provides a complementary source of features for edge-guided fusion.

[0096] Simple multi-branch feature concatenation or addition is a static fusion method, which cannot adaptively adjust the importance of different branches according to image content. To achieve dynamic fusion of multi-scale features, this invention utilizes a lightweight EdgeMap convolution module to directly regress the edge intensity map E from the main features, serving as a spatial weight prior for subsequent fusion. This module consists of a concatenation of depthwise convolution (DWConv) and pointwise convolution (PWConv), where depthwise convolution is used to extract local edge responses, and pointwise convolution is used to compress feature channels into single-channel representations. The specific processing flow is as follows:

[0097]

[0098] in Using the Sigmoid activation function, the output edge intensity map is... , It reflects the strength of the edge response at each spatial location in the input feature map. The closer the value is to 1, the stronger the edge response at that location. The closer it is to 0, the smoother the edge response at that location. This edge prior provides important spatial guidance information for subsequent dynamic fusion.

[0099] Subsequently, the EdgeGuidedMix component uses this as a basis to implement dynamic gating fusion. First, it calculates the dynamic threshold by taking fractional q of the pixel distribution in the edge map E. This serves as the benchmark for subsequent gating:

[0100]

[0101] Where q is a preset quantile, used to characterize the threshold standard of regions with strong edge response. Based on this, the edge map is normalized, cropped, and then smoothed by 3×3 convolution and activated by Sigmoid to generate a spatially adaptive gated weight map G.

[0102]

[0103] This gating mechanism enables the model to adaptively adjust the fusion ratio of the two branches at different spatial locations based on the strength of the edge response: in regions with strong edge responses, it tends to retain fine-grained details from the small branch; in relatively smooth regions, it relies more on the larger-scale contextual features from the base branch. This yields preliminary fusion features. The fusion process can be represented as:

[0104]

[0105] Here, ⊙ represents element-wise multiplication. This mechanism enables the model to adaptively integrate multi-scale features based on image content, thereby alleviating the conflict between detail representation and context modeling.

[0106] Furthermore, during feature transformation in deep networks, high-frequency detail information is easily smoothed, leading to a weakening of responses to minor defects. Moreover, in the dual-branch fusion structure, the fused features mainly originate from the transformation results of different branches, and some low-level detail information from the original input is not directly preserved. Therefore, a parallel detail compensation path is designed. This path bypasses the main feature transformation layer and directly extracts details from the backbone features. High-frequency information is extracted and injected into the fusion result in a gating manner.

[0107] First, depthwise convolution (DWConv) is used to process the input features. Perform local transformations to obtain intermediate features. :

[0108]

[0109] Subsequently, to highlight the high-frequency components, the local low-frequency smoothing results were subtracted to obtain the high-frequency features. ,Right now:

[0110]

[0111] This operation enhances detail response by highlighting high-frequency variations by suppressing local smoothing components. To avoid introducing unnecessary noise in smooth regions, the high-frequency details are spatially modulated using the gating map G generated in the aforementioned fusion stage, enhancing detail components only in regions with strong edge responses to obtain fused features. The formula is as follows:

[0112]

[0113] Here, λ is the gain coefficient, used to control the intensity of high-frequency compensation. This mechanism does not uniformly enhance all regions, but rather uses the edge prior G to selectively compensate for details, thereby enhancing the response of small defects while suppressing the amplification of background noise.

[0114] Furthermore, to further enhance the model's ability to perceive complex image structures, this invention introduces an edge-aware channel recalibration mechanism (EdgeSEE). The standard SE module generates channel weights through global average pooling, but lacks explicit utilization of prior edge information. Therefore, this invention incorporates the global response of the edge map into the channel weight modulation process. Let the input features be... The edge graph is E, and its calculation process is as follows:

[0115] First, global average pooling is performed on the input feature map to extract the global feature representation for each channel. The feature map of each channel is compressed into a scalar, representing the overall feature intensity of that channel:

[0116]

[0117] Then, the basic channel weights are generated through a channel transformation module consisting of two 1×1 convolution layers. :

[0118]

[0119] in and For the parameters of two convolutional layers, Let r be the SiLU activation function and r be the compression ratio. The sigmoid function is used to obtain w, which is the weight of each channel, representing the importance of that channel in the global features.

[0120] Meanwhile, global average pooling AvgPool(E) is performed on the edge graph E to obtain the global response intensity of the edge:

[0121]

[0122] Based on this, the channel weights are modulated using the edge global response intensity to obtain the edge-aware channel weights:

[0123]

[0124] Where γ is the edge gain coefficient. It represents the factor by which the channel weights are enhanced in the edge region. When the overall edge response is strong, the channel weights will adaptively increase as e increases. Its amplification factor is between 1 and γ, thereby improving the model's attention to edge and texture-related channels.

[0125] Finally, the adjusted channel weights Applying this to the fused feature map yields the enhanced main branch output:

[0126]

[0127] It should be noted that the designed EGMCEM module not only includes the aforementioned enhanced main branch, but also retains the skip connection (bypass) branch characteristics of the C3 structure. Let the output characteristic map of the bypass branch be... The enhanced output feature map of the main branch is The two are then concatenated along the channel dimension, and feature fusion is performed through a 1×1 convolutional layer to finally obtain the output feature map of the module. :

[0128]

[0129] This design enhances the ability to express details and represent multiple scales in the main branch while retaining the basic feature information in the side branches, thereby further improving the overall feature integration capability of the module.

[0130] In summary, this module constructs a collaborative enhancement structure consisting of multi-scale window attention, edge-guided fusion, high-frequency detail compensation, and edge-aware channel recalibration, which is then fused with the C3 bypass branch to form a complete EGMCEM module. Its technical chain comprises five steps: multi-scale extraction, edge-guided fusion, high-frequency detail compensation, channel recalibration, and bypass fusion output. It systematically enhances the model's ability to represent the features of minute industrial defects from four levels: spatial adaptive fusion, detail compensation, channel selection, and structural feature integration. The structure of the edge-guided multi-scale collaborative enhancement module is as follows: Figure 5 As shown.

[0131] 1.2.2 Parallel Multi-Branch Deep Convolution Feature Enhancement Module

[0132] In industrial surface defect detection, the scale of the targets varies. Traditional single-path convolutional networks typically use fixed-size convolutional kernels, resulting in a single receptive field. This makes it difficult to simultaneously capture fine-grained local details and broader contextual information, thus limiting the model's ability to represent multi-scale defects. To enhance the network's ability to extract features from defects of different scales, this invention designs a lightweight feature enhancement module based on parallel depthwise convolution and feature concatenation. This module extracts spatial features under different receptive fields through parallel branches and enhances the output feature representation using an efficient static fusion strategy. Multi-scale feature generation stage: First, a 1x1 convolution is used to compress the input feature Y channels to reduce the computational overhead of subsequent parallel branches and extract more compact intermediate features, resulting in:

[0133]

[0134] Subsequently, two depthwise convolutions (DWConv) with different kernel sizes were used; see [link to depthwise convolution structure] for details. Figure 7 Parallel processing of compressed features to extract spatial information at different scales.

[0135]

[0136] in, Branches focus more on local details and small-scale defects. This is used to model contextual information over a larger domain to enhance the network's adaptability to targets at different scales.

[0137] In the feature fusion stage, the dual-branch outputs are concatenated along the channel dimension to preserve multi-scale feature information, and then fused and channel restored using a 1×1 convolution.

[0138]

[0139] This 1×1 convolution remaps the concatenated features back to the input channel dimension, while effectively integrating features from different receptive fields, thereby enhancing multi-scale expressive power while maintaining computational efficiency.

[0140] Finally, the fused feature X is residually connected to the original input feature Y, and the final result is output through the SiLU activation function:

[0141]

[0142] Residual connections help preserve original feature information and improve the gradient propagation process, thereby enhancing the module's training stability. Overall, this module achieves effective integration of features from different receptive field spaces through a static structure of "parallel extraction-static fusion-residual enhancement," improving the model's ability to represent multi-scale defect targets with relatively low overhead. The structure of the parallel multi-branch deep convolutional feature enhancement module is as follows: Figure 6 As shown.

[0143] 1.3 Robust pre-training driven phased collaborative optimization strategy

[0144] To improve the robustness of industrial surface defect detection models in complex environments, this invention first attempts to directly superimpose PGD adversarial training after the improved model has been trained. Theoretically, adversarial training, by introducing perturbation samples during the training phase, can enhance the model's adaptability to changes in input distribution, thus potentially improving the detection stability of the improved model in complex interference scenarios. However, experimental results show that this strategy did not bring the expected performance gain; instead, it caused a decrease in detection performance in most test scenarios. This indicates that for complex improved models that incorporate multiple feature enhancement mechanisms, feature optimization for detection accuracy and robustness optimization for perturbation stability are not simply additive but may have certain conflicting objectives. To verify this phenomenon and analyze its causes, this invention conducts comparative experiments on the standard model, the improved model, and the improved model after directly superimposing PGD adversarial training. The results are shown in Tables 1-3.

[0145] As shown in Tables 1 and 2, the model performance was significantly improved after introducing the enhancement module on top of the standard YOLOv11n. On the original test set, mAP@0.5 increased from 90.3% to 93.9%; on the Gaussian blur and pixel variation test sets, mAP@0.5 increased to 94.5% and 94.4%, respectively. This indicates that the improved model can more effectively represent discriminative features in small defects, multi-scale defects, and complex backgrounds, demonstrating that the introduced enhancement module has good feature extraction and defect recognition capabilities under conventional supervised training conditions. However, further comparison of Tables 2 and 3 reveals that the model performance degraded when PGD adversarial training was directly implemented on the improved model. For example, on the original test set, Recall decreased from 89.4% to 84.7%, and mAP@0.5 decreased from 93.9% to 89.7%; on the Gaussian blur and motion blur test sets, mAP@0.5 decreased to 90.1% and 86.6%, respectively. The above results indicate that while adversarial training improves the model's ability to suppress perturbations, it also weakens the efficiency of the improved module in utilizing local textures, edge details, and fine-grained defect features to some extent. In other words, the performance advantage of the improved model largely depends on the full exploitation of highly sensitive detail features, while PGD adversarial training emphasizes a smooth response to input perturbations, which to some extent compresses the expression space of fine-grained discriminative features, leading to a trade-off between detection accuracy and robustness. Therefore, directly adding adversarial training to complex improved models may not necessarily achieve synergistic gains and may even undermine the performance advantages brought by the original feature enhancement strategy.

[0146] Table 1 Performance Comparison of YOLOv11 Baseline Models

[0147]

[0148] Table 2 Performance Comparison of Improved Models

[0149]

[0150] Table 3 Performance Comparison of Improved Models in Direct Adversarial Training

[0151]

[0152] To address the aforementioned issues, this invention proposes a decoupled robust transfer framework. First, PGD adversarial training is performed on the standard YOLOv11n baseline model to obtain robust pre-trained weights. Then, an enhancement module is introduced to construct an improved model based on the standard YOLOv11n structure, and the robust pre-trained weights are transferred to the shared structural part as initial parameters. Finally, the improved model is fine-tuned under supervision using clean samples. This strategy separates the robust learning and structural enhancement processes in stages, effectively avoiding direct interference from adversarial training on the fine-grained feature representation capabilities of the improved model, while retaining the perturbation adaptability advantages brought by robust pre-training.

[0153] Table 4 shows that after adopting the aforementioned phased collaborative optimization strategy, the model's performance on each test set is further improved. Specifically, the mAP@0.5 on the original test set, the Gaussian blurred test set, and the low-light test set reaches 94.4%, 95.4%, and 81.3%, respectively. The results indicate that the proposed decoupled robust transfer framework can effectively inherit the robust representation obtained by the baseline model through adversarial training while fully leveraging the feature modeling capabilities of the enhancement module, thus achieving a balance between detection accuracy and perturbation adaptability. Compared to directly superimposing PGD adversarial training on the improved model, this method can more effectively alleviate the conflict between accuracy optimization and robustness optimization, providing a feasible path for high-precision and high-robustness detection in complex industrial surface defect scenarios.

[0154] Table 4 Performance Comparison of Phased Collaborative Optimization

[0155]

[0156] 2. Experimental Results and Analysis

[0157] 2.1 Dataset

[0158] The publicly available PCB defect detection benchmark dataset PKU-Market-PCB was used to train and evaluate the model. This dataset, collected from actual PCB production environments, covers six common defect types: vias, rodent bites, open circuits, short circuits, stray wires, and copper spatter. The original dataset contains 1386 images. To ensure complete annotation and data balance, this study selected 693 bare board defect images suitable for the defect detection task, containing 2953 annotated instances. Each image corresponds to only one defect category, and the instance distribution for each defect type is shown in Table 3. The dataset was divided into training, validation, and test sets in an 8:1:1 ratio.

[0159] Table 5. Distribution of Dataset Instances

[0160]

[0161] 2.2 Self-built interference test dataset

[0162] To systematically evaluate the robustness of the model in real industrial environments, this invention constructs a single-factor perturbation evaluation protocol based on the PKU-Market-PCB benchmark test set. Specifically, based on the original test set (maintaining the original sample size and label distribution), four single perturbation subsets are synthesized through systematic parameter control. See [link to relevant documentation]. Figure 8 The dataset includes a Gaussian blur subset (simulating optical defocus and lens aberration), a motion blur subset (simulating production line mechanical vibration and camera movement), a low-light subset (simulating sudden changes in light source and extreme backlighting environments), and a pixel transformation subset (simulating sensor noise and quantization error, introduced). Each perturbation subset is constructed independently and maintains the same number of images as the original test set to ensure fairness in single-variable control and evaluation.

[0163] This rigorously controlled single-factor experimental design endows the evaluation results with high interpretability, enabling precise attribution of model performance degradation to specific physical degradation sources, thereby identifying the algorithm's vulnerabilities under specific industrial conditions. This benchmark provides quantifiable and actionable diagnostic criteria for subsequent targeted optimizations (such as enhancement strategies for low-light conditions or deblurring preprocessing for motion blur), driving industrial vision inspection models to substantially move from a "average accuracy priority" paradigm in laboratory environments to a "reliability assurance" paradigm in complex industrial settings. Specific visual samples of various perturbations are provided. Figure 7 As shown.

[0164] 2.3 Experimental Environment and Parameter Adjustment

[0165] This study's experimental environment was based on the Windows 10 operating system, and the PyTorch framework was used for the development and training of deep learning models. During model training, input images were uniformly scaled and normalized to a resolution of 640×640, and the batch size was set to 8 to avoid memory overflow. The optimizer used was stochastic gradient descent, with an initial learning rate of 0.01, a momentum factor of 0.937, and a weight decay coefficient of 0.0005. All models were trained for 300 epochs to ensure sufficient convergence.

[0166] 2.4 Evaluation Indicators

[0167] In 2D object detection tasks, the Intersection over Union (IoU) ratio is a core metric for measuring the degree of overlap between the predicted bounding box and the ground truth bounding box. A higher IoU value indicates that the predicted location is closer to the actual target. A threshold of 0.5 is typically used as the standard for determining whether the detection is successful.

[0168] To comprehensively evaluate the performance of detection models, precision and recall are commonly used metrics. Precision refers to the proportion of truly positive samples among all detection results judged as positive by the model, reflecting the accuracy of the model's predictions. Recall, on the other hand, represents the proportion of truly positive samples correctly detected by the model, reflecting the model's coverage of the target. The formulas for calculating both are shown below:

[0169]

[0170]

[0171] Wherein, TP (true positive) represents a sample that is correctly predicted as a positive example; FP (false positive) represents a sample that is incorrectly predicted as a positive example; and FN (false negative) represents a sample that is incorrectly predicted as a negative example.

[0172] Mean precision (AP) is a core metric for comprehensively evaluating the performance of object detection models. It is defined as follows: Mean precision (AP) is the area enclosed by the precision-recall curve and the coordinate axis. This metric effectively balances precision and recall. The mean AP is calculated as the average AP across all classes, using the following formula:

[0173]

[0174]

[0175] Where N is the total number of categories, which is 6 in this invention. This represents the average accuracy for the i-th class. A higher mAP value indicates better overall detection performance across all classes, and therefore this metric is often used as the final evaluation standard for model performance.

[0176] 2.5 Ablation Experiment

[0177] To systematically evaluate the contributions of each component proposed in this invention and verify the effectiveness of the core training paradigm, this section designs rigorous ablation experiments. All experiments are conducted on the same PKU-Market-PCB dataset and perturbation test set, and strictly adhere to the same training settings to ensure the fairness and comparability of the results. A total of eight comparative experiments are set up to progressively decompose and quantify the utility of each improvement point, as detailed below:

[0178] Using the original YOLO11n model as a performance benchmark, we successively introduced multi-environment PGD adversarial training (A), the EGMCEM module (B), and the PMDCFEM module (C) for basic improvements, and verified the effectiveness of each module. Then, using the "decoupled robust transfer" paradigm proposed at the core of this invention, we combined the pre-trained weights PA obtained from adversarial training with EGMCEM and PMDCFEM respectively to construct PA+B and PA+C fusion models. In addition, we further integrated the EGMCEM and PMDCFEM modules to propose a hybrid attention model (B+C). Finally, we transferred the pre-trained weights PA to the hybrid model and fine-tuned it on a clean dataset. Through the above experiments, we further verified the effectiveness of each module and the collaborative optimization ability between modules, and obtained the final TER-YOLO model, as shown below.

[0179] 2.5.1 Ablation experiments on the original test set

[0180] The performance of each module in the original test set environment is shown in Table 6. After independently introducing module B (edge-guided dual-branch collaborative enhancement module), mAP50 significantly improved from 90.3% to 93.0% of the baseline, and Recall improved by 0.9 percentage points. This verifies the effectiveness of the dual-branch structure (window base captures global semantics, window small focuses local details) combined with EdgeGuidedMix dynamic gating fusion: the spatial adaptive mechanism guided by the edge map E can dynamically weigh the contributions of the two branches according to the image content, enhance detailed features in edge regions, and retain contextual features in flat regions, thereby systematically improving the defect representation ability. Independently introducing module C (parallel multi-branch deep convolution) also performed well, with mAP50 reaching 92.7%, and the mAP50-95 index (49.7%) was better than module B, indicating that the parallel deep convolution, through the "parallel extraction-static fusion" strategy, effectively integrated multi-scale receptive fields with low computational cost, and demonstrated outstanding scale adaptability to defects of different sizes.

[0181] In contrast, while independently introducing adversarial training module A improved precision by 0.7% (93.9% vs 93.2%), it decreased recall by 2.2%, mAP50-95 by 3.0%, and FPS dropped significantly to 72.5. This indicates that while standard adversarial training enhances robustness, it sacrifices some detail sensitivity in pursuit of perturbation invariance, leading to decreased localization accuracy and increased inference overhead.

[0182] When using a decoupled robust transfer paradigm for module combination, significant complementary gains were observed. The PA+B combination, while maintaining the structural advantages of module B, achieved simultaneous improvements in Precision (94.5%) and mAP50 (94.1%) through adversarial transfer of pre-trained weights. This indicates that the robust feature representation imparted by adversarial training is synergistic with the hierarchical feature extraction of the two-branch Swin—adversarial pre-training forces the model to learn the essential features of defects rather than surface statistical properties, while the EdgeGuidedMix mechanism further strengthens these highly discriminative edge region representations in the feature space while suppressing non-edge noise. The PA+C combination achieved a significant improvement in Precision (97.1%), verifying the compatibility of lightweight multi-branch convolution and adversarial pre-trained weights in terms of computational efficiency and feature discriminability.

[0183] It is noteworthy that the B+C hybrid model, without introducing adversarial pre-trained weights, achieved a precision of 97.3% and an mAP50-95 of 50.8%. This indicates that the two modules have a dynamic-static complementary mechanism at the feature extraction level: Module B achieves pixel-level adaptive feature selection (dynamic) through spatially gated weights generated by EdgeMap, while Module C achieves cross-scale static feature fusion (static) through channel concatenation and 1x1 convolution. Both enhance feature representation from the dimensions of "spatial importance" and "scale receptive field diversity," respectively, forming a multi-granularity defect representation system.

[0184] Ultimately, the TER-YOLO model (PA+B+C) achieved the best balance between precision (94.8%) and recall (92.0%), with an mAP50 of 94.4%. Although the absolute accuracy was slightly lower than the B+C combination, considering the additional computational resource requirements of the detail compensation path (extraction and injection of high-frequency details H) and the EdgeSEE channel recalibration mechanism in module B, PA+B+C achieved a synergistic optimal balance between robustness and accuracy through decoupling and migration.

[0185] Table 6 Ablation Experiments on the Original Test Set

[0186]

[0187] 2.5.2 Ablation Experiments on the Perturbation Test Set

[0188] To verify the robustness of each module in complex industrial environments, this section conducts ablation experiments under four typical perturbation scenarios: Gaussian blur, pixel variation, low light, and motion blur. The results are shown in Tables 7-10. The robustness contributions of each module exhibit differentiated characteristics, and the synergistic effect is particularly significant in harsh environments.

[0189] The baseline model alone exhibits a significant performance drop in low-light environments (mAP50 is only 68.0%), but after introducing module B, mAP50 recovers to 71.9%. This is attributed to the EdgeGuidedMix mechanism's ability to identify defect boundaries through edge maps E even in low-contrast environments, and the invariance of "local gradient calculation" (obtaining high-frequency details H through the difference between DWConv and AvgPool) in the detail compensation pathway to illumination changes. Module C performs exceptionally well in Gaussian blur scenes, increasing mAP50 to 93.3%, indicating that the multi-scale receptive field of parallel multi-branch deep convolution has inherent resistance to blur degradation—large branches preserve the coarse-grained structure after blurring, while small branches capture the remaining fine-grained texture.

[0190] When using a decoupled transfer paradigm to combine modules, the model exhibits hierarchical synergistic characteristics. The PA+B combination demonstrates a significant synergistic effect in motion-fuzzy environments: although introducing A alone leads to a performance decrease (mAP50 88.0%), when PA is combined with B as a pre-training weight, mAP50 recovers to 92.0%, and Recall is significantly improved to 90.7%. This indicates that the shifted window mechanism of the two-branch Swin can effectively alleviate the feature failure problem of adversarial training in dynamic-fuzzy scenarios—adversarial pre-training provides basic perturbation invariance, while EdgeGuidedMix accurately locates defect regions through edge prior G, avoiding edge drift caused by motion blur. The PA+C combination achieves suboptimal performance (mAP50 77.0%) in low-light environments, verifying that the combination of lightweight multi-scale convolution and adversarial pre-training can maintain the stability of multi-scale feature extraction under low signal-to-noise ratio conditions.

[0191] TER-YOLO (PA+B+C) achieved or nearly achieved optimal performance in all perturbation scenarios. Particularly in the most challenging Low-light test, this model significantly outperformed other configurations, achieving an mAP50 of 81.3%, an improvement of 8.3 percentage points over the B+C combination. This cross-module synergy can be explained by the following mechanisms: Adversarial pre-training (PA) endows the model with basic immunity to illumination perturbations; the two-branch Swing (B) uses EdgeSEE channel recalibration—dynamically enhancing edge-related channel weights using the edge global response e—to strengthen defect edge responses under low light; and parallel multi-branch convolution (C) ensures that defect features at different scales can still be captured even in low light conditions through complementary receptive fields. These three components form a three-tiered defense system of "robust foundation - edge enhancement - scale coverage".

[0192] In motion-blurred scenarios, PA+B+C also achieved the best mAP50 (93.2%), demonstrating the effective transfer of multi-environment adversarial pre-trained weights to the hybrid architecture: adversarial training optimizes the inter-class margin of the feature space, EdgeGuidedMix optimizes the spatial distribution of the feature space, and multi-branch convolution optimizes the scale coverage of the feature space, which together endow the model with strong robustness to complex perturbations.

[0193] Table 7 Ablation Experiments on Gaussian Blur Test Set

[0194]

[0195] Table 8. Ablation Experiments on Pixel Change Test Set

[0196]

[0197] Table 9 Ablation Experiments on Low-Light Test Set

[0198]

[0199] Table 10 Ablation Experiments on Motion Fuzzy Test Set

[0200]

[0201] In summary, the ablation experiments verified that all three modules proposed in this invention can effectively improve the model's detection accuracy. Specifically, the edge-guided collaborative enhancement module improves the accuracy of defect detection by strengthening the learning of defect edge features, while reducing the false detection rate, systematically enhancing the model's ability to represent minor industrial defects. The parallel multi-branch deep convolutional feature enhancement module achieves multi-scale feature extraction and fusion with low computational cost, promotes the complementary integration of features from different receptive fields, effectively enriches the scale diversity of output features, and thus improves the model's recognition performance for defects of different sizes. Furthermore, the maximum loss-based adversarial training robustness enhancement module introduces targeted perturbations during training, forcing the model to learn the ability to cope with difficult samples, thereby enhancing the model's discriminative power for essential defect features, suppressing the influence of environmental interference factors, and significantly improving the model's robustness and stability.

[0202] 2.6 Comparative Experiment

[0203] To verify the effectiveness of the TER-YOLO model, this paper selects YOLOv5, YOLOv8, YOLOv9t, YOLOv10n, YOLOv11n, and YOLOv12 as comparison models on the PKU-Market-PCB dataset. All models were trained and tested using the same data partitioning, input size, number of training epochs, and hardware environment. Considering the differences in training strategies among different YOLO architectures, other training parameters were set according to the official implementations or recommended configurations of each model to ensure the reasonableness and fairness of the comparison. Experimental results are shown in Tables 11-16.

[0204] Table 11 Comparison Experiments on the Original Test Set

[0205]

[0206] Table 12 Comparison Experiment of Gaussian Blur Test Set

[0207]

[0208] Table 13 Comparison Experiment of Compression Distortion Test Set

[0209]

[0210] Table 14 Comparison Experiment of Low Light Illumination Test Set

[0211]

[0212] Table 15 Comparison Experiments on Motion Fuzzy Test Sets

[0213]

[0214] The experimental results across various test sets show that TER-YOLO exhibits strong detection capabilities on the original test set, Gaussian blur test set, compression distortion test set, low-light test set, and motion blur test set. Table 16 shows that TER-YOLO's average precision, recall, mAP50, and mAP50-95 reached 95.06%, 87.56%, 91.82%, and 47.36%, respectively, all of which are the best results among all compared models. Compared to YOLOv9t, which has the second-best overall accuracy, TER-YOLO improves by 0.96, 2.70, 2.74, and 1.64 percentage points, respectively, indicating that this model has better overall detection performance in complex degraded scenes.

[0215] Table 16 Comparison of experimental averages for each test set

[0216]

[0217] In specific scenarios, TER-YOLO achieved mAP50 values ​​of 94.4%, 95.4%, 94.8%, 81.3%, and 93.2% on the original test set, Gaussian blur test set, compression distortion test set, low-light test set, and motion blur test set, respectively, all of which were the highest values ​​among all comparison models. In the most challenging low-light test set, all comparison models showed significant performance degradation; for example, the mAP50 values ​​of YOLOv12, YOLOv5, and YOLOv9t dropped to 58.0%, 66.0%, and 74.6%, respectively. TER-YOLO, however, still achieved an mAP50 of 81.3% and an mAP50-95 of 39.8%, both optimal results, indicating that this method can maintain good detection performance under low-light degradation conditions.

[0218] From the perspective of detection accuracy, TER-YOLO outperforms existing mainstream comparison algorithms in both mAP50 and mAP50-95 metrics across various test subsets. Compared to YOLOv5, although the accuracy metrics are similar in some scenarios, TER-YOLO achieves a stable improvement in recall, averaging approximately 4.10 percentage points higher. This indicates that the model has a significant advantage in reducing false negative rates, better meeting the practical requirement of "better to detect false positives than false negatives" in industrial defect detection. Compared to YOLOv8 and YOLOv9t, TER-YOLO improves the average mAP50 across all scenarios by 3.26 and 2.74 percentage points, respectively, further validating the effectiveness of the proposed improvement method in enhancing detection performance in complex scenarios.

[0219] In summary, TER-YOLO achieved superior detection results in various test scenarios, especially under complex degradation conditions such as low light, demonstrating that the improved method proposed in this paper is effective in enhancing the robustness and adaptability of industrial defect detection models to complex scenarios.

[0220] Furthermore, to more intuitively demonstrate the performance changes of the improved model and the YOLOv11n baseline model during training, this invention provides curves showing the changes in various metrics of the TER-YOLO model and the YOLOv11n baseline model during the training phase, such as... Figure 9 As shown.

[0221] Finally, to further evaluate the overall performance of the model, four random samples were selected for feature visualization to verify the effectiveness of the TER-YOLO model. The results of the comparative visualization analysis between the TER-YOLO model and the YOLOv11n baseline model are as follows: Figure 10As shown in the figure, compared to the YOLOv11n baseline model, the TER-YOLO model can capture richer contextual information, improve feature extraction efficiency, thereby enhancing the performance of object detection in complex scenes, achieving more accurate object localization, and effectively reducing missed detections and false detections.

[0222] Based on the same inventive concept, this application also provides a system for implementing the TER-YOLO-based industrial surface defect detection method described above. The solution provided by this system is similar to the solution described in the above method, and therefore will not be repeated here.

[0223] In one embodiment, a TER-YOLO-based industrial surface defect detection system is also provided, comprising:

[0224] The acquisition module is used to acquire the image to be detected;

[0225] The recognition module is used to input the image to be detected into the TER-YOLO model to obtain the recognition result.

[0226] In the above embodiments, each module of the TER-YOLO industrial surface defect detection system can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can call and execute the operations corresponding to each module.

[0227] In one embodiment, a computer device is also provided, comprising: a memory for storing a computer program; and a processor for executing the computer program to implement the steps as described in all the above method embodiments.

[0228] In one embodiment, a readable storage medium is also provided, on which a computer program is stored, which, when executed by a processor, implements the steps as described in all the above method embodiments.

[0229] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0230] The embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on its differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0231] The above are merely preferred embodiments of the present application and are not intended to limit the embodiments of the present application. For those skilled in the art, the embodiments of the present application can have various modifications and variations. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of the present application should be included within the protection scope of the embodiments of the present application.

Claims

1. A TER-YOLO-based industrial surface defect detection method, characterized in that, Includes the following steps: Acquire the image to be detected; The image to be detected is input into the TER-YOLO model to obtain the recognition result.

2. The TER-YOLO-based industrial surface defect detection method according to claim 1, characterized in that, The training process of the TER-YOLO model includes the following: PGD ​​adversarial training was performed on the YOLOv11n baseline model to obtain pre-trained weights; The last C3k2 module in the backbone network of the YOLOv11n baseline model is replaced with an edge-guided multi-scale collaborative enhancement module. Some C3k2 modules in the neck network of the YOLOv11n baseline model are replaced with edge-guided multi-scale collaborative enhancement modules, and a parallel multi-branch deep convolutional feature enhancement module is introduced to construct an improved detection model. The pre-trained weights are then transferred to the improved detection model for optimized training to obtain the TER-YOLO model.

3. The TER-YOLO-based industrial surface defect detection method according to claim 2, characterized in that, The processing procedure of the edge-guided multi-scale collaborative enhancement module is as follows: Input features of the main branch Perform depthwise convolution and pointwise convolution to obtain an edge intensity map; calculate a dynamic threshold based on a preset fractional q on the pixel distribution of the edge intensity map; normalize and crop the edge intensity map based on the dynamic threshold; and generate a spatial adaptive gating weight map G by performing 3×3 convolution smoothing and Sigmoid activation. Input features into the main branch Features are obtained by inputting parallel branches of the Win Transformer with different window sizes. and characteristics ; Based on the spatial adaptive gating weight map G, the features are... and characteristics Perform dynamic gating fusion to obtain preliminary fusion features. ; Utilizing depthwise convolution to input features in the main branch Perform local transformations to obtain intermediate features. Average pooling is performed on the intermediate features to obtain local low-frequency smoothing results, and the intermediate features are then processed. By subtracting the local low-frequency smoothing results, high-frequency features are obtained. ; High-frequency characteristics are analyzed using preset gain coefficients and spatially adaptive gated weighting graph G. To conduct spatial control and integrate initial features Combine to obtain fusion features ; For the fusion features Global average pooling is performed to extract the global feature representation of each channel, and the basic channel weights are generated through a channel transformation module consisting of two 1×1 convolutional layers. Global average pooling is performed on the edge intensity map to obtain the global edge response intensity. ; Based on the edge global response strength Basic channel weights Modulation is performed to obtain edge-aware channel weights. ; the channel weights With fusion features Multiply the main elements to obtain the main branch output. ; Output the main branch The features from the bypass branches are concatenated along the channel dimension and then fused through a convolutional layer to obtain the output feature map. .

4. The TER-YOLO-based industrial surface defect detection method according to claim 3, characterized in that, The SwinTransformer branch includes layer normalization, multi-head self-attention for windows, multi-layer perceptron, and residual connection, or the SwinTransformer branch includes layer normalization, multi-head self-attention for shifted windows, multi-layer perceptron, and residual connection.

5. The TER-YOLO-based industrial surface defect detection method according to claim 2, characterized in that, The processing procedure of the parallel multi-branch deep convolutional feature enhancement module is as follows: The input feature Y is compressed using a 1x1 convolution to obtain the feature. ; The compressed features are processed in parallel using two depthwise convolutions with different kernel sizes. Spatial information at different scales is extracted to obtain features. and characteristics ; Features and characteristics The concatenation is performed along the channel dimension, and then fusion and channel recovery are performed through a 1×1 convolution to obtain feature X; The feature X is residually connected to the input feature Y, and the final result is output through the SiLU activation function.

6. The TER-YOLO-based industrial surface defect detection method according to claim 2, characterized in that, It also includes the following steps: Obtain a dataset, which includes images and corresponding defect category annotations. Divide the dataset into a training set, a validation set, and a test set according to a preset ratio. Use a single perturbation factor to perturb the test set to obtain several perturbation subsets. The number of images in each perturbation subset is the same as the number of images in the test set. The model's performance is evaluated using a test set and several perturbation subsets, with evaluation metrics including precision, recall, and mean precision.

7. The TER-YOLO-based industrial surface defect detection method according to claim 6, characterized in that, The perturbation single factor includes Gaussian blur, a subset of motion blur, low light, and pixel transformation.

8. A TER-YOLO-based industrial surface defect detection system, characterized in that, include: The acquisition module is used to acquire the image to be detected; The recognition module is used to input the image to be detected into the TER-YOLO model to obtain the recognition result.

9. A computer device, characterized in that, Includes: memory, used to store computer programs; A processor for executing the computer program to implement the method as described in any one of claims 1 to 7.

10. A readable storage medium, characterized in that, The readable storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1 to 7.