Unsupervised industrial product surface defect detection method

By constructing a model architecture consisting of a teacher network, a student network, and a segmentation network, the model management and threshold dependency issues of unsupervised defect detection methods in industrial applications are resolved, achieving efficient end-to-end defect detection applicable to surface defect detection of industrial products across multiple categories and locations.

CN120976111APending Publication Date: 2025-11-18SHENSHI OPTOMETRY (SHANGHAI) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510992401.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-18
Publication Date
2025-11-18

AI Technical Summary

Technical Problem

Existing unsupervised defect detection methods face challenges in industrial applications, including complex model management, strong threshold dependence, and deployment difficulties, making it difficult to scale up deployment and meet the high-efficiency detection requirements of industrial production.

Method used

Employing a model architecture comprising a teacher network, a student network, and a segmentation network, this system optimizes model parameters through multi-scale feature extraction and cosine loss calculation, combined with focus loss, to achieve end-to-end defect detection. It outputs pixel-level defect probability maps, eliminating reliance on manual thresholds and supporting unified model training for multiple categories and locations.

Benefits of technology

It simplifies model management, improves the automation and robustness of detection, and enables efficient defect detection in industrial production, meeting high-cycle requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120976111A_ABST
    Figure CN120976111A_ABST
Patent Text Reader

Abstract

The invention discloses an unsupervised industrial product surface defect detection method. According to the technical scheme, the method comprises the following steps: constructing a ternary collaborative architecture comprising a teacher network, a de-noising student network and a segmentation network; in the training stage, normal samples and Berlin noise are used for dynamically synthesizing defect samples with pixel-level labels, and training is carried out in a self-supervision mode; and calculating the difference between the teacher network and the student network in a plurality of feature levels, inputting the difference into the segmentation network, and directly outputting a pixel-level defect probability graph. Compared with the prior art, the method has the beneficial effects that multi-category and multi-point product data mixed training can be supported, and the model management and maintenance cost is greatly reduced. Secondly, defect detection is converted into a pixel segmentation task, the robustness and accuracy of detection are remarkably improved, finally, the overall network structure can be compatible with a mainstream segmentation model, and end-to-end deployment and efficient acceleration can be easily carried out by adopting tools such as TensorRT and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision algorithms, and in particular to an unsupervised method for detecting surface defects in industrial products. Background Technology

[0002] In modern industrial manufacturing, surface defect detection is a crucial step in ensuring product quality. Traditional manual inspection methods are inefficient, subjective, and prone to fatigue, and have been gradually replaced by automated inspection systems based on machine vision. In recent years, with the rapid development of deep learning technology, especially supervised learning, the accuracy and efficiency of defect detection have been greatly improved. However, supervised methods have a fundamental bottleneck: they heavily rely on large-scale, diverse, and precisely pixel-level labeled defect sample datasets. In actual production, collecting and labeling all possible defect types is virtually impossible, leading to supervised models often "ignoring" novel or sporadic defects they have not learned before.

[0003] To overcome this limitation, academia and industry have turned their attention to unsupervised defect detection methods, also known as anomaly detection or positive sample learning. The core idea of ​​these methods is to train the model using only a large number of normal (defect-free) samples, allowing the model to fully learn the "normal" pattern. During inference, any input deviating from this normal pattern will be identified as an anomaly or defect. This paradigm greatly reduces the difficulty of data acquisition and, theoretically, can detect any unknown type of defect.

[0004] Despite their promising prospects, existing unsupervised defect detection methods still face three major challenges in industrial applications, severely restricting their large-scale deployment:

[0005] 1. Model Management Challenges: One Model Per Inspection Point. Traditional unsupervised methods typically train a dedicated model for each specific inspection point (or product category). A complex production line may contain hundreds or thousands of inspection points, meaning an equal number of models need to be trained and maintained. This "model explosion" phenomenon imposes a huge management burden on version control, deployment updates, and system maintenance.

[0006] 2. Strong Threshold Dependence: Cumbersome debugging and poor robustness. Most traditional methods ultimately output an anomaly score map, requiring manual setting of one or more thresholds to determine whether a region is a defect. Threshold setting is a very tricky balance problem: too strict a threshold will cause a large number of normal fluctuations to be falsely reported as defects (high false alarm rate), while too lenient a threshold may miss real, small defects (high false negative rate). Fixed thresholds are often difficult to adapt to situations such as changes in lighting and product batch differences, resulting in poor robustness.

[0007] 3. Deployment and Integration Challenges: Non-End-to-End Design. Many algorithm models that perform exceptionally well in academic research do not have an "end-to-end" inference process. They may involve complex preprocessing, multi-stage model inference, and time-consuming post-processing steps (such as Gaussian blurring on the CPU). This makes it difficult to directly utilize existing efficient inference frameworks (such as NVIDIA's TensorRT) for overall optimization and acceleration, resulting in unsatisfactory inference speeds after actual deployment, failing to meet the high-speed requirements of production lines.

[0008] Therefore, the industry urgently needs a better way to solve the above problems. Summary of the Invention

[0009] In view of this, this invention proposes an unsupervised method for detecting surface defects in industrial products, aiming to overcome the shortcomings of existing unsupervised detection technologies in practical applications. Specifically, this includes: simplifying model management in multi-point, multi-category scenarios; eliminating reliance on manually set thresholds to improve the automation and robustness of detection; and optimizing the model structure to achieve seamless integration with industrial-grade deployment toolchains, enabling efficient end-to-end inference. The technical solution of this invention is as follows:

[0010] This invention discloses an unsupervised method for detecting surface defects in industrial products, comprising the following steps:

[0011] S1. Construct a model architecture that includes a teacher network, a student network, and a segmentation network. The student network includes an encoder and a decoder.

[0012] S2. Input positive samples into the teacher network to extract multi-scale features.

[0013] S3. Generate defect images and input them into the student network to extract features. And calculate the cosine loss between the positive sample features of the teacher network and the defective features of the student network;

[0014] S4. Calculate the characteristics of teacher network defects. Cosine feature X of student network defect characteristics i The fused feature X is obtained after upsampling and concatenation.

[0015] S5. Input X into the segmentation network and output a pixel-level defect probability map p t And calculate the focus loss;

[0016] S6. Update model parameters using joint cosine loss and focus loss;

[0017] S7. Verify the model's performance and end training.

[0018] Specifically, the steps in S7 are as follows:

[0019] Load the validation dataset, calculate image features, and calculate the cosine feature X. i Calculate the segmentation probability p t Calculate the crossover-union ratio (CUIR), save the model parameters with the highest CUIR, and end the validation.

[0020] Specifically, multi-scale feature extraction comprises three levels:

[0021] The first-level feature size is

[0022] The second-level feature size is

[0023] The third-level feature size is

[0024] Specifically, the formula for calculating the cosine loss of the positive sample features of the teacher network and the defective features of the student network is as follows:

[0025]

[0026] in, Multi-scale features extracted from the teacher network. Features extracted from student networks.

[0027] Specifically, the cosine feature X of student network deficiency characteristics i The specific calculation formula is as follows:

[0028]

[0029] in, Characteristics of teacher network deficiencies Features extracted from student networks.

[0030] Specifically, the formula for calculating focus loss is as follows:

[0031] FL(p t )=-α t (1-p t ) γ log(p t )

[0032] Where, α t γ is the balancing factor used to balance positive and negative samples, and γ is the focus factor.

[0033] Specifically, the positive sample balance factor is 0.75, the negative sample balance factor is 0.25, and the focus factor is 4.

[0034] Specifically, the teacher network and the student network use the same backbone network structure.

[0035] Specifically, the segmentation network includes an ASPPHead structure that automatically outputs pixel classification results.

[0036] Specifically, defect image generation methods include:

[0037] Generate a Perlin noise mask of the same size as the positive sample image; randomly select an anomalous image and scale it to the size of the positive sample; replace pixels with a noise mask value of 1 with the corresponding pixels of the anomalous image.

[0038] The advantages of this invention are as follows:

[0039] 1. Solves the model management challenge: The network structure of this invention, particularly through training with synthesized diverse defect data, enables it to learn multiple normal sample patterns. Therefore, it supports mixed training with normal sample data from different product categories or different inspection points, ultimately resulting in a more generalized "universal" model. This fundamentally solves the "one model per point" problem, achieving "one model for multiple uses," and greatly simplifies model deployment and lifecycle management in industrial settings.

[0040] 2. Solves the threshold dependence problem: This invention innovatively introduces a segmentation network. This network receives the difference feature maps generated by comparing teacher and student networks and directly outputs the probability that each pixel belongs to "normal" or "abnormal". The final defect judgment is based on the pixel classification result, rather than a global or local abnormality score. This is equivalent to allowing the model to automatically learn the complex decision boundary that distinguishes between normal and abnormal during training, achieving "threshold adaptation", thus eliminating the dependence on manual thresholds and improving the stability and reliability of detection.

[0041] 3. Solves the deployment difficulty problem: The overall architecture of this invention is a forward-propagating end-to-end network during inference, and its structure is highly similar to many mainstream semantic segmentation models (such as the DeepLab series). This allows it to directly reuse mature deployment toolchains (such as TensorRT) for efficient optimization and acceleration. In addition, this invention designs operations such as Gaussian blur, which are traditionally used as post-processing steps, as a convolutional layer in the network, so that they can be accelerated by GPUs, realizing true "end-to-end" high-speed inference and meeting the stringent requirements of industrial production for detection efficiency. Attached Figure Description

[0042] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only one embodiment of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0043] Figure 1 This is a detailed flowchart of the training phase of the present invention;

[0044] Figure 2 This is a detailed flowchart of the verification phase of the present invention;

[0045] Figure 3 This is a diagram illustrating the defect detection effect of the present invention in an embodiment. Detailed Implementation

[0046] The technical solutions of the present invention will now be clearly and completely described with reference to the embodiments and accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0047] Unless otherwise defined, all technical and scientific terms used in this invention have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains; the terminology used in the detailed description is for the purpose of describing particular embodiments only and is not intended to limit the invention; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.

[0048] In the description of specific embodiments of the present invention, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present invention, "multiple" means two or more, unless otherwise explicitly defined.

[0049] In this invention, the reference to "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described in this invention can be combined with other embodiments.

[0050] In the description of the embodiments of this invention, the term "and / or" is merely a description of the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, in this invention, the character " / " generally indicates that the preceding and following associated objects have an "or" relationship.

[0051] It should be noted that, for ease of description, all identical technical features are labeled with the same symbols in the following embodiments.

[0052] In modern industrial manufacturing, surface defect detection is a crucial step in ensuring product quality. Traditional manual inspection methods are inefficient, subjective, and prone to fatigue, and have been gradually replaced by automated inspection systems based on machine vision. In recent years, with the rapid development of deep learning technology, especially supervised learning, the accuracy and efficiency of defect detection have been greatly improved. However, supervised methods have a fundamental bottleneck: they heavily rely on large-scale, diverse, and precisely pixel-level labeled defect sample datasets. In actual production, collecting and labeling all possible defect types is virtually impossible, leading to supervised models often "ignoring" novel or sporadic defects they have not learned before.

[0053] To overcome this limitation, academia and industry have turned their attention to unsupervised defect detection methods, also known as anomaly detection or positive sample learning. The core idea of ​​these methods is to train the model using only a large number of normal (defect-free) samples, allowing the model to fully learn the "normal" pattern. During inference, any input deviating from this normal pattern will be identified as an anomaly or defect. This paradigm greatly reduces the difficulty of data acquisition and, theoretically, can detect any unknown type of defect.

[0054] Despite their promising prospects, existing unsupervised defect detection methods still face three major challenges in industrial applications, severely restricting their large-scale deployment:

[0055] 1. Model Management Challenges: One Model Per Inspection Point. Traditional unsupervised methods typically train a dedicated model for each specific inspection point (or product category). A complex production line may contain hundreds or thousands of inspection points, meaning an equal number of models need to be trained and maintained. This "model explosion" phenomenon imposes a huge management burden on version control, deployment updates, and system maintenance.

[0056] 2. Strong Threshold Dependence: Cumbersome debugging and poor robustness. Most traditional methods ultimately output an anomaly score map, requiring manual setting of one or more thresholds to determine whether a region is a defect. Threshold setting is a very tricky balance problem: too strict a threshold will cause a large number of normal fluctuations to be falsely reported as defects (high false alarm rate), while too lenient a threshold may miss real, small defects (high false negative rate). Fixed thresholds are often difficult to adapt to situations such as changes in lighting and product batch differences, resulting in poor robustness.

[0057] 3. Deployment and Integration Challenges: Non-End-to-End Design. Many algorithm models that perform exceptionally well in academic research do not have an "end-to-end" inference process. They may involve complex preprocessing, multi-stage model inference, and time-consuming post-processing steps (such as Gaussian blurring on the CPU). This makes it difficult to directly utilize existing efficient inference frameworks (such as NVIDIA's TensorRT) for overall optimization and acceleration, resulting in unsatisfactory inference speeds after actual deployment, failing to meet the high-speed requirements of production lines.

[0058] Therefore, the industry urgently needs a better way to solve the above problems.

[0059] In view of this, this invention proposes an unsupervised method for detecting surface defects in industrial products, aiming to overcome the shortcomings of existing unsupervised detection technologies in practical applications. Specifically, this includes: simplifying model management in multi-point, multi-category scenarios; eliminating reliance on manually set thresholds to improve the automation and robustness of detection; and optimizing the model structure to achieve seamless integration with industrial-grade deployment toolchains, enabling efficient end-to-end inference. The specific technical solution of this invention is as follows:

[0060] This invention discloses an unsupervised method for detecting surface defects in industrial products, comprising the following steps:

[0061] S1. Construct a model architecture that includes a teacher network, a student network, and a segmentation network. The student network includes an encoder and a decoder.

[0062] S2. Input positive samples into the teacher network to extract multi-scale features.

[0063] S3. Generate defect images and input them into the student network to extract features. And calculate the cosine loss between the positive sample features of the teacher network and the defective features of the student network;

[0064] S4. Calculate the characteristics of teacher network defects. Cosine feature X of student network defect characteristics i The fused feature X is obtained after upsampling and concatenation.

[0065] S5. Input X into the segmentation network and output a pixel-level defect probability map p t And calculate the focus loss;

[0066] S6. Update model parameters using joint cosine loss and focus loss;

[0067] S7. Verify the model's performance and end training.

[0068] In one feasible implementation, such as Figure 1 As shown, the training steps are as follows:

[0069] A. Loading normal images: Load B positive sample images, with width and height of H and W respectively. The images contain RGB 3 channels. Then the dimensions of this batch of data are (B,3,H,W).

[0070] B. Generating Defect Images: First, randomly generate a Perlinnoise mask with the same width and height as the normal image; second, randomly select an image from the anomaly source dataset, call it the anomaly image, and scale it to the size of the normal image; finally, replace the pixels in the normal image where the Perlinnoise mask is 1 with the corresponding pixel values ​​from the anomaly image. Thus, the defect dataset is obtained, including: defect data and defect contour labels (M).

[0071] C. Feature Calculation: Normal images are fed into the teacher network, and encoder features of positive sample images are extracted, namely... The feature dimensions are respectively The defective images are fed into the teacher network, and the features of the defective sample images are extracted, respectively. The feature dimensions are respectively The defect image is fed into the student network, and the features of the defect sample image are calculated and denoted as... The feature dimensions are respectively

[0072] D. Calculate the cosine loss: Calculate the cosine similarity loss function between the positive sample features of the teacher network and the decoder features of the defective sample features of the student network. The formula is expressed as follows:

[0073] E. Calculate the cosine characteristic X: The formula is expressed as follows Upsample X3 and X2 to the size of X1, and concatenate them along the channel dimension to obtain X = concat(X1, X2, X3), with a feature dimension of .

[0074] F. Calculate segmentation probabilities: Feed the cosine feature X into the segmentation network to calculate the probability p of each pixel for each category, which is the same size as the original image. t The probability dimension is (B, 2, H, W), where 2 represents the two categories of normal and abnormal.

[0075] G. Calculate the segmentation loss: The formula is expressed as FL(p t )=-α t (1-p t ) γ log(p t ), α t γ is the balancing factor used to balance positive and negative samples; it is typically 0.75 for positive samples and 0.25 for negative samples. γ is the focus factor used to adjust the weights of easy and difficult samples; it is generally set to 4 by default.

[0076] H. Update model parameters: Update model parameters using the loss functions from steps D and F.

[0077] I. Verify the model's effectiveness.

[0078] J. End of training

[0079] Specifically, the steps in S7 are as follows:

[0080] Load the validation dataset, calculate image features, and calculate the cosine feature X. i Calculate the segmentation probability p t Calculate the crossover-union ratio (CUIR), save the model parameters with the highest CUIR, and end the validation.

[0081] In one feasible implementation, such as Figure 2 As shown, the verification steps are as follows:

[0082] A. Load the verification dataset: first, all images; second, defect contour labels M.

[0083] B. Calculate image features: Input the test samples into the teacher network and extract the teacher network features T. 1 T 2 T 3 The feature dimensions are respectively Test samples are fed into the student network to extract student network features. The feature dimensions are respectively

[0084] C. Calculate the cosine characteristic X: The formula is expressed as follows Upsample X3 and X2 to the size of X1, and concatenate them along the channel dimension to obtain X = concat(X1, X2, X3), with the feature dimension being...

[0085] D. Calculate the segmentation probability p t The cosine feature X is fed into the segmentation network to calculate the probability p of each pixel, which is the same size as the original image, belonging to normal or abnormal. t The feature dimensions are (B, 2, H, W). Each pixel is assigned the category with the highest probability to obtain the defect segmentation result image P, with dimensions (B, H, W).

[0086] E. Calculate the intersection-union ratio:

[0087] E. Save Model: Save the parameters of the first-order model with the largest intersection-union ratio.

[0088] G. End verification.

[0089] The technical effects of this invention are further illustrated by the following embodiments:

[0090] Using 15 different product categories, each image is a 256x2 RGB 3-channel image. The classic Restnet18 network was selected as the student and teacher network samples. The specific experimental steps are as follows:

[0091] Training phase:

[0092] A. Loading normal images: Load B positive sample images, with width and height of H and W respectively. The images contain RGB 3 channels. Then the dimensions of this batch of data are (B,3,256,256).

[0093] B. Generating Defect Images: First, randomly generate a Perlinnoise mask with the same width and height as the normal image; second, randomly select an image from the anomaly source dataset, call it the anomaly image, and scale it to the size of the normal image; finally, replace the pixels in the normal image where the Perlinnoise mask is 1 with the corresponding pixel values ​​from the anomaly image. Thus, the defect dataset is obtained, including: defect data and defect contour labels (M).

[0094] C. Feature Calculation: Normal images are fed into the teacher network, and encoder features of positive sample images are extracted, namely... The feature dimensions are (B, 64, 64, 64), (B, 128, 32, 32), and (B, 256, 16, 16), respectively. The defective images are fed into the teacher network, and the features of the defective sample images are extracted, respectively. The feature dimensions are (B, 64, 64, 64), (B, 128, 32, 32), and (B, 256, 16, 16), respectively. The defect image is fed into the student network to calculate the defect sample image features, denoted as... The feature dimensions are (B,64,64,64), (B,128,32,32), and (B,256,16,16), respectively.

[0095] D. Calculate the cosine loss: Calculate the cosine similarity loss function between the positive sample features of the teacher network and the decoder features of the defective sample features of the student network. The formula is expressed as follows:

[0096] E. Calculate the cosine characteristic X: The formula is expressed as follows Upsample X3 and X2 to the size of X1, and concatenate them along the channel dimension to obtain X = concat(X1, X2, X3), with a feature dimension of (B, 448, 64, 64).

[0097] F. Calculate segmentation probabilities: Feed the cosine feature X into the segmentation network to calculate the probability p of each pixel for each category, which is the same size as the original image. t The probability dimension is (B, 2, 256, 256), where 2 represents the two categories of normal and abnormal.

[0098] G. Calculate the segmentation loss: The formula is expressed as FL(p t )=-α t (1-p t ) γ log(p t ), α t γ is the balancing factor used to balance positive and negative samples; it is typically 0.75 for positive samples and 0.25 for negative samples. γ is the focus factor used to adjust the weights of easy and difficult samples; it is generally set to 4 by default.

[0099] H. Update model parameters: Update model parameters using the loss functions from steps 4 and 6.

[0100] I. Verify the model's effectiveness.

[0101] J. End of training.

[0102] Verification phase

[0103] A. Load the verification dataset. This includes all images and the defect contour labels M.

[0104] B. Calculate image features: Input the test samples into the teacher network and extract the teacher network features T. 1 T 2 T 3The feature dimensions are (B, 64, 64, 64), (B, 128, 32, 32), and (B, 256, 16, 16), respectively; the test samples are fed into the student network, and the student network features are extracted. The feature dimensions are (B,64,64,64), (B,128,32,32), and (B,256,16,16), respectively.

[0105] C. Calculate the cosine characteristic X: The formula is expressed as follows Upsample X3 and X2 to the size of X1, and concatenate them along the channel dimension to obtain X = concat(X1, X2, X3), with a feature dimension of (B, 448, 64, 64).

[0106] D. Calculate the segmentation probability p t The cosine feature X is fed into the segmentation network to calculate the probability p of each pixel, which is the same size as the original image, belonging to normal or abnormal. t The feature dimension is (B, 2, 256, 256). Each pixel is assigned the category with the highest probability to obtain the defect segmentation result image P, with dimension (B, 256, 256).

[0107] E. Calculate the intersection-union ratio:

[0108] E. Save Model: Save the parameters of the first-order model with the largest intersection-union ratio.

[0109] G. End verification.

[0110] In this embodiment, the experimental results are as follows: Figure 3 As shown, the method of this invention can accurately locate defect areas in the original image. The probability heatmap in the middle clearly highlights the defect location, and its shape and range highly match the real label on the right. This intuitively demonstrates that this invention can still achieve high-precision pixel-level defect localization without training with real defect samples, verifying the advanced nature and practicality of this technical solution.

[0111] The advantages of this invention are as follows:

[0112] 1. Solves the model management challenge: The network structure of this invention, particularly through training with synthesized diverse defect data, enables it to learn multiple normal sample patterns. Therefore, it supports mixed training with normal sample data from different product categories or different inspection points, ultimately resulting in a more generalized "universal" model. This fundamentally solves the "one model per point" problem, achieving "one model for multiple uses," and greatly simplifies model deployment and lifecycle management in industrial settings.

[0113] 2. Solves the threshold dependence problem: This invention innovatively introduces a segmentation network. This network receives the difference feature maps generated by comparing teacher and student networks and directly outputs the probability that each pixel belongs to "normal" or "abnormal". The final defect judgment is based on the pixel classification result, rather than a global or local abnormality score. This is equivalent to allowing the model to automatically learn the complex decision boundary that distinguishes between normal and abnormal during training, achieving "threshold adaptation", thus eliminating the dependence on manual thresholds and improving the stability and reliability of detection.

[0114] 3. Solves the deployment difficulty problem: The overall architecture of this invention is a forward-propagating end-to-end network during inference, and its structure is highly similar to many mainstream semantic segmentation models (such as the DeepLab series). This allows it to directly reuse mature deployment toolchains (such as TensorRT) for efficient optimization and acceleration. In addition, this invention designs operations such as Gaussian blur, which are traditionally used as post-processing steps, as a convolutional layer in the network, so that they can be accelerated by GPUs, realizing true "end-to-end" high-speed inference and meeting the stringent requirements of industrial production for detection efficiency.

Claims

1. A method for detecting surface defects in industrial products based on unsupervised inspection, characterized in that, Includes the following steps: S1. Construct a model architecture that includes a teacher network, a student network, and a segmentation network, wherein the student network includes an encoder and a decoder; S2. Input positive samples into the teacher network to extract multi-scale features. S3. Generate defect images and input them into the student network to extract features. And calculate the cosine loss between the positive sample features of the teacher network and the defective features of the student network; S4. Calculate the characteristics of teacher network defects. Cosine feature X of student network defect characteristics i The fused feature X is obtained after upsampling and concatenation; S5. Input X into the segmentation network and output a pixel-level defect probability map p t And calculate the focus loss; S6. Update model parameters using joint cosine loss and focus loss; S7. Verify the model's performance and end training.

2. The method according to claim 1, characterized in that, The specific steps in S7 are as follows: Load the validation dataset, calculate image features, and calculate the cosine feature X. i Calculate the segmentation probability p t Calculate the crossover-union ratio (CUIR), save the model parameters with the highest CUIR, and end the validation.

3. The method according to claim 1, characterized in that, Multi-scale feature extraction comprises three levels: The first-level feature size is The second-level feature size is The third-level feature size is 4. The method according to claim 1, characterized in that, The formula for calculating the cosine loss of the positive sample features of the teacher network and the defective features of the student network is as follows: in, Multi-scale features extracted from the teacher network. Features extracted from student networks.

5. The method according to claim 1, characterized in that, Cosine feature X of student network defect characteristics i The specific calculation formula is as follows: in, Characteristics of teacher network deficiencies Features extracted from student networks.

6. The method according to claim 1, characterized in that, The formula for calculating focus loss is as follows: FL(p t )=-a t (1-p t ) γ log(p t ) Where, α t γ is the balancing factor used to balance positive and negative samples, and γ is the focus factor.

7. The method according to claim 1, characterized in that, The balance factor for positive samples is 0.75, for negative samples it is 0.25, and the focus factor is 4.

8. The method according to claim 1, characterized in that, The teacher network and the student network use the same backbone network structure.

9. The method according to claim 1, characterized in that, The segmentation network includes an ASPPHead structure and automatically outputs pixel classification results.

10. The method according to claim 1, characterized in that, Defect image generation methods include: Generate a Perlin noise mask of the same size as the positive sample image; randomly select an anomalous image and scale it to the size of the positive sample; replace pixels with a noise mask value of 1 with the corresponding pixels of the anomalous image.