A surface defect detection method based on feature pre-fusion and mask guidance

By constructing a surface defect detection method based on feature pre-fusion and mask guidance, the shortcomings of existing algorithms in detecting defects with low discrimination and small scale are solved, achieving high-precision and robust defect detection, which is suitable for surface defect detection of industrial products.

CN116805310BActive Publication Date: 2025-12-26CENT SOUTH UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311034675.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-17
Publication Date
2025-12-26
Estimated Expiration
2043-08-17

AI Technical Summary

Technical Problem

Existing deep learning-based defect detection algorithms perform poorly in detecting low-resolution and small-scale surface defects, failing to meet the high-precision quality inspection requirements of modern industry.

Method used

A surface detection method guided by feature prefusion and mask was designed. By constructing a model, including a backbone network BoneNet, a feature prefusion module FPF, and a multi-stage fusion module MSF, information diffusion between multi-scale feature maps and improvement of information density in defect regions are achieved. The information diffusion module ID and the semantic interaction module CCBM are used for weighted splicing and fusion of feature maps, and the final detection is performed in conjunction with the detection header.

Benefits of technology

It improves the detection accuracy for defects with low discrimination and small scale, generates high-precision defect detection results, and enhances the robustness and applicability of the algorithm.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116805310B_ABST
    Figure CN116805310B_ABST
Patent Text Reader

Abstract

The application discloses a surface defect detection method based on feature pre-fusion and mask guidance, and mainly solves the problem of low detection accuracy of weak distinguishability and small scale defects in the prior art. The implementation scheme is as follows: 1) obtaining a data set and a detection label; 2) constructing a defect detection model; 3) constructing a loss function; 4) training the defect detection model; and 5) reasoning and obtaining a detection result. The surface defect detection model constructed by the application realizes the expansion of the receptive field and the information diffusion through the feature pre-fusion, enhances the context within the feature map, and effectively improves the detection accuracy of weak distinguishability defects. The mask label of the defect boundary box is introduced through multi-stage feature fusion, so that the information density of the defect area is increased, and the detection accuracy of small scale defects is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of image processing, and particularly relates to a surface defect detection method based on feature pre-fusion and mask guidance. BACKGROUND

[0002] In the industrial production process, due to the deficiency of the production process, various defects may appear on the surface of the product. In order to ensure the product quality, the surface defect detection of the industrial product is needed. In the current production link, the industrial product quality inspection mainly depends on manual work. Since the manual detection has strong subjectivity, low efficiency and poor consistency, it cannot meet the requirements of modern industry for high-speed and high-precision quality inspection. The industrial product surface defect detection using the algorithm based on computer vision is a feasible scheme that can meet the requirements of modern industry. The traditional defect detection algorithm based on computer vision relies on manual prior information to design the model structure and parameters to complete the defect detection. This traditional algorithm is difficult to obtain accurate and universal feature templates, which leads to poor robustness of the algorithm and limited application range, so it has been gradually replaced by the method of deep learning. The defect detection algorithm based on deep learning converts the defect detection problem into a target detection problem to realize the recognition and positioning of defects. The existing deep learning method has poor detection effect on low distinguishability and small scale surface defects, and cannot meet the defect detection requirements in special industrial scenes. SUMMARY

[0003] The application fully considers the shortcomings of the existing method, and aims to provide a surface defect detection method based on feature pre-fusion and mask guidance. Through the information diffusion and mask guidance, the multi-scale context enhancement and defect area information density improvement are realized to generate high-precision defect detection results.

[0004] I. Technical principle

[0005] Most of the current neural network-based defect detection algorithms use a target detection framework to complete the algorithm construction to realize the recognition and positioning of defects. The target detection algorithm extracts features from the input image through BoneNet, realizes multi-scale feature fusion by the Neck structure, and finally realizes the positioning and recognition of the target by the Header. The low differentiation and small scale surface defects existing in industrial products are the pain points of defect detection, and the general target detection algorithm is difficult to accurately position and recognize them. In order to realize high-precision surface defect detection, the present application designs a feature pre-fusion module (FPF) to connect the BoneNet and the Neck in the target detection algorithm, to realize the information diffusion between the multi-scale feature maps, to enhance the context in the feature map, and to assist the algorithm to better complete the detection of low-differentiation defects. In view of the problem of small defect size, the present application designs a multi-stage feature fusion module (MSF) as the Neck. The module realizes the prediction of the defect bounding box and the prediction of the bounding box mask through staged feature fusion. The bounding box mask generated in the first stage will guide the second stage feature fusion to improve the information density of the defect area, and ensure that the small scale defects are accurately detected.

[0006] II. According to the above principle, the present application is realized by the following scheme:

[0007] A surface defect detection method based on feature pre-fusion and mask guidance, comprising the following steps:

[0008] (1) Obtain the data set and detection label:

[0009] Obtain the surface defect data set and the corresponding detection label;

[0010] (2) Construct a defect detection model: the model is composed of a backbone network BoneNet, a feature pre-fusion module FPF, a multi-stage fusion module MSF, and a detection head Header. The specific construction process includes the following steps:

[0011] (2-a) Construct the backbone network BoneNet: take DarkNet53-CSP as the backbone network. The input image is processed by the backbone network to obtain three feature maps f1, f2 and f3 of different scales, wherein f1 represents the smallest scale feature map, and f3 represents the largest scale feature map;

[0012] (2-b) Construct the feature pre-fusion module FPF: the module is composed of three receptive field modules RFB and three information diffusion modules ID; the feature maps f1, f2 and f3 obtained in step (2-a) are taken as the inputs of the three receptive field modules RFB, respectively, to obtain the processing results and , and the feature map group together into the first information diffusion module ID1 to obtain an output result After up-sampling processing, the feature map group together into the second information diffusion module ID2 to obtain an output result After up-sampling processing, the feature map group together into the third information diffusion module ID3 to obtain an output result

[0013] The information diffusion module ID is constructed as follows:

[0014] The input of the information diffusion module includes a reference feature map and a feature map group wherein and respectively represent feature maps of three different scales; and After processing by the sampling layer, feature maps of the same scale as the reference feature map are obtained and After pixel-by-pixel multiplication with the reference feature map respectively, weighted feature maps are obtained In the channel dimension, splicing is performed, and the splicing result is processed by the first semantic interaction module CCBM1 to obtain an intermediate feature f mid ; f mid and the weighted feature map In the channel dimension, splicing is performed, and the splicing result is processed by the second semantic interaction module CCBM2 to obtain an output result f id of the information diffusion module ID; the input of the semantic interaction module CCBM in this step is sequentially processed by the channel attention module, the convolution layer, the normalization layer and the Mish activation function to obtain the output result of the module;

[0015] In the first information diffusion module ID1, takes as the input reference feature map; in the second information diffusion module ID2, takes the up-sampling result of as the input reference feature map; in the third information diffusion module ID3, takes the up-sampling result of as the input reference feature map; the three information diffusion modules all take as the input feature map group ​​​​​

[0016] (2-c) Constructing the Multi-Stage Fusion Module (MSF): The feature map generated by the Feature Pre-fusion Module (FPF) in step (2-b) is used to... and The feature maps are split along the channel dimension in a 1:N ratio to generate two sets of feature maps. and Where N is a positive integer, and N∈[1,2048]; the first set of feature maps After processing by the first bidirectional feature pyramid module FPNPAN1, an initial fused multi-scale feature map set is generated. The initial fusion feature map with the largest scale is selected. The mask prediction result is obtained after processing by the convolution module; initial fusion of multi-scale feature map groups. The three feature maps and the second set of feature maps The three feature maps in the image are concatenated along the channel dimension according to different scales to obtain... and Will and After being input together into the second bidirectional feature pyramid module FPNPAN2, the final fusion result of the multi-stage fusion module MSF is obtained. and

[0017] (2-d) Constructing the Detection Header: The detection head consists of three convolutional modules with the same structure. Each convolutional module consists of a convolutional layer and a ReLU activation function. The final fusion result generated by the multi-stage fusion module MSF in step (2-c) is then used. and The results are processed by three convolutional modules, and the final detection result is obtained by merging the results.

[0018] (3) Construct the loss function:

[0019] Construct the following hybrid loss function L mix :

[0020] L mix =L mask +L OD

[0021] Where L mask L is the loss between the mask prediction result and the mask label. OD L represents the loss between the target detection result and the target detection label. mask The structure is as follows:

[0022] L mask =LBCE_mask +L iou_mask

[0023] where L BCE_mask is the binary cross-entropy loss between the mask prediction and the mask label, L iou_mask is the IoU loss between the prediction box and the ground truth box, respectively defined as:

[0024]

[0025]

[0026] where P represents the mask prediction map, Gt represents the mask label map, both of which have the same size, H represents the height of the map, W represents the width of the map, P i,j and Gt i,j represent the pixel value of the (i, j) point in P and Gt, respectively, P i,j is a real number and P i,j ∈(0, 1), Gt i,j is an integer and Gt i,j ∈[0,1], log(·) represents the natural logarithm, represents the pixel-wise addition operation, represents the pixel-wise multiplication operation, and |·| represents the sum of all pixels in the image.

[0027] In this step, L OD is constructed as follows:

[0028] L OD = L iou_box + L BCE_obj + L CE_cls

[0029] where L iou_box is the IOU loss between the prediction box and the ground truth box, L BCE_obj is the confidence loss of the prediction box, and L BCE_cls is the class loss of the prediction box, respectively defined as:

[0030]

[0031] L BCE _ obj =-(ylog(conf)+(1-y)log(1-conf))

[0032]

[0033] box1 represents a prediction box, box2 represents a real box, area_inter(·) represents an intersection area, area_union(·) represents a union area, y represents a confidence label, conf represents a confidence prediction value, p k represents a class label of a defect, cls k represents a class prediction value of a defect; n is a positive integer, representing the number of defect classes, and log(·) represents a natural logarithm;

[0034] (4) Training a defect detection model:

[0035] The defect detection model constructed in step (2) is trained using the data set obtained in step (1); the mixed loss function L mix The error between the prediction result output by the model and the label is calculated; during the training process, the Adam algorithm is used to update the model parameters, and L-2 regularization is used as a constraint; after E epochs of training, a trained surface defect detection model is obtained, where E is a positive integer, and E [1, 10000];

[0036] (5) Inference and obtaining a detection result:

[0037] After the test image is normalized, it is input into the trained defect detection model, and the model output result is subjected to non-maximum suppression to obtain the final defect detection result.

[0038] In step (2-c), N is preferably 7;

[0039] In step (4), E is preferably 30.

[0040] Compared with the prior art, the present application has the following advantages:

[0041] (1) The feature pre-fusion module constructed in the present application increases the receptive field through the RFB module, and at the same time, the information diffusion module ID diffuses the multi-scale feature information in the form of weighting multi-scale features based on the reference feature, enhances the context information within the feature map, and improves the detection accuracy of the algorithm for low-differentiation defects.

[0042] (2) The multi-stage fusion module MSF constructed in the present application provides fusion features for the prediction of defect bounding boxes and the prediction of bounding mask through two-stage feature fusion, the fusion features provided in the first stage are guided by the mask label and added to the second stage feature fusion, so that the second stage feature fusion process pays more attention to the defect target, improves the information density of the defect region, and makes the detection result of the algorithm for small-scale defects more accurate. BRIEF DESCRIPTION OF DRAWINGS

[0043] Figure 1A surface defect detection method based on feature pre-fusion and mask guidance according to an embodiment of the present application;

[0044] Figure 2 A defect detection model structure diagram according to an embodiment of the present application;

[0045] Figure 3 An information diffusion module ID structure diagram according to an embodiment of the present application;

[0046] Figure 4 A semantic interaction module CCBM structure diagram according to an embodiment of the present application;

[0047] Figure 5 A surface defect detection method result comparison diagram with other method detection results according to an embodiment of the present application. DETAILED DESCRIPTION

[0048] The specific embodiments of the present application are described below:

[0049] Embodiment 1

[0050] Figure 1 A surface defect detection method flow chart based on feature pre-fusion and mask guidance according to an embodiment of the present application is shown, and the specific steps are as follows:

[0051] Step 1, obtain the data set and detection label.

[0052] Obtain the surface defect data set and the corresponding detection label.

[0053] Step 2, construct a defect detection model, which is composed of a backbone network BoneNet, a feature pre-fusion module FPF, a multi-stage fusion module MSF, and a detection head Header.

[0054] Figure 2 A surface defect detection model structure diagram constructed according to an embodiment of the present application is shown, and the specific steps are as follows:

[0055] (2-a) Construct the backbone network BoneNet: take DarkNet53-CSP as the backbone network, and the input image with a size of 3x352x352 is processed by the backbone network to obtain feature maps f1, f2 and f3 with scales of 512x11x11, 256x22x22 and 128x44x44.

[0056] (2-b) constructing a feature pre-fusion module FPF: the module is composed of three receptive field modules RFB and three information diffusion modules ID; the feature maps f1, f2 and f3 obtained in step (2-a) are taken as the inputs of the three receptive field modules RFB respectively, and the processing results with scales of 128×11×11, 128×22×22 and 128×44×44 are obtained With the feature map group is input into the first information diffusion module ID1 to obtain an output result with a scale of 128×11×11 With the feature map group is input into the second information diffusion module ID2 to obtain an output result with a scale of 128×22×22 With the feature map group is input into the third information diffusion module ID3 to obtain an output result with a scale of 128×44×44

[0057] The information diffusion module ID is constructed as follows:

[0058] Figure 3 The information diffusion module structure diagram in the overall model of the embodiment of the application is shown, the input of the information diffusion module includes a reference feature map with a scale of 128×W×H and a feature map group wherein and respectively represent the feature maps with scales of 128×11×11, 128×22×22 and 128×44×44; and after processing by the sampling layer, the feature maps with scales of 128×W×H are obtained and and after pixel-by-pixel multiplication with the reference feature map respectively, the weighted feature maps with a scale of 128×W×H are obtained and and the channel dimension is spliced, and the splicing result is processed by the first semantic interaction module CCBM1 to obtain the intermediate feature f with a scale of 128×W×H mid ;f mid and the weighted feature map ​The concatenation is performed along the channel dimension. After the concatenation result is processed by the second semantic interaction module CCBM2, the output result f of the information diffusion module ID with a scale of 128×W×H is obtained. id ;

[0059] In the first information dissemination module ID1, with The baseline feature map is used as input, where both H and W are 11; in the second information diffusion module ID2, with The upsampling result is used as the input baseline feature map, where H and W are both 22; in the third information diffusion module ID3, the upsampling result is used as the input baseline feature map. The upsampling result is used as the input baseline feature map, where H and W are both 44; all three information diffusion modules are based on... The feature map set as its input

[0060] Figure 4 The diagram shown is a structural diagram of the semantic interaction module in the overall model of the embodiment of the present invention. The input of the semantic interaction module is processed sequentially through the channel attention module, the convolutional layer with a kernel size of 3×3, the normalization layer and the Mish activation function to obtain the output result of the module.

[0061] (2-c) Constructing the Multi-Stage Fusion Module (MSF): The feature map generated by the Feature Pre-fusion Module (FPF) in step (2-b) is used to... and The channels are segmented in a 1:N ratio, generating two sets of feature maps with scales of (16×11×11, 16×22×22, 16×44×44) and (112×11×11, 112×22×22, 112×44×44) respectively. and First set of feature maps After processing by the first bidirectional feature pyramid module FPNPAN1, a preliminary fusion multi-scale feature map set with scales of (16×11×11, 16×22×22, 16×44×44) is generated. The initial fusion feature map with the largest scale is selected. After processing by the convolutional module, a mask prediction result with a scale of 1×44×44 is obtained. This convolutional module consists of a convolutional layer with a kernel size of 3×3 and a ReLU activation function; the initial fusion of multi-scale feature maps is then performed. The three feature maps and the second set of feature maps The three feature maps are stitched together along the channel dimension according to different scales, resulting in stitched results with scales of 128×11×11, 128×22×22, and 128×44×44 respectively. and After being input into the second bidirectional feature pyramid module FPNPAN2, the final fusion results with scales of 128x11x11, 128x22x22 and 128x44x44 are obtained In the embodiment, N is 7.

[0062] (2-d) Constructing the detection header Header: The detection header is composed of three convolution modules, and the three convolution modules have the same structure. Each convolution module is composed of a convolution layer with a convolution kernel size of 3x3 and a Relu activation function. The final fusion result generated by the multi-stage fusion module MSF in step (2-c) is input into the three convolution modules respectively, and the processing results are combined to obtain the final detection result.

[0063] Step 3, constructing a loss function:

[0064] The following hybrid loss function L is constructed mix :

[0065] L mix = L mask + L OD

[0066] Wherein L mask is the loss between the mask prediction result and the mask label, L OD is the loss between the target detection result and the target detection label, and L mask is constructed as follows:

[0067] L mask = L BCE_mask + L iou_mask

[0068] Wherein L BCE_mask is the binary cross entropy loss between the mask prediction result and the mask label, and L iou_mask is the intersection over union loss between the mask prediction result and the mask label, which are defined as follows:

[0069]

[0070]

[0071] Wherein P represents the mask prediction graph, Gt represents the mask label graph, and the sizes of P and Gt are the same, H represents the height of the graph, W represents the width of the graph, P i,j and Gt i,j represent the pixel values of (i,j) points in P and Gt respectively, P​​​​​i,j is a real number and P i,j ∈(0, 1), Gt i,j is an integer and Gt i,j ∈[0, 1], log(·) represents taking the natural logarithm, represents a pixel-wise addition operation, represents a pixel-wise multiplication operation, and |·| represents taking the sum of all pixels in an image.

[0072] In this step, L OD is constructed as follows:

[0073] L OD = L iou_box + L BCE_obj + L CE_cls

[0074] where L iou _ box is the IOU loss between the predicted box and the real box, L BCE_obj is the confidence loss of the predicted box, and L BCE_cls is the class loss of the predicted box, which are defined as follows, respectively:

[0075]

[0076] L BCE_obj = -(yloy(conf) + (1-y)log(1-conf))

[0077]

[0078] box1 represents the predicted box, box2 represents the real box, area_inter((·() represents taking the intersection area, area_union((·() represents taking the union area, y represents the confidence label, conf represents the confidence prediction value, p k represents the class label of the defect, cls k represents the class prediction value of the defect; n is a positive integer, representing the number of defect classes, and log(·) represents taking the natural logarithm.

[0079] Step 4, training the detection model:

[0080] The detection model constructed in step (2) is trained using the data set obtained in step (1); a hybrid loss function L mix is used to measure the error between the predicted results output by the model and the labels; during the training process, the Adam algorithm is used to update the model parameters, and L-2 regularization is used as a constraint; after E epochs of training, a trained surface defect detection model is obtained, and in this embodiment, E is 30.

[0081] Step 5, reasoning and obtaining detection results:

[0082] After the test image is normalized, it is input into the trained defect detection model, and the model output result is subjected to non-maximum suppression to obtain the final defect detection result.

[0083] Example 2

[0084] The method in Example 1 is used to perform surface defect detection experiments on the data set D_En. The operating system of this experiment is Windows 10, and the PyTorch 1.2.0 framework based on CUDA 10.0 and cuDNN 7.6.0 is used. A personal computer equipped with Intel(R) (Xeon(R) (W-2123(CPU(3.60GHz) and NVIDIA(GeForce(RTX(2080Ti(11GB) hardware is used for training and testing.

[0085] In this example, mAP, mAP50, mAP75, and mAR are used as four indicators to compare the ATSS, Cascade, CenterNet, FasterRCNN, FCOS, Libra, Retina-Net, SSD300, YOLOv3, YOLOx, and SYLOv4 eleven detection methods with the method of the present application on the D_En data set.

[0086] The comparison results are shown in Table 1. It can be found that compared with other methods, the present application can obtain accurate segmentation results on the D_En data set, and reaches the optimal value in the evaluation indicators mAP, mAP50, and mAR.

[0087] Figure 4 The surface defect detection results of the embodiment of the present application and the detection results of other methods are shown in the comparison chart. The results show that the model designed by the present application can well handle various challenging scenarios, including low-differentiation defects (column 1), small-scale defects (columns 2, 3, and 4), and low-differentiation and small-scale defects (columns 5, 6, 7, and 8). Compared with other methods, the defect detection results generated by the method are more accurate.

[0088] The above-described embodiments are only the preferred embodiments of the present application, and do not limit the scope of the present application. Any changes made according to the structure and principles of the present application should be covered within the scope of protection of the present application.

[0089] Table 1

[0090]

Claims

1. A surface defect detection method based on feature pre-fusion and mask guidance, characterized in that The method comprises the following steps: (1) obtaining a data set and a detection label: obtain a surface defect data set and a corresponding detection label; (2) constructing a defect detection model: the model is composed of a backbone network BoneNet, a feature pre-fusion module FPF, a multi-stage fusion module MSF, and a detection head Header, and the specific construction process comprises the following steps: (2-a) constructing a backbone network BoneNet: taking DarkNet53-CSP as the backbone network, inputting an image into the backbone network to obtain three feature maps f1, f2 and f3 of different scales, wherein f1 represents the smallest scale feature map, and f3 represents the largest scale feature map; (2-b) Constructing the Feature Prefusion Module (FPF): This module consists of three receptive field modules (RFB) and three information diffusion modules (ID); the feature maps f1, f2, and f3 obtained in step (2-a) are used as inputs to the three receptive field modules (RFB) to obtain the processing results. and Will With feature map group The inputs are combined into the first information dissemination module ID1 to obtain the output results. Will After upsampling, it is compared with the feature map group. The inputs are combined into the second information dissemination module ID2 to obtain the output results. Will After upsampling, it is compared with the feature map group. The inputs are combined into the third information dissemination module ID3 to obtain the output results. The information diffusion module ID is constructed as follows: The input of the information diffusion module includes a reference feature map with a feature map group wherein with respectively represent feature maps of three different scales; with After processing by the sampling layer, feature maps of the same scale as the reference feature map are obtained with with After pixel-by-pixel multiplication with the reference feature map, weighted feature maps are obtained with with Splicing is performed in the channel dimension, and the splicing result is processed by the first semantic interaction module CCBM1 to obtain an intermediate feature f mid ; f mid and the weighted feature map Splicing is performed in the channel dimension, and the splicing result is processed by the second semantic interaction module CCBM2 to obtain the output result f id of the information diffusion module ID; In the first information dissemination module ID1, with The baseline feature map serves as the input; in the second information diffusion module ID2, it is used as... The upsampling result is used as the input baseline feature map; in the third information diffusion module ID3, the upsampling result is used as the input baseline feature map. The upsampling result is used as the input baseline feature map; all three information diffusion modules use... The feature map set as its input (2-c) constructing a multi-stage fusion module MSF: splitting the feature maps generated by the feature pre-fusion module FPF in step (2-b) in the channel dimension according to a ratio of 1:N to generate two groups of feature maps and respectively splitting in the channel dimension according to a ratio of 1:N to generate two groups of feature maps and the first group of feature maps after being processed by the first bidirectional feature pyramid module FPNPAN1, a group of initial fusion multi-scale feature maps is generated the initial fusion feature map with the largest scale among them after being processed by a convolution module, a mask prediction result is obtained; the group of initial fusion multi-scale feature maps three feature maps in the group of initial fusion multi-scale feature maps are respectively spliced in the channel dimension according to different scales with three feature maps in the second group of feature maps and and together input into the second bidirectional feature pyramid module FPNPAN2, a final fusion result of the multi-stage fusion module MSF is obtained and ​ (2-d) Constructing a detection header Header: The detection header is composed of three convolution modules, and the final fusion result generated by the multi-stage fusion module MSF in step (2-c) is input into the three convolution modules and After the three convolution modules are processed, the final detection result is obtained after the processing results are combined. (3) constructing a loss function: The mixed loss function L is constructed as follows mix : L mix = L mask + L OD where L mask is the loss between the mask prediction result and the mask label, L OD is the loss between the target detection result and the target detection label, and L mask is constructed as follows: L mask = L BCE_mask + L iou_mask where L BCE_mask is the binary cross-entropy loss between the mask prediction and the mask label, L iou_mask is the IoU loss between the mask prediction and the mask label, defined as: where P denotes a mask prediction map, Gt denotes a mask ground truth map, both of the same size, H denotes the height of the map, W denotes the width of the map, P i,j and Gt i,j denote the pixel value at (i, j) in P and Gt, respectively, P i,j is a real number and P i,j ∈ (0, 1), Gt i,j is an integer and Gt i,j ∈ [0, 1], log(·) denotes the natural logarithm, denotes a pixel-wise addition operation, denotes a pixel-wise multiplication operation, and |·| denotes the sum of all pixels in an image. In this step L OD The construction is as follows: L OD = L iou_box + L BCE_obj + L CE_cls where L iou_box is the IOU loss between the predicted box and the true box, L BCE_obj is the confidence loss of the predicted box, and L BCE_cls is the class loss of the predicted box, defined as follows, respectively: L BCE_obj = -(y log(conf) + (1 - y) log(1 - conf)) box1 represents a prediction box, box2 represents a real box, area_inter(·) represents an intersection area, area_union(·) represents a union area, y represents a confidence label, conf represents a confidence prediction value, p k represents a class label of a defect, cls k represents a class prediction value of a defect; n is a positive integer, representing the number of defect classes, log(·) represents a natural logarithm; (4) training a defect detection model: The defect detection model constructed in step (2) is trained by using the data set obtained in step (1); and the hybrid loss function L constructed in step (3) is used mix An error between a prediction result output by the calculation model and a label is calculated; during the training process, the model parameters are updated by using an Adam algorithm, and L-2 regularization is used as a constraint; after E epochs of training, a trained surface defect detection model is obtained; (5) reasoning and obtaining a detection result: After the test image is normalized, it is input into the trained defect detection model, and the model output result is subjected to non-maximum suppression to obtain the final defect detection result.

2. The surface defect detection method based on feature pre-fusion and mask guidance as claimed in claim 1, wherein, The semantic interaction module CCBM in step (2-b) is processed by a channel attention module, a convolution layer, a normalization layer and a Mish activation function in sequence to obtain an output result.

3. The method of claim 1, wherein the method is based on feature pre-fusion and mask guidance for surface defect detection. In step (2-c), N is a positive integer, and N [1, 2048].

4. The method of claim 1, wherein the method is based on feature pre-fusion and mask guidance for surface defect detection. The convolution module in step (2-c) is composed of a convolution layer and a Relu activation function.

5. The method of claim 1, wherein the method further comprises: The three convolution modules in step (2-d) have the same structure, and each convolution module is composed of a convolution layer and a Relu activation function.

6. The method of feature pre-fusion and mask-guided surface defect detection of claim 1, wherein, In step (4), E is a positive integer, and E [1, 10000].