Multi-scale micro-defect detection method on workpiece surface based on PA-MLFPN
By introducing the path-augmented multi-level feature pyramid network (PA-MLFPN) into workpiece surface defect detection, the problem of insufficient performance of traditional convolutional neural networks in multi-scale and tiny defect detection is solved, achieving higher detection accuracy and leakage. reduction in detection rate.
Patent Information
- Application Number
- CN202210285543.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-22
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2042-03-22
AI Technical Summary
Traditional convolutional neural networks are difficult to effectively detect multi-scale and tiny defects in workpiece surface defect detection, especially due to the randomness and shape variability of defects, which leads to poor detection performance and poor perception of small targets.
An improved method based on multi-level feature pyramid network (MLFPN), path enhanced multi-level feature pyramid network (PA-MLFPN), is proposed. Through multi-level and multi-scale feature extraction and feature fusion modules, combined with SSD, it detects workpiece surface defects and enhances the detection of small defects. Detection capabilities of defective targets.
It improves the detection accuracy of multi-scale micro-defect targets, effectively solves the problem of missed detection of small defect targets, and improves detection performance.
Smart Images

Figure CN114638809B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a multi-scale small defect detection method on a workpiece surface based on PA-MLFPN, and belongs to the technical field of computer vision. Background Art
[0002] The task of workpiece surface defect detection is an indispensable part of workpiece production. However, due to the influence of factors such as workpiece production equipment and production process, the surface of the produced workpiece often has various types of defects such as scratches, convex powder, and abrasions. These defects not only affect the appearance, but also bury many hidden dangers for the subsequent use of the workpiece, such as accelerating the aging of the workpiece and thus affecting the service life, and even affecting the normal use of the workpiece. Therefore, it is particularly important to use appropriate defect detection technology to improve the production quality of workpieces. Traditional surface defect detection tasks are usually completed manually, but manual detection is often affected by factors such as personal subjective experience, working environment, and mental state, and thus lacks standardization. At the same time, manual methods are prone to false detection and missed detection when detecting high-speed movement or smaller defects.
[0003] With the development of deep learning, more and more target detection algorithms based on convolutional neural networks have been proposed. However, due to the characteristics of the convolutional network structure and the surface defects of workpieces, we believe that the following problems still exist in the task of completing the surface defect detection task based on convolutional neural networks: (i) The randomness of the surface defects of workpieces leads to variable defect scales. For example, two different types of defect targets may have similar sizes, but the complexity of their performance may vary greatly, or the scale changes of the same defect type may also vary greatly. However, in the traditional convolutional network model, the feature layer used to detect objects within a specific size range is mainly composed of a single-level feature layer or two adjacent layers for final detection, which will result in poor detection performance. (ii) In the actual task of surface defect detection of workpieces, defects often have more small defect targets based on their variable shapes. In the convolutional neural network, the shallow feature layer has a higher resolution and contains more location and detail information that is conducive to the detection of small targets. Deep features have stronger semantic information, but the resolution is very low and the perception of small targets is poor. Summary of the invention
[0004] The purpose of the present invention is to provide a multi-scale micro-defect detection method for workpiece surface based on PA-MLFPN to solve the problems in the prior art. A multi-level feature pyramid network (MLFPN) is selected to solve the multi-scale defect target problem by extracting multi-level and multi-scale features. And on the basis of MLFPN, an improved method is proposed for the workpiece surface defect detection task, and a path-augmentation multi-level feature pyramid network (PA-MLFPN) is proposed to further utilize shallow features, and is embedded in SSD for workpiece surface defect detection to improve the detection accuracy of multi-scale micro-defect targets.
[0005] To achieve the above object, the present invention provides the following technical solution: based on the PA-MLFPN workpiece surface multi-scale micro-defect detection method, the following steps A to D are performed to obtain a workpiece surface defect detection model, and then based on the VGG16 backbone feature extraction network to obtain a micro-defect sample image of the target workpiece, the workpiece surface defect detection model is applied to obtain the preset defect classifications corresponding to the multi-scale micro-defects in the target workpiece image;
[0006] Step A: Based on the MLFPN model, the PA-MLFPN feature extraction model is constructed with the image of a sample with small defects as input and a multi-layer feature pyramid as output;
[0007] The PA-MLFPN feature extraction model includes an FFMv1 feature fusion module, a basic feature layer, a multi-level FFMv2 feature fusion module, a multi-level improved TUM refinement U-type module, and an improved SFAM scale-based feature aggregation module. The FFMv1 feature fusion module serves as the input end of the PA-MLFPN feature extraction model. The output end of the FFMv1 feature fusion module is connected to the input end of the basic feature layer. The output end of the basic feature layer is respectively connected to the input ends of each FFMv2 feature fusion module and the input end of the first-level improved TUM refinement U-type module. The multi-level FFMv2 feature fusion module is alternately stacked and connected with the multi-level improved TUM refinement U-type module. The output end of the last-level improved TUM refinement U-type module is connected to the input end of the improved SFAM scale-based feature aggregation module. The output end of the improved SFAM scale-based feature aggregation module serves as the output end of the PA-MLFPN feature extraction model. The step of training the PA-MLFPN feature extraction model includes the following steps 101 to 104:
[0008] Step 101: Based on the FFMv1 feature fusion module, conv4_3 and conv5_3 are used as input, and the basic feature layer of multi-scale micro-defects on the surfaces of multiple workpieces is used as output, and then step 102 is entered;
[0009] Step 102: The basic feature layer of multi-scale micro-defects on the workpiece surface is input to the first-level improved TUM refinement U-type module for further feature extraction, and the basic feature maps of micro-defects of six scales output at different levels are output, and then step 103 is entered; the improved TUM refinement U-type module adopts 3×3 hole convolution with a step size of 1 and a dilated rate of (2, 2, 3, 3, 1) in the encoder part to perform feature learning, and uses an average pooling operation with a step size of 2 for downsampling, and adds an information transmission path from the shallow layer to the deep layer on the basis of the original U-type structure to interpolate the detailed position information of the shallow feature pyramid feature to the deep layer, that is, Ti is convolved with a convolution kernel size of 3×3 and a step size of 2, and the feature map size is reduced to half of the original size, that is, Conv(T i ), then and C i+1 The result is then added element by element, and then convolved with a kernel size of 3×3 and a step size of 1 to obtain T i+1 , the calculation formula is:
[0010]
[0011] Step 103: Taking the maximum feature map of the six scale basic feature maps obtained by the basic feature layer and the first-level TUM model as input, input it to the first-level FFMv2 feature fusion module to obtain the first-level fused feature map; then taking the first-level fused feature map and the basic feature layer map as input, input it to the second-level FFMv2 feature fusion module to obtain the second-level fused feature map, and alternately stacking the multi-level improved TUM refined U-type model and the FFMv2 feature fusion module by taking the first-level fused feature map and the basic feature layer map as input, and taking the second-level fused feature map as output, obtaining the shallow feature pyramid feature map, the middle feature pyramid feature map and the deep feature pyramid feature map, and then entering step 104;
[0012] Step 104: feature aggregation is performed based on the SFAM module, with the shallow feature pyramid feature map, the middle feature pyramid feature map, and the pyramid feature layer map of the same size in the deep feature pyramid feature map as input, and the multi-layer feature pyramid map as output, and then the ECA module is used to allocate weights on the channel for the obtained multi-layer feature pyramid; the specific steps of using the ECA module to allocate weights on the channel for the obtained multi-layer feature pyramid based on the SFAM module are:
[0013] Step V-1: Perform global average pooling on the feature layers of the multi-layer feature pyramid map initially aggregated by the SFAM module to obtain the weights of C channels, and then proceed to step V-2;
[0014] Step V-2: Use one-dimensional convolution with a kernel size of k to realize local cross-channel interaction information to obtain the weight coefficients of C channels, where the kernel size k is adaptively determined as a function of the number of channels C, and the calculation formula is:
[0015]
[0016] Among them, || odd It means taking the nearest odd number, and b and γ are 1 and 2 respectively. Finally, the weight coefficients of C channels are passed through the Sigmoid function to obtain C values between 0 and 1, which correspond to the weights of the original channels respectively. They are then multiplied with the multi-layer feature pyramid map for weighting and then output to obtain a multi-level feature pyramid feature map.
[0017] Step B: Based on the Prediction layer, a classification model is constructed by taking the multi-layer feature pyramid image of the micro-defect sample image as input and the preset defect classifications corresponding to the multi-scale micro-defects in the image as output;
[0018] Step C: The PA-MLFPN feature extraction model is connected first and the classification model is connected in sequence, and the input end of the classification model is connected to the output end of the PA-MLFPN feature extraction model, so as to form a detection model that takes a sample image of multi-scale tiny defects on the workpiece surface at a single defect position as input and takes the preset defect classifications corresponding to the multi-scale tiny defects in the image as output;
[0019] Step D: Based on a preset number of multi-scale tiny defect sample images on the workpiece surface each containing a single defect location, and the preset defect classifications corresponding to each multi-scale tiny defect sample image on the workpiece surface, the tiny defect sample image is used as input, and the preset defect classifications corresponding to the multi-scale tiny defects in the image are used as output, a detection model is trained to obtain a workpiece surface defect detection model.
[0020] Furthermore, the aforementioned multi-scale micro defects on the workpiece surface include preset defects such as scratch defects, convex powder defects, and abrasion defects.
[0021] Furthermore, the aforementioned PA-MLFPN-based multi-scale micro-defect detection method for workpiece surfaces also includes obtaining multi-scale micro-defect sample images of workpiece surfaces each containing a single defect position, and dividing the multi-scale micro-defect sample image data set on the workpiece surface according to a preset ratio, and dividing it into a training set, a test set, and a validation set. Specifically, on the workpiece production line, a sampling device is used to take photos and samples of each workpiece at a fixed position; the collected workpiece surface images are annotated with surface defects through labelimg, and the images annotated with Labelimg are made into a data set in VOC format; the images in the data set are enhanced through imgaug data enhancement; the enhanced data set is randomly divided with a test set ratio of 9:1 and a training set: validation set ratio of 9:1.
[0022] Furthermore, the aforementioned step A also includes fine-tuning the obtained PA-MLFPN feature extraction model, specifically:
[0023] During training, Focal loss is used to calculate the classification loss, and Smooth L1 is used to calculate the regression loss. The final loss function used is a combination of Focal loss and Smooth L1:
[0024] L=L fl +L SL1
[0025] The classification loss Focal loss calculation formula is:
[0026] Where y′ is the predicted output, y is the label of the real sample, α is the weight of positive and negative samples, θ is the weight of easy-to-classify samples and difficult-to-classify samples; the regression loss Smooth L1 calculation formula is as follows: Where x is the difference between the predicted box and the true box.
[0027] Furthermore, the aforementioned multi-scale micro-defect detection method based on PA-MLFPN workpiece surface is verified on actual samples to obtain defect classification results that meet the preset conditions, specifically:
[0028] The evaluation indicators precision P and recall R are set for model evaluation. The calculation formula is:
[0029]
[0030] TP represents the number of correctly identified defect areas, TN represents the number of correctly identified background areas, FP represents the number of correctly identified background areas as defect areas, and FN represents the number of incorrectly identified defects as background areas.
[0031] The average precision AP is set to evaluate the detection performance of the model for various types of defects on the test set. The area enclosed by the PR curve and the horizontal and vertical axes is the AP of this type of defect. The calculation formula is as follows:
[0032]
[0033] The detection results of multi-category defects are set to use the mean average precision mAP. The mAP calculation formula of the test results is as follows:
[0034]
[0035] Furthermore, in the aforementioned verification of the preset defect classification corresponding to the sample image of tiny defects, the number of loop iterations is set to 100, the batch size is first set to 32, and the learning rate is initialized to 5e-4. When the number of iterations reaches 50, the batch size is reset to 16 and the learning rate is reset to 1e-4.
[0036] Furthermore, the aforementioned actual sample verification obtains defect classification results that meet the preset conditions. The early stopping method is used during training, and the verification loss is calculated in each iteration. When the verification loss value reaches the local optimum, it is iterated for 6 more times. If the model no longer converges, the training is stopped.
[0037] The invention discloses a method for detecting multi-scale micro-defects on workpiece surfaces based on PA-MLFPN. Compared with the prior art, the above technical solution has the following technical effects: in view of the characteristics of multi-scale and micro-defects on the workpiece surface, the traditional target detection algorithm cannot perform detection well. A workpiece surface defect detection algorithm based on path-enhanced multi-level feature pyramid network (PA-MLFPN) is proposed. On the basis of extracting multi-level and multi-scale defect features, the characterization capability of small defect targets is further enhanced, the detection accuracy of targets of different scales is improved, and the problem of missed detection of small defect targets is effectively solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a process step diagram of the present invention;
[0039] Figure 2 This is the network model diagram after PA-MLFPN is embedded in the detection model;
[0040] Figure 3 This is a schematic diagram of using dilated convolution in the downsampling part;
[0041] Figure 4 It is a schematic diagram of the feature combination method of the feature enhancement path;
[0042] Figure 5 This is the improved TUM structure diagram;
[0043] Figure 6 This is the improved SFAM structure diagram;
[0044] Figure 7 It is a display diagram of the workpiece surface defect detection results. DETAILED DESCRIPTION
[0045] In order to better understand the technical content of the present invention, specific embodiments are given and described as follows in conjunction with the accompanying drawings.
[0046] like Figure 1 As shown, the process steps of the present invention are as follows: the first step is to collect the surface defect image of the workpiece.
[0047] The second step is to label defects and perform data enhancement to construct a workpiece surface defect dataset. Specifically, on the workpiece production line, a sampling device is used to take photos and samples of each workpiece at a fixed position to construct a workpiece surface defect dataset. The collected workpiece surface images are annotated with surface defects through labelimg. The workpiece surface defect dataset is divided into training set, test set and validation set according to the preset ratio, and the images that have been surface-annotated by Labelimg are made into a VOC format dataset; the images in the dataset are enhanced through imgaug data enhancement; the enhanced dataset is randomly divided with a ratio of (training set + validation set): test set of 9:1 and a ratio of training set: validation set of 9:1.
[0048] The third step is to build PA-MLFPN. Based on the MLFPN model, the PA-MLFPN feature extraction model is constructed with the image of a sample with tiny defects as input and the multi-layer feature pyramid image of the sample image with tiny defects as output.
[0049] The fourth step is to build a classification model based on the prediction layer, taking the multi-layer feature pyramid image of the tiny defect sample image as input and the preset defect classification corresponding to the multi-scale tiny defects in the image as output;
[0050] The fifth step is to obtain a sample image of a tiny defect of the target workpiece based on the VGG16 backbone feature extraction network, and connect the PA-MLFPN feature extraction model first and the classification model later in sequence, and connect the input end of the classification model to the output end of the PA-MLFPN feature extraction model, so as to form a detection model that takes the sample image of multi-scale tiny defects on the workpiece surface at a single defect position as input and takes the preset defect classifications corresponding to the multi-scale tiny defects in the image as output;
[0051] The sixth step is to train the detection model based on a preset number of multi-scale micro-defect sample images of workpiece surfaces each containing a single defect location, and the preset defect classifications corresponding to each multi-scale micro-defect sample image on the workpiece surface, with the micro-defect sample image as input and the preset defect classifications corresponding to the multi-scale micro-defects in the image as output, to obtain a workpiece surface defect detection model.
[0052] like Figure 2 As shown in the figure, based on the VGG16 network model, the defect image is used as input, and the conv4_3 and conv5_3 feature layers in VGG16 are used as output to construct a backbone feature extraction network. The network model is formed by connecting PA-MLFPN first and the Prediction layer later in series; the PA-MLFPN model includes the FFMv1 feature fusion module, the basic feature layer, the multi-level FFMv2 feature fusion module, the multi-level improved TUM refinement U-shaped module, and the improved SFAM scale-based feature aggregation module. The conv4_3 and conv5_3 are initially fused by FFMv1 to obtain the basic feature layer (Basefeature) for the next series of further feature fusions.
[0053] The FFMv1 feature fusion module serves as the input end of the PA-MLFPN model, the output end of the FFMv1 feature fusion module is connected to the input end of the basic feature layer, the output end of the basic feature layer is respectively connected to the input end of each FFMv2 feature fusion module and the input end of the first-level improved TUM refinement U-type module, the multi-level FFMv2 feature fusion module is alternately stacked and connected with the multi-level improved TUM refinement U-type module, the output end of the last-level improved TUM refinement U-type module is connected to the input end of the improved SFAM scale-based feature aggregation module, and the output end of the improved SFAM scale-based feature aggregation module serves as the output end of the PA-MLFPN model; the step of training the PA-MLFPN model includes the following steps 101 to 104:
[0054] Step 101: Based on the FFMv1 feature fusion module, conv4_3 and conv5_3 are used as input, and the basic feature layer of multi-scale micro-defects on the surfaces of multiple workpieces is used as output, and then step 102 is entered;
[0055] Step 102: Taking the basic feature layer of multi-scale micro-defects on the workpiece surface as input, input it to the first-level improved TUM refinement U-shaped module for further feature extraction, and taking the basic feature maps of micro-defects of six scales output at different levels as output, and then entering step 103;
[0056] Step 103: specifically, the maximum feature map among the six scale basic feature maps obtained by the basic feature layer and the first-level TUM model is used as input, and is input to the first-level FFMv2 feature fusion module to obtain the first-level fused feature map; then the first-level fused feature map and the basic feature layer map are used as input, and are input to the second-level FFMv2 feature fusion module to obtain the second-level fused feature map, and the first-level fused feature map and the basic feature layer map are used as input in a manner of alternately stacking multi-level improved TUM refinement U-type models and FFMv2 feature fusion modules, and the second-level fused feature map is used as output to obtain a shallow feature pyramid feature map, a middle feature pyramid feature map, and a deep feature pyramid feature map, and then enter step 104;
[0057] Step 104: Perform feature aggregation based on the SFAM module, take the pyramid feature layer map of the same size in the shallow feature pyramid feature map, the middle feature pyramid feature map, and the deep feature pyramid feature map as input, and take the multi-layer feature pyramid map as output, and then use the ECA module to allocate weights on the channel for the obtained multi-layer feature pyramid.
[0058] Then, the multi-layer feature pyramid image of the tiny defect sample image is used as input, and the defect classifications corresponding to the multi-scale tiny defects in the image are used as output. This is input into the Prediction layer to obtain the defect classifications corresponding to the tiny defects on the workpiece surface.
[0059] like Figure 3 As shown in the figure, the downsampling part uses a schematic diagram of a dilated convolution. In the encoder part of the TUM refined U-type model, a 3×3 dilated convolution with a step size of 1 and a dilated rate of (2, 2, 3, 3, 1) is used for feature learning, and an average pooling operation with a step size of 2 is used for downsampling.
[0060] like Figure 4 As shown in the figure, the feature combination method of the feature enhancement path is to add an information transmission path from the shallow layer to the deep layer on the basis of the original U-shaped structure to interpolate the detail position information of the shallow feature pyramid feature to the deep layer, that is, Ti is convolved with a convolution kernel size of 3×3 and a step size of 2, and the feature map size is reduced to half of the original size, that is, Conv(Ti), and then added element by element with Ci+1. The result is then convolved with a convolution kernel size of 3×3 and a step size of 1 to obtain Ti+1. The calculation formula is:
[0061]
[0062] like Figure 5As shown in the figure, the improved TUM structure, the TUM refinement U-shaped module uses 3×3 dilated convolution with a step size of 1 and dilated rates set to (2, 2, 3, 3, 1) in the encoder part for feature learning, and uses an average pooling operation with a step size of 2 for downsampling. By setting different dilated rates to obtain receptive fields of different sizes to obtain multi-scale information, it avoids information loss in the process of continuous convolution of downsampling to retain more shallow defect target information. On this basis, a 1×1 convolution with a step size of 1 and a channel number of 128 is further performed to adjust the number of channels and output.
[0063] like Figure 6 As shown in the figure, the structure of the improved SFAM; the specific process of using the ECA module in the second stage of the improved SFAM module is as follows: the ECA module is introduced to perform a one-dimensional convolution of size k to replace the two fully connected layers, where k is adaptively determined by the function of the number of channels C. This not only avoids the dimensionality reduction operation, but also interacts with local cross-channel information through one-dimensional convolution of adaptive size. Specifically, for the feature layer initially aggregated in the first stage of SFAM, global average pooling is first performed to obtain the weight of each channel. If there are C channels, a total of C channel weights are obtained.
[0064] Then, a one-dimensional convolution of size k is used to realize local cross-channel interaction information to obtain weights, where the kernel size k needs to be adaptively determined:
[0065] Among them, || odd Indicates taking the nearest odd number, and b and γ are 1 and 2 respectively in the experiment. Finally, the output of the previous step is passed through the Sigmoid function to obtain C values between 0 and 1, which correspond to the weights of the original channels respectively, and multiplied by the input features for weighting and then output.
[0066] The constructed model is fine-tuned on the workpiece surface defect dataset. Specifically, during training, Focal loss is used to calculate the classification loss, and Smooth L1 is used to calculate the regression loss. The final loss function used is a combination of Focalloss and Smooth L1: L = L fl +L SL1 , classification loss Focal loss
[0067] The calculation formula is:
[0068] Where y is the predicted output, y is the label of the real sample, α is the weight of positive and negative samples, and θ is the weight of easy-to-classify samples and difficult-to-classify samples. The regression loss Smooth L1 calculation formula is as follows:
[0069] Where x is the difference between the predicted box and the true box.
[0070] In order to evaluate the performance of the algorithm proposed in this paper, the relevant evaluation indicators precision (Precision, P) and recall (Recall, R) are used for model evaluation.
[0071] Among them, TP, TN and FP represent the number of defects correctly identified, the number of background areas correctly identified and the number of background areas misidentified as defects respectively:
[0072] Average Precision (AP) is used to evaluate the detection performance of the model for various types of defects on the test set, as shown in the following formula. The area enclosed by the PR curve and the horizontal and vertical axes is the AP of this type of defect: The detection results of multiple categories of defects are evaluated by mean Average Precision (mAP). The test result mAP of the present invention is shown as follows:
[0073] The transfer learning method is used to train the network. The weight file is obtained by pre-training on the VOC dataset, and then fine-tuning is performed on the workpiece surface defect dataset.
[0074] The number of loop iterations is set to 100. First, the batch size is set to 32 and the learning rate is initialized to 5e-4. When the number of iterations reaches 50, the batch size is reset to 16 and the learning rate is reset to 1e-4. In addition, early stopping is used during training to avoid overfitting caused by continued training. The validation loss is calculated for each iteration. When the validation loss value reaches the local optimum, it is iterated for 6 more times. If the model no longer converges, the training is stopped.
[0075] Figure 7 During the specific implementation, the image of a sample with tiny defects is input to obtain the surface defect detection results of the workpiece, specifically scratch defects, convex powder defects, and abrasion defects.
[0076] Various aspects of the invention are described herein with reference to the accompanying drawings, in which many illustrative embodiments are shown. The embodiments of the invention are not limited to those shown in the accompanying drawings. It should be understood that the invention is implemented by any of the various concepts and embodiments described above, as well as the concepts and embodiments described in detail, because the concepts and embodiments disclosed in the invention are not limited to any implementation. In addition, some aspects disclosed in the invention may be used alone or in any appropriate combination with other aspects disclosed in the invention.
[0077] Although the present invention has been disclosed as above with preferred embodiments, it is not intended to limit the present invention. A person with ordinary knowledge in the technical field to which the present invention belongs may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be determined by the definition of the claims.
[0078] The invention discloses a method for detecting multi-scale micro-defects on workpiece surfaces based on PA-MLFPN. Compared with the prior art, the above technical solution has the following technical effects: in view of the characteristics of multi-scale and micro-defects on the workpiece surface, the traditional target detection algorithm cannot perform detection well. A workpiece surface defect detection algorithm based on path-enhanced multi-level feature pyramid network (PA-MLFPN) is proposed. On the basis of extracting multi-level and multi-scale defect features, the characterization capability of small defect targets is further enhanced, the detection accuracy of targets of different scales is improved, and the problem of missed detection of small defect targets is effectively solved.
Claims
1. A multi-scale micro-defect detection method on workpiece surface based on PA-MLFPN, characterized in that: Perform the following steps A to D to obtain a workpiece surface defect detection model, and then apply the workpiece surface defect detection model based on a sample image of a small defect of a target workpiece obtained by a VGG16 backbone feature extraction network to obtain preset defect classifications corresponding to multi-scale small defects in the target workpiece image; Step A: Based on the MLFPN model, the PA-MLFPN feature extraction model is constructed with the image of a sample with small defects as input and a multi-layer feature pyramid as output; The PA-MLFPN feature extraction model includes an FFMv1 feature fusion module, a basic feature layer, a multi-level FFMv2 feature fusion module, a multi-level improved TUM refinement U-type module, and an improved SFAM scale-based feature aggregation module. The FFMv1 feature fusion module serves as the input end of the PA-MLFPN feature extraction model. The output end of the FFMv1 feature fusion module is connected to the input end of the basic feature layer. The output end of the basic feature layer is respectively connected to the input ends of each FFMv2 feature fusion module and the input end of the first-level improved TUM refinement U-type module. The multi-level FFMv2 feature fusion module is alternately stacked and connected with the multi-level improved TUM refinement U-type module. The output end of the last-level improved TUM refinement U-type module is connected to the input end of the improved SFAM scale-based feature aggregation module. The output end of the improved SFAM scale-based feature aggregation module serves as the output end of the PA-MLFPN feature extraction model. The step of training the PA-MLFPN feature extraction model includes the following steps 101 to 104: Step 101: Based on the FFMv1 feature fusion module, conv4_3 and conv5_3 are used as input, and the basic feature layer of multi-scale micro-defects on the surfaces of multiple workpieces is used as output, and then step 102 is entered; Step 102: The basic feature layer of multi-scale micro-defects on the workpiece surface is input to the first-level improved TUM refinement U-type module for further feature extraction, and the basic feature maps of micro-defects of six scales output at different levels are output, and then step 103 is entered; the improved TUM refinement U-type module adopts 3×3 hole convolution with a step size of 1 and a dilated rate of (2, 2, 3, 3, 1) in the encoder part to perform feature learning, and uses an average pooling operation with a step size of 2 for downsampling, and adds an information transmission path from the shallow layer to the deep layer on the basis of the original U-type structure to interpolate the detailed position information of the shallow feature pyramid feature to the deep layer, that is, Ti is convolved with a convolution kernel size of 3×3 and a step size of 2, and the feature map size is reduced to half of the original size, that is, Conv(T i ), then and C i+1 The result is then added element by element, and then convolved with a kernel size of 3×3 and a step size of 1 to obtain T i+1 , the calculation formula is: Step 103: Taking the maximum feature map of the six scale basic feature maps obtained by the basic feature layer and the first-level improved TUM refinement U-type module as input, input it to the first-level FFMv2 feature fusion module to obtain the first-level fused feature map; then taking the first-level fused feature map and the basic feature layer map as input, input it to the second-level FFMv2 feature fusion module to obtain the second-level fused feature map, and taking the first-level fused feature map and the basic feature layer map as input in a manner of alternately stacking multi-level improved TUM refinement U-type models and FFMv2 feature fusion modules, and taking the second-level fused feature map as output, obtain the shallow feature pyramid feature map, the middle feature pyramid feature map and the deep feature pyramid feature map, and then enter step 104; Step 104: feature aggregation is performed based on the SFAM module, with the shallow feature pyramid feature map, the middle feature pyramid feature map, and the pyramid feature layer map of the same size in the deep feature pyramid feature map as input, and the multi-layer feature pyramid map as output, and then the ECA module is used to allocate weights on the channel for the obtained multi-layer feature pyramid; the specific steps of using the ECA module to allocate weights on the channel for the obtained multi-layer feature pyramid based on the SFAM module are: Step V-1: Perform global average pooling on the feature layers of the multi-layer feature pyramid map initially aggregated by the SFAM module to obtain the weights of C channels, and then proceed to step V-2; Step V-2: Use one-dimensional convolution with a kernel size of k to realize local cross-channel interaction information to obtain the weight coefficients of C channels, where the kernel size k is adaptively determined as a function of the number of channels C, and the calculation formula is: Among them, || odd It means taking the nearest odd number, and b and γ are 1 and 2 respectively. Finally, the weight coefficients of C channels are passed through the Sigmoid function to obtain C values between 0 and 1, which correspond to the weights of the original channels respectively. They are then multiplied with the multi-layer feature pyramid map for weighting and then output to obtain a multi-level feature pyramid feature map. Step B: Based on the Prediction layer, a classification model is constructed by taking the multi-layer feature pyramid image of the micro-defect sample image as input and the preset defect classifications corresponding to the multi-scale micro-defects in the image as output; Step C: The PA-MLFPN feature extraction model is connected first and the classification model is connected in sequence, and the input end of the classification model is connected to the output end of the PA-MLFPN feature extraction model, so as to form a detection model that takes a sample image of multi-scale tiny defects on the workpiece surface at a single defect position as input and takes the preset defect classifications corresponding to the multi-scale tiny defects in the image as output; Step D: Based on a preset number of multi-scale tiny defect sample images on the workpiece surface each containing a single defect location, and the preset defect classifications corresponding to each multi-scale tiny defect sample image on the workpiece surface, the tiny defect sample image is used as input, and the preset defect classifications corresponding to the multi-scale tiny defects in the image are used as output, a detection model is trained to obtain a workpiece surface defect detection model.
2. The method for detecting multi-scale micro-defects on workpiece surface based on PA-MLFPN according to claim 1, characterized in that: The preset defects included in the multi-scale tiny defects on the workpiece surface include scratch defects, convex powder defects, and abrasion defects.
3. The method for detecting multi-scale micro-defects on workpiece surface based on PA-MLFPN according to claim 1, characterized in that: It also includes obtaining multi-scale micro-defect sample images of workpiece surfaces each containing a single defect position, and dividing the multi-scale micro-defect sample image data set on the workpiece surface into a training set, a test set, and a validation set according to a preset ratio. Specifically, on the workpiece production line, a sampling device is used to take photos and samples of each workpiece at a fixed position; the collected workpiece surface images are annotated with surface defects through labelimg, and the images annotated with the surface through Labelimg are made into a data set in VOC format; the images in the data set are enhanced through imgaug data enhancement; the enhanced data set is randomly divided with a ratio of training set + validation set: test set of 9:1 and a ratio of training set: validation set of 9:
1.
4. The method for detecting multi-scale micro-defects on workpiece surface based on PA-MLFPN according to claim 1, characterized in that: Step A also includes fine-tuning the obtained PA-MLFPN feature extraction model, specifically: During training, Focal loss is used to calculate the classification loss, and Smooth L1 is used to calculate the regression loss. The final loss function used is a combination of Focal loss and Smooth L1: L=L fl +L SL1 The classification loss Focal loss calculation formula is: Where y′ is the predicted output, y is the label of the real sample, α is the weight of positive and negative samples, θ is the weight of easy-to-classify samples and difficult-to-classify samples; the regression loss Smooth L1 calculation formula is as follows: Where x is the difference between the predicted box and the true box.
5. The method for detecting multi-scale micro-defects on workpiece surface based on PA-MLFPN according to claim 1, characterized in that: The defect classification results that meet the preset conditions are obtained by verifying the actual samples, specifically: The evaluation indicators precision P and recall R are set for model evaluation. The calculation formula is: TP represents the number of correctly identified defect areas, TN represents the number of correctly identified background areas, FP represents the number of correctly identified background areas as defect areas, and FN represents the number of incorrectly identified defects as background areas. The average precision AP is set to evaluate the detection performance of the model for various types of defects on the test set. The area enclosed by the PR curve and the horizontal and vertical axes is the AP of this type of defect. The calculation formula is as follows: The detection results of multiple categories of defects are set to use the mean average precision mAP. The mAP calculation formula of the test results is as follows: 。 6. The method for detecting multi-scale micro-defects on workpiece surface based on PA-MLFPN according to claim 1, characterized in that: In the verification of the preset defect classification corresponding to the sample image of tiny defects, the number of loop iterations is set to 100. First, the batch size is set to 32 and the learning rate is initialized to 5e-4. When the number of iterations reaches 50, the batch size is reset to 16 and the learning rate is reset to 1e-4.
7. The method for detecting multi-scale micro-defects on workpiece surface based on PA-MLFPN according to claim 1, characterized in that: The defect classification results that meet the preset conditions are obtained by actual sample verification. The early stopping method is used during training, and the verification loss is calculated in each iteration. When the verification loss value reaches the local optimum, it is iterated for 6 more times. If the model no longer converges, the training is stopped.
