A lightweight defect detection method based on contrastive knowledge distillation

The lightweight defect detection method based on comparative knowledge distillation solves the problems of low efficiency and high computing resource requirements of existing defect detection methods, achieves efficient and accurate defect detection, and reduces model complexity and computing resource requirements.

CN118887206BActive Publication Date: 2025-01-21HUNAN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411346269.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2025-01-21
Estimated Expiration
2044-09-26

AI Technical Summary

Technical Problem

The existing defect detection methods have problems such as inefficient efficiency, insufficient flexibility and high demand for computing resources, and it is difficult to meet the needs of modern manufacturing for efficient and accurate testing.

Method used

A lightweight defect detection method based on contrastive knowledge distillation is adopted. By building a teacher network model and a lightweight student network model, and using contrastive learning loss and detection loss for training, knowledge distillation is achieved and the model complexity and computing resource requirements are reduced.

Benefits of technology

While maintaining high detection accuracy, it greatly reduces model complexity and computing resource requirements, improves the efficiency and accuracy of defect detection, and is suitable for industrial field environments with limited resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118887206B_ABST
    Figure CN118887206B_ABST
Patent Text Reader

Abstract

The present invention discloses a lightweight defect detection method based on contrastive knowledge distillation, which collects and preprocesses defect detection data, builds a teacher network model and a lightweight student network model for defect detection, and trains the teacher network model based on the preprocessed data set; the defect images in the preprocessed data set are input into the trained teacher network model and the lightweight student network model to obtain the teacher multi-scale knowledge and the student multi-scale knowledge, and the difference between the multi-scale knowledge of the teacher and student network models is minimized by contrastive learning loss, and the total loss composed of contrastive learning loss and detection loss is combined to update the parameters of the student network model by using the back propagation algorithm; the trained lightweight student network model is deployed and applied to the autonomous mobile robot to realize dynamic and real-time defect detection of intelligent manufacturing products. Promote efficient, accurate and sustainable intelligent manufacturing production.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of defect detection in intelligent manufacturing, and in particular relates to a lightweight defect detection method based on comparative knowledge distillation. Background Art

[0002] In the field of intelligent manufacturing, product quality inspection is an important link to ensure the stability of the production process and the qualified rate of products. Defect detection, as an important part of quality inspection, aims to identify and locate various defects in products, such as surface scratches, cracks, deformation, etc., through automated means. However, traditional defect detection methods have many limitations and cannot meet the needs of modern manufacturing for efficient and accurate detection. Limitations of existing defect detection methods: 1) Manual detection: Traditional defect detection mainly relies on manual operation. This method is not only inefficient, but also limited by the experience and fatigue of the inspectors, and the stability and consistency of the detection results are difficult to guarantee; 2) Rule-based methods: Some early automated defect detection systems rely on preset rules and thresholds for detection. This method may be effective for known types of defects, but it shows great limitations when facing complex and changeable defect types and environmental changes, and lacks sufficient flexibility and adaptability; 3) Deep learning methods: In recent years, defect detection methods based on deep learning have gradually emerged. By training models such as convolutional neural networks (CNNs), deep learning methods have shown superior performance in image recognition and defect detection. However, these models usually require a lot of computing resources and data for training and inference, which increases the complexity of the system and makes it difficult to meet the real-time and resource-limited requirements of industrial sites.

[0003] Based on this, the present invention proposes a lightweight defect detection method based on comparative knowledge distillation. Summary of the invention

[0004] In view of the above technical problems, the present invention provides a lightweight defect detection method based on comparative knowledge distillation.

[0005] The technical solution adopted by the present invention to solve the technical problem is:

[0006] A lightweight defect detection method based on comparative knowledge distillation, the method comprising the following steps:

[0007] S100: collecting and preprocessing defect detection data to obtain a preprocessed data set;

[0008] S200: Build a teacher network model and a lightweight student network model for defect detection;

[0009] S300: training the teacher network model based on the preprocessed data set to obtain a trained teacher network model;

[0010] S400: Input the defect images in the preprocessed data set into the trained teacher network model to obtain the teacher multi-scale knowledge, and at the same time input the defect images in the preprocessed data set into the lightweight student network model to obtain the student multi-scale knowledge, minimize the difference between the multi-scale knowledge of the teacher and student network models through contrastive learning loss, transfer the fine-grained knowledge of the teacher network model to the student network model to complete contrastive knowledge distillation, and use the back propagation algorithm to update the parameters of the student network model in combination with the total loss composed of contrastive learning loss and detection loss to obtain a trained lightweight student network model;

[0011] S500: Deploy and apply the trained lightweight student network model to an autonomous mobile robot to achieve dynamic and real-time defect detection of smart manufacturing products.

[0012] Preferably, S100 includes:

[0013] S110: Collect comprehensive and diverse defect image data covering various defect types in the intelligent manufacturing process through real-time acquisition of production lines or using historical data;

[0014] S120: Use annotation software to annotate the defect type and location in each image;

[0015] S130: preprocessing the marked defect data to obtain preprocessed defect data; wherein the preprocessing includes uniformly cropping the image and processing the defect data using image enhancement technology.

[0016] Preferably, the teacher network model in S200 includes a residual network with a depth of 101 layers for multi-scale feature extraction, a feature pyramid module for multi-scale feature fusion, and a detection head module for detection result prediction; wherein the feature pyramid module first uses a convolution layer to construct multi-scale features of different scales and the same number of channels, and then uses bilinear interpolation to achieve top-down feature fusion to achieve the fusion of semantic features and pixel-level features. The detection head module first uses four convolution layers with shared weights to encode the fused multi-scale features, and then predicts the positioning box and category of the defect through two decoding branches composed of convolution layers.

[0017] Preferably, the lightweight student network model in S200 includes a residual network with a depth of 18 layers for multi-scale feature extraction, a feature pyramid module for multi-scale feature fusion, and a detection head module for detection result prediction; wherein the feature pyramid module first uses a convolution layer to construct multi-scale features of different scales and the same number of channels, and then uses bilinear interpolation to achieve top-down feature fusion to achieve the fusion of semantic features and pixel-level features. The detection head module first uses four convolution layers with shared weights to encode the fused multi-scale features, and then predicts the positioning box and category of the defect through two decoding branches composed of convolution layers.

[0018] Preferably, S400 includes:

[0019] S410: Input the defect images in the preprocessed data set into the trained teacher network model and the lightweight student network model to obtain multi-scale knowledge and , ;

[0020] S420: The multi-scale knowledge of the teacher network model and the multi-scale knowledge of the student network model are combined by using a sliding window and Divide into non-overlapping local knowledge blocks and ;

[0021] S430: constructing positive and negative sample pairs in contrastive learning using local knowledge blocks, with knowledge blocks at corresponding positions as positive sample pairs and knowledge blocks at non-corresponding positions as negative sample pairs, and using contrastive loss based on cross entropy to minimize the distance between positive sample pairs and maximize the distance between negative sample pairs;

[0022] S440: Use the global knowledge distribution alignment method to achieve the global knowledge transfer between the teacher and student network models;

[0023] S450: Use the detection loss to train the self-learning process of the lightweight student network model, combine the contrastive learning loss and the detection loss to form the total loss of training the student network model, and use the back propagation algorithm to update the parameters of the student network model to obtain a trained lightweight student network model.

[0024] Preferably, S420 specifically includes:

[0025] ;

[0026] ;

[0027] in, Represents the teacher network model The scale of A local block, Represents the student network model The scale of local blocks, in addition, , and Indicates the coordinates of the upper left corner of the sliding window, The value range is , The value range is .

[0028] Preferably, the local knowledge contrast loss in S430 is specifically:

[0029] ;

[0030] in represents the cosine similarity metric function, is the temperature parameter used to control the smoothness of the distribution, is the number of positive sample pairs;

[0031] The calculation formula of the cosine similarity calculation function is as follows:

[0032] ;

[0033] in, represents the dot product of the teacher and the student’s local knowledge blocks, represents the two-norm.

[0034] Preferably, S440 includes:

[0035] S441: By The local knowledge calculates the absolute value, and then follows The dimension is obtained by aggregating local knowledge by calculating the average value The global knowledge of dimension The local knowledge calculates the absolute value, and then follows The dimension is obtained by aggregating local knowledge by calculating the average value Dimensional global knowledge; calculate the teacher network model and lightweight student network model separately and Global knowledge of dimensions;

[0036] S442: The aggregated global knowledge is processed using a normalized exponential function to obtain the teacher and student network models. and Dimensional global knowledge distribution;

[0037] S443: The mean square error loss (MSE) of the knowledge distribution of the teacher and student network models is calculated to achieve the transfer of global knowledge distribution.

[0038] Preferably, S441 is specifically:

[0039] ;

[0040] ;

[0041] ;

[0042] ;

[0043] in, It is the teacher network model Global knowledge of dimensions, Is a student network model Global knowledge of dimensions, It is the teacher network model Global knowledge of dimensions, Is a student network model Global knowledge of dimensions, It is the teacher network model The local knowledge of the A local block, The student network model The local knowledge of the A local block, It is the teacher network model The local knowledge of the pixel values, The student network model The local knowledge of the pixel value;

[0044] S442 is specifically:

[0045] ;

[0046] ;

[0047] ;

[0048] ;

[0049] in, It is the teacher network model Dimensional global knowledge distribution, Is a student network model Dimensional global knowledge distribution, It is the teacher network model Dimensional global knowledge distribution, Is a student network model Dimensional global knowledge distribution, is the temperature coefficient, is the number of local knowledge blocks, is the size of the local knowledge block, which is used to adjust the scale range of knowledge distribution;

[0050] S443 is specifically:

[0051] .

[0052] Preferably, S450 is specifically:

[0053] ;

[0054] in, and They are used to adjust the distillation loss and detection loss respectively. is the distillation loss, To detect losses;

[0055] The detection loss includes classification loss, regression loss and center point prediction loss. The classification loss uses focal loss, which is:

[0056] ;

[0057] Where y represents the label of the actual defect category, and p represents the category predicted by the student network model. It is a hyperparameter used to adjust the size of the loss;

[0058] The regression loss uses the generalized intersection-over-union loss, which is calculated as follows:

[0059] ;

[0060] in, represents the intersection-over-union ratio between the real annotation and the predicted box, It represents the minimum area of ​​the box that can contain both the predicted box and the true box, and U represents the joint area of ​​the predicted box and the true box;

[0061] The center point loss uses cross entropy loss, and the calculation formula is as follows:

[0062] ;

[0063] in, Represents the true centrality value, between 0 and 1, represents the centrality value predicted by the model, and N is the total number of samples;

[0064] Detection loss The calculation formula is as follows:

[0065] ;

[0066] in, , and They are the weight coefficients used to adjust the classification loss, regression loss and center loss respectively.

[0067] Knowledge distillation is a method that transfers the knowledge of a large and complex model (teacher network model) to a small and lightweight model (lightweight student network model). Through knowledge distillation, the student network model can significantly reduce the demand for computing resources while maintaining high performance, thereby achieving lightweight models. A lightweight defect detection method based on contrastive knowledge distillation is proposed to combine the advantages of knowledge distillation and contrastive learning to address the shortcomings of existing technologies. This method can not only significantly reduce model complexity and computing resource requirements while maintaining high detection accuracy, but also has strong adaptability and robustness, and is suitable for various defect detection tasks in the field of intelligent manufacturing. Through the introduction of contrastive knowledge distillation technology, the present invention not only improves the efficiency and accuracy of defect detection, but also greatly reduces the demand for computing resources. It is particularly suitable for application in resource-constrained industrial field environments, and promotes efficient, accurate and sustainable intelligent manufacturing production. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] Figure 1 It is a flow chart of a lightweight defect detection method based on comparative knowledge distillation in one embodiment of the present invention;

[0069] Figure 2 It is a schematic diagram of a lightweight defect detection method based on comparative knowledge distillation in one embodiment of the present invention. DETAILED DESCRIPTION

[0070] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings.

[0071] In one embodiment, Figure 1 and Figure 2 As shown, a lightweight defect detection method based on contrast knowledge distillation comprises the following steps:

[0072] S100: collecting and preprocessing defect detection data to obtain a preprocessed data set;

[0073] S200: Build a teacher network model and a lightweight student network model for defect detection;

[0074] S300: training the teacher network model based on the preprocessed data set to obtain a trained teacher network model;

[0075] S400: Input the defect images in the preprocessed data set into the trained teacher network model to obtain the teacher multi-scale knowledge, and at the same time input the defect images in the preprocessed data set into the lightweight student network model to obtain the student multi-scale knowledge, minimize the difference between the multi-scale knowledge of the teacher and student network models through contrastive learning loss, transfer the fine-grained knowledge of the teacher network model to the student network model to complete contrastive knowledge distillation, and use the back propagation algorithm to update the parameters of the student network model in combination with the total loss composed of contrastive learning loss and detection loss to obtain a trained lightweight student network model;

[0076] S500: Deploy and apply the trained lightweight student network model to an autonomous mobile robot to achieve dynamic and real-time defect detection of smart manufacturing products.

[0077] In one embodiment, S100 includes:

[0078] S110: Collect comprehensive and diverse defect image data covering various defect types (such as surface scratches, cracks, bubbles, deformation, contamination, etc.) in the intelligent manufacturing process through real-time acquisition of production lines or using historical data;

[0079] S120: Use annotation software to annotate the defect type and location in each image;

[0080] S130: preprocessing the marked defect data to obtain preprocessed defect data; wherein the preprocessing includes uniformly cropping the image and processing the defect data using image enhancement technology.

[0081] Specifically, in the intelligent manufacturing scenario, data collection and preprocessing of defect detection are the key to achieving efficient and accurate detection. Labeling in S120 is to facilitate the training of the defect detection network; unified cropping in S130 ensures that the defect data is input into the detection network with the same size, and then image enhancement techniques such as rotation, translation, scaling, flipping, adding noise and color adjustment are used to process the defect data to enhance the diversity and robustness of the data and ensure that the detection network can be fully trained. The preprocessed defect image dataset is divided into a training set and a validation set for the training and testing process of the model. Through the above steps, it is ensured that the image data is of high quality and good representativeness before entering the model training, thereby providing a solid foundation for efficient and accurate defect detection.

[0082] In one embodiment, the teacher network model in S200 includes a residual network with a depth of 101 layers for multi-scale feature extraction, a feature pyramid module for multi-scale feature fusion, and a detection head module for detection result prediction; wherein the feature pyramid module first uses a convolutional layer to construct multi-scale features of different scales and the same number of channels, and then uses bilinear interpolation to achieve top-down feature fusion to achieve the fusion of semantic features and pixel-level features. The detection head module first uses four convolutional layers with shared weights to encode the fused multi-scale features, and then predicts the positioning box and category of the defect through two decoding branches composed of convolutional layers.

[0083] Specifically, teacher network model training is a key step in building a lightweight defect detection system, which aims to build a defect detector with strong feature expression ability and high detection accuracy. Through deep structure and advanced design, the detector can capture subtle features in the image and achieve high-precision defect detection.

[0084] In this process, the present invention selects the existing target detection model ATSS network as the teacher detector for locating defect locations and identifying defect categories. The ATSS network combines advanced feature extraction and target detection technologies to provide accurate defect detection results. The backbone network of the teacher network model selects a residual network (ResNet-101) with 101 layers for multi-scale defect feature extraction. ResNet-101 solves the gradient vanishing problem in deep network training by introducing residual blocks, ensuring the effective training of deep networks and powerful feature expression capabilities. In addition, a feature pyramid module (FPN) is used in the teacher network model to fuse defect features of different scales. FPN can effectively integrate high-resolution and low-resolution features by enhancing features through a bottom-up path, thereby improving the detection capability of multi-scale defects.

[0085] In order to train and test the teacher network model, a labeled defect dataset is used. The dataset should cover various defect types and different environmental conditions to ensure the generalization and representativeness of the model. During the training process, the detection performance of the model is further improved through data enhancement, optimizer selection, and hyperparameter tuning. After the training is completed, the weights of the teacher network model with excellent performance are saved to guide the learning process of the student network model, thereby realizing the construction of a lightweight defect detection system.

[0086] In one embodiment, the lightweight student network model in S200 includes a residual network with a depth of 18 layers for multi-scale feature extraction, a feature pyramid module for multi-scale feature fusion, and a detection head module for detection result prediction; wherein the feature pyramid module first uses a convolution layer to construct multi-scale features of different scales and the same number of channels, and then uses bilinear interpolation to achieve top-down feature fusion to achieve the fusion of semantic features and pixel-level features. The detection head module first uses four convolution layers with shared weights to encode the fused multi-scale features, and then predicts the positioning box and category of the defect through two decoding branches composed of convolution layers.

[0087] Specifically, the present invention selects the target detection model ATSS network that is consistent with the teacher network model as a lightweight defect detection model to facilitate knowledge transfer. The backbone network of the lightweight detector (student network model) selects an 18-layer residual network for multi-scale defect feature extraction. In addition, a feature pyramid module is also used in the student network model to fuse defect features of different scales, which can ensure the effective integration of high-resolution and low-resolution features and improve the detection capability of multi-scale defects.

[0088] In one embodiment, S400 includes:

[0089] S410: Input the defect images in the preprocessed data set into the trained teacher network model and the lightweight student network model to obtain multi-scale knowledge and , ;

[0090] S420: The multi-scale knowledge of the teacher network model and the multi-scale knowledge of the student network model are combined by using a sliding window and Divide into non-overlapping local knowledge blocks and ;

[0091] S430: constructing positive and negative sample pairs in contrastive learning using local knowledge blocks, with knowledge blocks at corresponding positions as positive sample pairs and knowledge blocks at non-corresponding positions as negative sample pairs, and using contrastive loss based on cross entropy to minimize the distance between positive sample pairs and maximize the distance between negative sample pairs;

[0092] S440: Use the global knowledge distribution alignment method to achieve the global knowledge transfer between the teacher and student network models;

[0093] S450: Use the detection loss to train the self-learning process of the lightweight student network model, combine the contrastive learning loss and the detection loss to form the total loss of training the student network model, and use the back propagation algorithm to update the parameters of the student network model to obtain a trained lightweight student network model.

[0094] Specifically, in S430, in order to achieve knowledge transfer between corresponding knowledge blocks, positive and negative sample pairs in contrastive learning can be constructed according to different positions, which can not only achieve the transfer of corresponding knowledge blocks, but also increase the differences between different knowledge blocks. The local knowledge blocks with the same position in the teacher network model and the lightweight student network model constitute the positive sample pair. , and local knowledge blocks at different positions constitute negative sample pairs In S440, in order to prevent the student network model from paying too much attention to the local knowledge of the teacher network model, a global knowledge distribution alignment method is adopted to achieve the migration of global knowledge between the teacher and student network models.

[0095] In one embodiment, S420 specifically includes:

[0096] ;

[0097] ;

[0098] in, Represents the teacher network model The scale of A local block, Represents the student network model The scale of local blocks, in addition, , and Indicates the coordinates of the upper left corner of the sliding window, The value range is , The value range is .

[0099] In one embodiment, the local knowledge contrast loss in S430 is specifically:

[0100] ;

[0101] in represents the cosine similarity metric function, is the temperature parameter used to control the smoothness of the distribution, is the number of positive sample pairs;

[0102] The calculation formula of the cosine similarity calculation function is as follows:

[0103] ;

[0104] in, represents the dot product of the teacher and the student’s local knowledge blocks, represents the two-norm.

[0105] In one embodiment, S440 includes:

[0106] S441: By The local knowledge calculates the absolute value, and then follows The dimension is obtained by aggregating local knowledge by calculating the average value The global knowledge of dimension The local knowledge calculates the absolute value, and then follows The dimension is obtained by aggregating local knowledge by calculating the average value Dimensional global knowledge; calculate the teacher network model and lightweight student network model separately and Global knowledge of dimensions;

[0107] S442: The aggregated global knowledge is processed using a normalized exponential function to obtain the teacher and student network models. and Dimensional global knowledge distribution;

[0108] S443: The mean square error loss (MSE) of the knowledge distribution of the teacher and student network models is calculated to achieve the transfer of global knowledge distribution.

[0109] In one embodiment, S441 is specifically:

[0110] ;

[0111] ;

[0112] ;

[0113] ;

[0114] in, It is the teacher network model Global knowledge of dimensions, Is a student network model Global knowledge of dimensions, It is the teacher network model Global knowledge of dimensions, Is a student network model Global knowledge of dimensions, It is the teacher network model The local knowledge of the A local block, The student network model The local knowledge of the A local block, It is the teacher network model The local knowledge of the pixel values, The student network model The local knowledge of the pixel value;

[0115] S442 is specifically:

[0116] ;

[0117] ;

[0118] ;

[0119] ;

[0120] in, It is the teacher network model Dimensional global knowledge distribution, It is a student network model Dimensional global knowledge distribution, It is the teacher network model Dimensional global knowledge distribution, It is a student network model Dimensional global knowledge distribution, is the temperature coefficient, is the number of local knowledge blocks, is the size of the local knowledge block, which is used to adjust the scale range of knowledge distribution;

[0121] S443 is specifically:

[0122] .

[0123] In one embodiment, S450 is specifically:

[0124] ;

[0125] in, and They are used to adjust the distillation loss and detection loss respectively. is the distillation loss, To detect losses;

[0126] The detection loss includes classification loss, regression loss and center point prediction loss. The classification loss uses focal loss, which is:

[0127] ;

[0128] Where y represents the label of the actual defect category, and p represents the category predicted by the student network model. It is a hyperparameter used to adjust the size of the loss;

[0129] The regression loss uses the generalized intersection-over-union loss, which is calculated as follows:

[0130] ;

[0131] in, represents the intersection-over-union ratio between the real annotation and the predicted box, It represents the minimum area of ​​the box that can contain both the predicted box and the true box, and U represents the joint area of ​​the predicted box and the true box;

[0132] The center point loss uses cross entropy loss, and the calculation formula is as follows:

[0133] ;

[0134] in, Represents the true centrality value, between 0 and 1, represents the centrality value predicted by the model, and N is the total number of samples;

[0135] Detection loss The calculation formula is as follows:

[0136] ;

[0137] in, , and They are the weight coefficients used to adjust the classification loss, regression loss and center loss respectively.

[0138] Furthermore, the model is evaluated and saved. First, the model is evaluated through the test set, and the performance indicators of the lightweight student network model are calculated, including accuracy, recall, F1 score, and average precision. Among them, the accuracy measures the correctness of the model prediction, the recall rate evaluates the proportion of defect instances detected by the model to all actual defect instances, the F1 score comprehensively considers the accuracy and recall rate, and provides a balanced evaluation of the overall performance, while the average precision reflects the overall performance of the model under different detection difficulties by calculating the precision and recall rate under different thresholds.

[0139] Finally, the weights of the trained lightweight student network model are saved. Saving the model weights is not only convenient for subsequent model loading and use, but can also be used for further model optimization and transfer learning.

[0140] The saved model weights will serve as the basis for model deployment, and dynamic and real-time detection of defects will be achieved in practical applications, thereby improving the autonomy and unmanned level of the intelligent manufacturing process. Deploying and applying the trained lightweight student network model to the autonomous mobile platform can significantly improve the efficiency and accuracy of defect detection in the intelligent manufacturing process. First, the autonomous mobile platform is equipped with a highly adaptable hardware and software environment, including the selection of high-performance processors and an environment compatible with the deep learning framework. Then, the trained lightweight model is refined and optimized, including model quantization, pruning, and format conversion, aiming to improve the inference speed and reduce memory usage to adapt to the computing resource constraints of the autonomous mobile platform. In addition, the optimized lightweight student network model is integrated into the inference engine of the autonomous mobile platform to ensure that the model can receive and process input data in real time and output accurate defect detection results in a timely manner. After deployment, the training set is expanded with new defect data and the model is retrained and optimized to further improve its detection accuracy and generalization ability.

[0141] The present invention not only realizes the dynamic, real-time and rapid detection of defects in the intelligent manufacturing process, but also promotes the autonomous and unmanned process of intelligent manufacturing, significantly improves production efficiency and product quality, and brings significant technological progress and economic benefits to the industry.

[0142] The above is a detailed introduction to a lightweight defect detection method based on comparative knowledge distillation provided by the present invention. This article uses specific examples to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the core idea of ​​the present invention. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.

Claims

1. A lightweight defect detection method based on comparative knowledge distillation, characterized in that: The method comprises the following steps: S100: collecting and preprocessing defect detection data to obtain a preprocessed data set; S200: Build a teacher network model and a lightweight student network model for defect detection; the teacher network model includes a residual network with a depth of 101 layers for multi-scale knowledge extraction, a feature pyramid module for multi-scale knowledge fusion, and a detection head module for detection result prediction; among them, the feature pyramid module first uses convolution layers to construct multi-scale knowledge of different scales and the same number of channels, and then uses bilinear interpolation to achieve top-down feature fusion, realizing the fusion of semantic features and pixel-level features. The detection head module first uses four convolution layers with shared weights to encode the fused multi-scale knowledge, and then passes through two decoding branches composed of convolution layers. The positioning box and category of the defect are predicted respectively; the lightweight student network model includes a residual network with a depth of 18 layers for multi-scale knowledge extraction, a feature pyramid module for multi-scale knowledge fusion, and a detection head module for detection result prediction; among them, the feature pyramid module first uses the convolution layer to construct multi-scale knowledge of different scales and the same number of channels, and then uses bilinear interpolation to achieve top-down feature fusion, realizing the fusion of semantic features and pixel-level features. The detection head module first uses four convolution layers with shared weights to encode the fused multi-scale knowledge, and then predicts the positioning box and category of the defect respectively through two decoding branches composed of convolution layers; S300: training the teacher network model based on the preprocessed data set to obtain a trained teacher network model; S400: Input the defect images in the preprocessed data set into the trained teacher network model to obtain the teacher multi-scale knowledge, and input the defect images in the preprocessed data set into the lightweight student network model to obtain the student multi-scale knowledge, minimize the difference between the multi-scale knowledge of the teacher and student network models through contrastive learning loss, transfer the fine-grained knowledge of the teacher network model to the student network model to complete contrastive knowledge distillation, and use the back propagation algorithm to update the parameters of the student network model in combination with the total loss composed of contrastive learning loss and detection loss to obtain a trained lightweight student network model; S400 includes: S410: Input the defect images in the preprocessed data set into the trained teacher network model and the lightweight student network model to obtain multi-scale knowledge and , ; S420: The multi-scale knowledge of the teacher network model and the multi-scale knowledge of the student network model are combined by using a sliding window and Divide into non-overlapping local knowledge blocks and ; S430: Utilizing local knowledge blocks and Construct positive and negative sample pairs in contrastive learning, with knowledge blocks at corresponding positions as positive sample pairs and knowledge blocks at non-corresponding positions as negative sample pairs. Use local knowledge contrast loss based on cross entropy to minimize the distance between positive sample pairs and maximize the distance between negative sample pairs. S440: Use the global knowledge distribution alignment method to achieve the global knowledge transfer between the teacher and student network models; S450: Using the detection loss to train the self-learning process of the lightweight student network model, combining the contrastive learning loss and the detection loss to form the total loss of the training student network model, and using the back propagation algorithm to update the parameters of the student network model to obtain a trained lightweight student network model; S440 includes: S441: By The local knowledge calculates the absolute value, and then follows The dimension is obtained by aggregating local knowledge by calculating the average value The global knowledge of dimension The local knowledge calculates the absolute value, and then follows The dimension is obtained by aggregating local knowledge by calculating the average value Global knowledge; calculate the teacher network model and lightweight student network model separately and Dimensional global knowledge; among them, is the number of local knowledge blocks, is the size of the local knowledge block, which is used to adjust the scale range of knowledge distribution; S442: The aggregated global knowledge is processed using a normalized exponential function to obtain the teacher and student network models. and Dimensional global knowledge distribution; S443: The global knowledge distribution alignment loss is obtained by calculating the mean square error loss MSE of the knowledge distribution of the teacher and student network models to achieve the transfer of global knowledge distribution; S500: Deploy and apply the trained lightweight student network model to an autonomous mobile robot to achieve dynamic and real-time defect detection of smart manufacturing products.

2. The method according to claim 1, characterized in that S100 includes: S110: Collect comprehensive and diverse defect image data covering various defect types in the intelligent manufacturing process through real-time acquisition of production lines or using historical data; S120: Use annotation software to annotate the defect type and location in each image; S130: preprocessing the marked defect data to obtain preprocessed defect data; wherein the preprocessing includes uniformly cropping the image and processing the defect data using image enhancement technology.

3. The method according to claim 2, characterized in that S420 is specifically: ; ; in, Represents the teacher network model The scale of A local block, Represents the student network model The scale of local blocks, in addition, , and Indicates the coordinates of the upper left corner of the sliding window, The value range is , The value range is .

4. The method according to claim 3, characterized in that The local knowledge contrast loss in S430 is specifically: ; in represents the cosine similarity metric function, is the temperature parameter used to control the smoothness of the distribution, is the number of positive sample pairs; The calculation formula of the cosine similarity calculation function is as follows: ; in, represents the dot product of the teacher and the student’s local knowledge blocks, represents the two-norm.

5. The method according to claim 4, characterized in that S441 is as follows: ; ; ; ; in, It is the teacher network model Global knowledge of dimensions, It is a student network model Global knowledge of dimensions, It is the teacher network model Global knowledge of dimensions, It is a student network model Global knowledge of dimensions, It is the teacher network model The local knowledge of the A local block, The student network model The local knowledge of the A local block, It is the teacher network model The local knowledge of the pixel values, The student network model The local knowledge of the pixel value; S442 is specifically: ; ; ; ; in, It is the teacher network model Dimensional global knowledge distribution, Is a student network model Dimensional global knowledge distribution, It is the teacher network model Dimensional global knowledge distribution, Is a student network model Dimensional global knowledge distribution, is the temperature coefficient, is the number of local knowledge blocks, is the size of the local knowledge block, which is used to adjust the scale range of knowledge distribution; S443 is as follows: 。 6. The method according to claim 5, characterized in that In S450, the detection loss is used to train the self-learning process of the lightweight student network model, and the contrastive learning loss and the detection loss are combined to form the total loss of the training student network model, which is specifically: ; in, and They are used to adjust the detection loss and distillation loss respectively. is the distillation loss, To detect losses; The detection loss includes classification loss, regression loss and center point prediction loss. The classification loss uses focal loss, which is: ; Where y represents the label of the actual defect category, and p represents the category predicted by the student network model. It is a hyperparameter used to adjust the size of the loss; The regression loss uses the generalized intersection-over-union loss, which is calculated as follows: ; in, represents the intersection-over-union ratio between the real annotation and the predicted box, It represents the minimum area of ​​the box that can contain both the predicted box and the true box, and U represents the joint area of ​​the predicted box and the true box; The center point prediction loss uses cross entropy loss, and the calculation formula is as follows: ; in, Represents the true centrality value, between 0 and 1, represents the centrality value predicted by the model, and N is the total number of samples; Detection loss The calculation formula is as follows: ; in, , and They are the weight coefficients used to adjust the classification loss, regression loss and center point prediction loss respectively.

Citation Information

Patent Citations

  • Unsupervised retina image segmentation method based on dual-scale full convolution reconstruction network

    CN117274602A

  • Lightweight defect detection method based on mixed multi-scale knowledge distillation

    CN118154607A