A deep learning defect detection method and device based on positive samples
Through the deep learning method and cascade detection network based on positive samples, the problem of sample imbalance and environmental interference in industrial surface defect detection is solved, and high-accuracy and robust detection effects are achieved, especially in small target detection. Excellent performance.
Patent Information
- Application Number
- CN202410202143.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-23
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-02-23
AI Technical Summary
Existing industrial surface defect detection methods suffer from sample imbalance, large environmental interference, and small defect detection problems. Moreover, methods based on deep learning require a large amount of data, and it is difficult to obtain a robust and good generalization model with a small number of samples.
Adopting a deep learning defect detection method based on positive samples, combined with the cascade detection network and online anomaly generation algorithm, through hash deduplication, data enhancement, feature dimensionality reduction and template map matching, rich and diverse defect samples are constructed to improve detection accuracy. and robustness.
It significantly improves the recall rate and robustness of detection, reduces background interference and false alarms, saves manual annotation costs, and improves the model's generalization ability and training efficiency.
Smart Images

Figure CN118396919B_ABST
Abstract
Description
Technical Field
[0001] In the technical field of industrial surface defect detection methods, a deep learning defect detection method and device based on positive samples are provided. Background Art
[0002] Industrial surface defect detection is a very important part of the workpiece production process to control the quality of the workpiece. In actual production, most of the manual quality inspection methods are still used. This method is not only inefficient, but also easily affected by human subjective factors, and long-term work fatigue can easily lead to misjudgment. Therefore, the development of automated industrial surface defect detection methods based on image visual processing is very important and meaningful.
[0003] Image-based visual processing methods can be divided into two categories: traditional image-based and deep learning-based. For example, the traditional image-based workpiece surface defect detection method combines manually extracted features with classification networks. Manually extracted features are easily interfered by the environment, such as glass reflections and object shadows; and because there are many types of defects and large differences, it is difficult to manually design features. In practical applications, traditional image methods based on background image comparison will have camera distortion and light interference, which will lead to the inability to align the background image and the image to be detected, resulting in misjudgment. The deep learning-based method uses convolutional networks to automatically extract features, which is more robust and stable than traditional images. Common deep learning methods require a large amount of data for supervised learning. In the task of surface defect detection, defective workpieces are low-probability events, and the number of defect samples is small. It is difficult to obtain a robust and generalizable model with a small number of samples.
[0004] In summary, in view of the existing difficulties in industrial defect detection: large environmental noise interference; many types of defects with large morphological differences; the existence of tiny defects; many normal samples and few defective samples, and strong unknown defects; this patent proposes a wine bottle defect detection method based on deep learning of positive samples. . Summary of the invention
[0005] The purpose of the present invention is to provide a deep learning defect detection method and device based on positive samples. By combining positive sample deep learning technology and cascade detection network, the problems of sample imbalance, environmental interference and tiny defect detection existing in traditional methods are effectively solved, and the accuracy and robustness of detection are improved.
[0006] In order to achieve the above object, the present invention adopts the following technical solutions:
[0007] A deep learning defect detection method based on positive samples includes the following steps:
[0008] Step 1: preprocess the normal sample data set DatasetA to obtain the preprocessed data set DatasetA;
[0009] Step 2: Train the preprocessed dataset DatasetA to obtain the region of interest positioning model DetectModel;
[0010] Step 3: Input DetectModel into the original normal sample dataset DatasetA, construct the base map dataset DatasetB, use the base map dataset DatasetB to construct the template map dataset DatasetC and the abnormal defect map dataset, and train based on the base map dataset, template map dataset and abnormal defect map dataset to obtain the industrial defect detection model;
[0011] Step 4: Detect the abnormal image Isrc in the actual production application process and output the abnormal area.
[0012] In the above technical solution, step 1 includes the following steps:
[0013] Step 1.1: Use the hash deduplication method to deduplicate the normal sample data set DatasetA and obtain the deduplicated data set DatasetA.
[0014] In the above technical solution, step 1 includes the following steps:
[0015] Step 2.1, annotate the region of interest and perform data enhancement on the dataset DatasetA to obtain the annotated and data enhanced dataset DatasetA;
[0016] Step 2.2: Use yolov5 detection model supervised learning to train the enhanced dataset DatasetA to obtain the region of interest positioning model DetectModel.
[0017] In the above technical solution, step 3 includes the following steps:
[0018] Step 3.1, input DetectModel into the original normal sample dataset DatasetA, obtain the workpiece area, cut it out for preprocessing, and construct the base map dataset DatasetB;
[0019] Step 3.2, select 20 images with large distribution differences from the base map dataset DatasetB as template map DatasetC, and use PCA to reduce the feature dimension of the base map to obtain the template map DatasetC;
[0020] Step 3.3, generate workpiece surface defects and obtain rich and diverse defect samples;
[0021] Step 3.4, promote learning inter-class differences and intra-class similarities to construct input and obtain a training data set;
[0022] Step 3.5: Build a deep learning workpiece defect detection model based on the training data set to obtain an industrial defect detection model.
[0023] In the above technical solution, step 4 includes the following steps:
[0024] Step 4.1, input the region of interest positioning model DetectModel to the abnormal image Isrc, obtain the roi image of the region to be detected, and perform preprocessing operations on the roi image;
[0025] Step 4.2, grayscale and scale the image of the region to be detected roi to obtain the image gray_roi;
[0026] Step 4.3, match and align the image gray_roi with the template image, calculate the difference, and splice the roi image, the aligned template image and the difference image, and send them to the industrial defect detection model;
[0027] Step 4.4: Output the abnormal defect position relative to the roi image and project it to the original image Isrc to obtain the final abnormal area.
[0028] The present invention also provides a deep learning defect detection device based on positive samples, comprising:
[0029] The preprocessing module is used to preprocess the normal sample data set DatasetA to obtain the preprocessed data set DatasetA;
[0030] The first-level detection network training module is used to perform first-level detection network training on the preprocessed data set DatasetA to obtain the region of interest positioning model DetectModel;
[0031] The secondary detection network training module is used to receive the original normal sample data set DatasetA and input it into DetectModel, construct the base map data set DatasetB, use the base map data set DatasetB to construct the template map data set DatasetC and the abnormal defect map data set, and train based on the base map data set, template map data set and abnormal defect map data set to obtain the industrial defect detection model;
[0032] The detection module is used to detect abnormal images Isrc in actual production applications and output abnormal areas.
[0033] In the above device, the preprocessing module further comprises:
[0034] The sample deduplication submodule uses the hash deduplication method to deduplicate the normal sample data set DatasetA and obtains the deduplicated data set DatasetA.
[0035] In the above device, the first-level detection network training module further includes:
[0036] The labeling and data enhancement submodule is used to label the region of interest and enhance the data of the dataset DatasetA to obtain the labeled and data enhanced dataset DatasetA;
[0037] The supervised learning submodule uses the yolov5 detection model for supervised learning to train the enhanced dataset DatasetA to obtain the region of interest positioning model DetectModel.
[0038] In the above device, the secondary detection network training module further includes:
[0039] The base map construction submodule is used to input the original normal sample dataset DatasetA into DetectModel, obtain the artifact area, cut it out for preprocessing, and construct the base map dataset DatasetB;
[0040] The template selection submodule is used to select images with large distribution differences from the base map dataset DatasetB as template images DatasetC, and use PCA to reduce the feature dimension of the base map;
[0041] The defect sample generation submodule is used to generate surface defects of workpieces and obtain rich and diverse defect samples;
[0042] The training data set construction submodule is used to promote the learning of inter-class differences and intra-class similarities to construct inputs and obtain training data sets;
[0043] The deep learning workpiece defect detection model construction submodule builds a deep learning workpiece defect detection model based on the training data set to obtain an industrial defect detection model.
[0044] In the above device, the detection module further comprises:
[0045] The region of interest positioning submodule is used to input the region of interest positioning model DetectModel into the abnormal image Isrc, obtain the roi image of the region to be detected, and perform preprocessing operations on the roi image;
[0046] The image processing submodule is used to grayscale and scale the image of the detection area roi to obtain the image gray_roi;
[0047] The template matching and alignment submodule is used to match and align the gray_roi image with the template image, calculate the difference, and splice the roi image, the aligned template image, and the difference image, and send them to the industrial defect detection model;
[0048] The abnormal region output submodule is used to output the abnormal defect position relative to the roi image and project it to the original image Isrc to obtain the final abnormal region.
[0049] Because the present invention adopts the above technical means, it has the following beneficial effects:
[0050] 1. Cascade detection network design: This solution adopts a two-level detection network. The first level locates the target of interest and effectively cuts out irrelevant background areas. This not only reduces background interference and false alarms, but also increases the proportion of workpiece defects in the input of the second-level detection network. It is particularly beneficial for the detection of small targets in industrial environments and significantly improves the recall rate.
[0051] 2. Online anomaly generation algorithm: This solution generates a rich variety of defect samples in real time through an online generation algorithm. These samples can well simulate real workpiece defects in terms of distribution and morphology. This innovation not only solves the problem of scarce industrial defect samples and difficulty in obtaining a strong generalization model, but also directly saves the high cost of manual labeling.
[0052] 3. Input fusion strategy: In the secondary detection network, the scheme fuses the image to be detected, the normal template image and the difference image between the two as input. This strategy effectively promotes the network to learn the difference between classes and the similarity within classes. This can not only improve the recall rate of unknown defect states, but also accelerate network convergence and improve training efficiency.
[0053] 4. Improvement of YOLOv5 structure: In view of the characteristics of industrial defects, this solution improves the YOLOv5 structure and integrates the features output by the shallower second-layer convolution module. This improvement enables the model to better capture the shallow features of workpiece defects (such as contours, contrast, etc.), thereby further improving the recall rate of defect detection. At the same time, in order to enhance the robustness of the model, the self-attention mechanism is added to the deep features to obtain more global information. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 To improve the yolov5 schematic;
[0055] Figure 2 It is a schematic diagram of FPN;
[0056] Figure 3 Schematic diagram of self-attention. DETAILED DESCRIPTION
[0057] The following is a detailed description of the embodiments of the present invention. Although the present invention will be described and illustrated in conjunction with some specific embodiments, it should be noted that the present invention is not limited to these embodiments. On the contrary, modifications or equivalent substitutions made to the present invention should all be included in the scope of the claims of the present invention.
[0058] In addition, in order to better illustrate the present invention, numerous specific details are given in the following specific embodiments. It will be understood by those skilled in the art that the present invention can also be implemented without these specific details.
[0059] The steps implemented by the present invention are as follows:
[0060] 1. Collect normal sample data set
[0061] Determine the industrial lighting method, collect a large number of normal workpiece images and perform sample deduplication as the normal sample data set DatasetA. The sample deduplication method adopts the hash deduplication method: first calculate the image hash value: set the hash size (hash_w, hash_h), convert the image to a grayscale image and scale it to (hash_w, hash_h), and calculate the pixel mean of the scaled image. Each pixel is compared with the average value, and 1 is taken if it is greater than the average value, and 0 is taken if it is less than the average value. The sequence of all pixel results is the hash value of the image. Deduplication operation: maintain an image hash value dictionary, the key-value pair is {image hash value: image name}, when the image hash value exists in the dictionary, it means a duplicate image, which can be removed; otherwise, the image is retained and the image hash value is added to the dictionary.
[0062] 2. The first-level detection network locates the region of interest
[0063] The original images obtained by commonly used industrial cameras not only contain a large amount of background areas, but are also much larger than the input size of general convolutional network models. Directly inputting the original images into the model, the preprocessing operation will compress them to the model input size, resulting in loss of details. Therefore, using the trained first-level detection network, the area of interest can be framed in the original image, retaining more defect details, and removing background interference from other non-workpiece areas.
[0064] Extract N images from the normal sample dataset DatasetA to annotate the regions of interest, where N is greater than 1000. After the annotation, perform data enhancement, which includes common light changes, image translation and rotation, image scaling, color changes, noise addition, etc. After data enhancement, the region of interest positioning model DetectModel is obtained based on supervised learning of the yolov5 detection model.
[0065] 3. Secondary inspection network for industrial defect detection
[0066] 3.1 Building a base map
[0067] Based on the region of interest positioning model, the base map dataset DatasetB is obtained: the collected original normal sample dataset DatasetA is input into DetectModel to obtain the workpiece area [sx1, sy1, sx2, sy2], and then cut out and perform preprocessing operations to construct the base map dataset DatasetB. The preprocessing operations include: graying the cut area image and scaling it to a fixed size (resize w , resize h ).
[0068] 3.2 Building a template graph
[0069] Select 20 images with large distribution differences from the base map dataset DatasetB as template images DatasetC. Use PCA to reduce the feature dimension of the base map to reduce the amount of calculation. First, randomly select one from the base map and add it to DatasetC. Then calculate the sum of the Euclidean distances between the features of the remaining base maps in DatasetB after dimensionality reduction and the features of all base maps in DatasetC after dimensionality reduction. Select the one with the largest distance and add it to DatasetC. Repeat this process until the required number of template images is reached.
[0070] 3.3 Generate workpiece surface defects
[0071] In order to obtain a defect detection model with good generalization in real workpieces, a rich variety of defect samples are required. However, there are few real defect samples for workpiece defect detection, so this patent generates a rich variety of defect samples to approximate the real defect distribution. Workpiece defects have different forms, different shapes, different textures, different spatial positions, and different defect area sizes, etc. Therefore, this patent considers the above aspects to construct rich defect samples. The commonly used texture dataset DTD and the VOC2007 dataset are selected as texture datasets. The texture dataset covers different light, target size, shape and texture features.
[0072] (1) Generate abnormal images based on the VOC2007 texture dataset
[0073] Select an image from the base map dataset DatasetB as the original sample I; randomly generate a set of left vertex positions (r_x, r_y) and abnormal area sizes (r_w, r_h) of the abnormal area to be generated based on the width and height of the original sample, and crop the area from the original sample I to obtain sub-image I roi ; Select an image T from the texture dataset VOC2007, convert it to grayscale, read the instance segmentation map, and randomly select a mask T of an instance target mask ; Texture image T and mask T maskInterpolate to the abnormal region size (r_w, r_h) to obtain T and T mask ; and merge according to formula 1 to obtain the abnormal subgraph T roi , where α ranges from (0.2 to 0.8), controlling the weighted fusion ratio of the texture image and the original image, and the mask image T mask represents the defect foreground mask, represents the background mask. Finally, as shown in Formula 2, the abnormal sub-graph T roi Replace the original image with the abnormal area to be generated to obtain the abnormal image I g .
[0074]
[0075] I g ←I [r_x,r_y,r_w,r_h] =I′ roi (2)
[0076] Among them I [r_x,r_y,r_w,r_h] The meaning is the abnormal area of the original image to be generated.
[0077] (2) Generate abnormal images based on texture dataset DTD
[0078] A sample is randomly selected from the base map database DatasetB as the original sample I. A set of left vertex positions (r_x, r_y) and abnormal area sizes (r_w, r_h) of the abnormal area to be generated are randomly generated based on the width and height of the original sample, and the sub-image I' is obtained by cropping the area of the original sample I roi ; Select an image T from DTD, convert it to grayscale, and interpolate it to the abnormal area size (r_w, r_h) to obtain image T′; In order to simulate rich defect shapes, three methods are used to generate shape masks. Method 1 generates a Perlin noise P of size (rw, rh) and binarizes it to obtain mask T′ mask Method 2: Create a zero background image with an abnormal region size (rw, rh) and fill the background image with standard shapes such as circles, rectangles and ellipses to obtain the mask T′ mask Method 3: Create a zero background image of the abnormal area size (r_w, r_h), randomly generate n coordinate points, use the opencv function fillPoly and fill the polygon with 255 values to obtain the mask T mask And according to formula 1, the abnormal subgraph I′ is obtained by fusion roi Finally, as shown in Formula 2, the abnormal subgraph T roi Replace the original image with the abnormal area to be generated to obtain the abnormal image I g .
[0079] The method for generating abnormal images based on the above two texture libraries can generate a variety of abnormal images in terms of position, size, texture, shape, etc.
[0080] 3.4 Promoting learning of inter-class differences and intra-class similarities to construct input
[0081] The method for generating anomalies proposed in this patent can generate rich and diverse anomaly samples to approximate the real anomaly distribution. In order to further improve the recall of unknown real defect samples, an input preprocessing module is designed to construct abnormal samples and normal samples, guiding the model to learn inter-class differences and intra-class similarities, rather than learning the defects themselves. The steps are as follows:
[0082] 4.1 Template Graph Matching and Alignment
[0083] The image to be detected I g The pixel distance is calculated for all template pixels in the Dataset C dataset, as shown in Formula 3. The template with the smallest distance is the successfully matched template I. t , where H and W are the width and height of the image to be detected. Then the surf algorithm is used to extract the abnormal image I g and Template I t The image key points and feature descriptors of the two images are used to measure the similarity of the two image descriptors with the Euclidean distance. The matching pairs with low similarity are discarded according to the ratio r, and the remaining matching pairs with high similarity are used to estimate the homography matrix. The homography matrix is used to transform the successfully matched template image to align it to the abnormal image, and the aligned template image l′t is obtained.
[0084]
[0085] 4.2 Constructing model input
[0086] During the training process, the ratio of abnormal samples to normal samples is 8:2. Constructing abnormal samples promotes inter-class difference learning, and constructing normal samples promotes intra-class similarity learning.
[0087] 4.2.1 Constructing abnormal training samples
[0088] Input image construction: Calculate the pixel absolute difference between the abnormal image and the aligned template image to obtain the inter-class difference map Idiff, and channel-join the abnormal image, the aligned template image, and the inter-class difference image to obtain the abnormal training sample.
[0089] Sample label construction: Calculate the pixel difference between the abnormal image and the normal image to obtain the abnormal change map, and binarize the abnormal change map to obtain a binary map. Count the upper left vertex (x1, y1) and lower right vertex (x2, y2) in the non-zero area of the binary map, and convert it into the yolo label format according to formula 4, where W and H are the width and height of the normal image.
[0090]
[0091] Where w, h, cx, and cy represent the normalized width, height, and center coordinates of the abnormal area, respectively.
[0092] 4.2.2 Constructing normal training samples
[0093] There is no need to construct target detection supervision labels for positive samples. The method for constructing normal samples is as follows:
[0094] Method 1, calculate the pixel difference between the normal image I and the aligned template image to obtain the intra-class difference map ldiff, and perform channel splicing on the normal image, the aligned template image and the difference image. This method is used to construct normal training samples, so that the normal samples carry the difference information between the normal images caused by surface distortion, light interference, etc., and this difference is not a real abnormality, which promotes the learning of intra-class differences and intra-class similarities; thus, the abnormality can be correctly detected during the reasoning process.
[0095] Method 2: Initialize an image difference map with a single channel pixel value of 0, copy the abnormal image lg to obtain the abnormal image Ig1, and directly perform channel splicing on the abnormal image Ig, the abnormal image Ig1, and the difference map. The normal samples constructed by this method can further promote the model to learn the difference, rather than the defect itself.
[0096] 3.5 Building a deep learning workpiece defect detection model
[0097] This patent uses the commonly used detection model yolov5. Yolov5 is divided into 3 parts:
[0098] (1) Feature extraction network csp-darknet53, which contains 5 convolution modules, extracts 5 layers of features c1, c2, c3, c4, and c5 respectively;
[0099] (2) The neck part includes the SPP layer and the feature fusion FPN layer. The SPP layer extracts and fuses the multi-view features of the final feature map C5. The FPN layer performs context feature fusion on the extracted features C3, C4, and C5 to output P3, P4, and P5.
[0100] (3) Prediction module: The three fused feature maps p3, p4, and p5 are respectively input into the convolution module to output category information, location information, and confidence.
[0101] In view of the fact that workpiece defects contain more shallow features, such as contours, contrast, etc., but lack advanced semantic features, and the existence of tiny defects in workpieces, the feature fusion module of yolov5 is improved. The results of the improved model are as follows Figure 1As shown in Figure 2, the shallow feature c2 has a larger image size and retains more input features, so the FPN layer references the shallower feature c2 and cancels the c5 layer, as shown in Figure 2. Figure 2 As shown; at the same time, in order to improve the c4 layer features to contain more global information, the self-attention mechanism is introduced. The self-attention structure is shown in the figure Figure 2 As shown in the figure, QKV are all features of the c4 layer as input. Q and K first perform matrix operations to calculate the correlation between features. The matrix operation calculates the correlation through the inner product operation of each eigenvector and all eigenvectors. Therefore, the output similarity information contains the correlation between all eigenvectors. Finally, the feature map output by matrix multiplication with the eigenvector V makes c4 contain more global information.
[0102] The base map is used to generate anomalies online and construct training samples to train the improved yolov5 detection model, and a two-stage industrial defect detection model is obtained.
[0103] 4. Output abnormal area
[0104] In the actual production application process, an abnormal image Isrc is collected and input into the first-stage positioning detection model, a more accurate roi image of the area to be detected is cropped, the cropped area image is grayed and scaled to a fixed size (resize w , resize h ) to obtain the image gray_roi. Match and align it with the template image, calculate the difference between the grayscale image gray_roi with a fixed size and the aligned template image, and splice the roi image, the aligned template image and the difference image, and send them to the trained two-stage detection model to output the abnormal defect position (dx1, dy1, dx2, dy2) relative to the roi image; finally, project the abnormal position to the original image Isrc as shown in formula (5).
[0105]
[0106] Among them, sx1, sx2, sy1, and sy2 are obtained by the one-stage region of interest positioning model, indicating that the region of interest is located at the upper left vertex and lower right vertex of the abnormal image Isrc. d′x1, d′y1, d′x2, and d′y2 indicate that the abnormal defect position is located at the upper left vertex and lower right vertex of the original abnormal image Isrc.
Claims
1. A deep learning defect detection method based on positive samples, It is characterized in that The following steps are involved: Step 1: preprocess the normal sample data set DatasetA to obtain the preprocessed data set DatasetA; Step 2: Train the region of interest positioning model DetectModel on the preprocessed data set DatasetA to obtain the region of interest positioning model DetectModel; Step 3: Input DetectModel into the original normal sample dataset DatasetA, construct the base map dataset DatasetB, use the base map dataset DatasetB to construct the template map dataset DatasetC and the abnormal defect map dataset, and train based on the base map dataset, template map dataset and abnormal defect map dataset to obtain the industrial defect detection model; Step 3.1, input DetectModel into the original normal sample dataset DatasetA, obtain the workpiece area, cut it out for preprocessing, and construct the base map dataset DatasetB; Step 3.2, select 20 images with large distribution differences from the base map dataset DatasetB as template map DatasetC, and use PCA to reduce the feature dimension of the base map to obtain the template map DatasetC; Step 3.3, generate workpiece surface defects and obtain rich and diverse defect samples; Step 3.4, promote learning inter-class differences and intra-class similarities to construct input and obtain a training data set; An input preprocessing module is used to construct abnormal samples and normal samples, guiding the model to learn inter-class differences and intra-class similarities instead of learning the defects themselves. The steps are as follows: Step 3.4.1 Template graph matching and alignment The image to be detected Calculate pixel distance with all template pixels in DatasetC , as shown in formula 3, the template with the smallest distance is the successfully matched template ,in is the width and height of the image to be detected; then the surf algorithm is used to extract abnormal images respectively and template diagram The image key points and feature descriptors of the two images are measured by Euclidean distance to measure the similarity of the two image descriptors. The matching pairs with low similarity are discarded according to the ratio r. The remaining matching pairs with high similarity are used to estimate the homography matrix. The homography matrix is used to perform a graphical transformation on the successfully matched template image to align it to the abnormal image to obtain the aligned template image I't; Formula 3 Step 3.4.2: Construct model input During the training process, the ratio of abnormal samples to normal samples is 8:
2. The construction of abnormal samples promotes inter-class difference learning, and the construction of normal samples promotes intra-class similarity learning; Step 3.4.2.1 Construct abnormal training samples Input image construction: Calculate the pixel absolute difference between the abnormal image and the aligned template image to obtain the inter-class difference image Idiff, and channel-join the abnormal image, the aligned template image, and the inter-class difference image to obtain the abnormal training sample; Sample label construction: Calculate the pixel difference between the abnormal image and the normal image to obtain the abnormal change map, and perform binarization on the abnormal change map to obtain a binary map. Count the upper left vertices of the non-zero area of the binary map ( x 1 ,y 1), the lower right vertex ( , ), and convert it to yolo label format according to formula 4, where W and H are the width and height of the normal image: Equation 4 in , , , represent the normalized abnormal area width, height and center point coordinates respectively; Step 4.2.2 Construct normal training samples There is no need to construct target detection supervision labels for positive samples. The methods for constructing normal samples are any of the following: Method 1: Calculate the pixel difference between the normal image I and the aligned template image to obtain the intra-class difference map Idiff, and perform channel splicing on the normal image, the aligned template image, and the difference image; Method 2: Initialize an image difference map with a single channel pixel value of 0, copy the abnormal image Ig to obtain the abnormal image Ig1, and directly perform channel splicing on the abnormal image Ig, the abnormal image Ig1, and the difference map; Step 3.5: Build a deep learning workpiece defect detection model based on the training data set to obtain an industrial defect detection model; Step 4: Detect the abnormal image Isrc in the actual production application process and output the abnormal area.
2. According to the method for deep learning defect detection based on positive samples in claim 1, It is characterized in that Step 1 includes the following steps: Step 1.1: Use the hash deduplication method to deduplicate the normal sample data set DatasetA and obtain the deduplicated data set DatasetA.
3. According to the method for deep learning defect detection based on positive samples in claim 1, It is characterized in that Step 2 includes the following steps: Step 2.1, annotate the region of interest and perform data enhancement on the dataset DatasetA to obtain the annotated and data enhanced dataset DatasetA; Step 2.2: Use yolov5 detection model supervised learning to train the enhanced dataset DatasetA to obtain the region of interest positioning model DetectModel.
4. The method for defect detection based on deep learning of positive samples according to claim 1, It is characterized in that Step 4 includes the following steps: Step 4.1, input the region of interest positioning model DetectModel to the abnormal image Isrc, obtain the roi image of the region to be detected, and perform preprocessing operations on the roi image; Step 4.2, grayscale and scale the image of the region to be detected roi to obtain the image gray_roi; Step 4.3, match and align the image gray_roi with the template image, calculate the difference, and splice the roi image, the aligned template image and the difference image, and send them to the industrial defect detection model; Step 4.4: Output the abnormal defect position relative to the roi image and project it to the original image Isrc to obtain the final abnormal area.
5. A deep learning defect detection device based on positive samples, It is characterized in that include: The preprocessing module is used to preprocess the normal sample data set DatasetA to obtain the preprocessed data set DatasetA; The first-level detection network training module is used to perform first-level detection network training on the preprocessed data set DatasetA to obtain the region of interest positioning model DetectModel; The secondary detection network training module is used to receive the original normal sample data set DatasetA and input it into DetectModel, construct the base map data set DatasetB, use the base map data set DatasetB to construct the template map data set DatasetC and the abnormal defect map data set, and train based on the base map data set, template map data set and abnormal defect map data set to obtain the industrial defect detection model; The secondary detection network training module further includes: The base map construction submodule is used to input the original normal sample dataset DatasetA into DetectModel, obtain the artifact area, cut it out for preprocessing, and construct the base map dataset DatasetB; The template selection submodule is used to select images with large distribution differences from the base map dataset DatasetB as template images DatasetC, and use PCA to reduce the feature dimension of the base map; The defect sample generation submodule is used to generate surface defects of workpieces and obtain rich and diverse defect samples; The training data set construction submodule is used to promote the learning of inter-class differences and intra-class similarities to construct inputs and obtain training data sets; The training dataset construction submodule includes the following steps: Step 3.1, input DetectModel into the original normal sample dataset DatasetA, obtain the workpiece area, cut it out for preprocessing, and construct the base map dataset DatasetB; Step 3.2, select 20 images with large distribution differences from the base map dataset DatasetB as template map DatasetC, and use PCA to reduce the feature dimension of the base map to obtain the template map DatasetC; Step 3.3, generate workpiece surface defects and obtain rich and diverse defect samples; Step 3.4, promote learning inter-class differences and intra-class similarities to construct input and obtain a training data set; An input preprocessing module is used to construct abnormal samples and normal samples, guiding the model to learn inter-class differences and intra-class similarities instead of learning the defects themselves. The steps are as follows: Step 3.4.1 Template graph matching and alignment The image to be detected Calculate pixel distance with all template pixels in DatasetC , as shown in formula 3, the template with the smallest distance is the successfully matched template ,in is the width and height of the image to be detected; then the surf algorithm is used to extract abnormal images respectively and template diagram The image key points and feature descriptors of the two images are measured by Euclidean distance to measure the similarity of the two image descriptors. The matching pairs with low similarity are discarded according to the ratio r. The remaining matching pairs with high similarity are used to estimate the homography matrix. The homography matrix is used to perform a graphical transformation on the successfully matched template image to align it to the abnormal image to obtain the aligned template image I't; Formula 3 Step 3.4.2: Construct model input During the training process, the ratio of abnormal samples to normal samples is 8:
2. The construction of abnormal samples promotes inter-class difference learning, and the construction of normal samples promotes intra-class similarity learning; Step 3.4.2.1 Construct abnormal training samples Input image construction: Calculate the pixel absolute difference between the abnormal image and the aligned template image to obtain the inter-class difference image Idiff, and channel-join the abnormal image, the aligned template image, and the inter-class difference image to obtain the abnormal training sample; Sample label construction: Calculate the pixel difference between the abnormal image and the normal image to obtain the abnormal change map, and perform binarization on the abnormal change map to obtain a binary map. Count the upper left vertices of the non-zero area of the binary map ( x 1 ,y 1), the lower right vertex ( , ), and convert it to yolo label format according to formula 4, where W and H are the width and height of the normal image: Equation 4 in , , , represent the normalized abnormal area width, height and center point coordinates respectively; Step 4.2.2 Construct normal training samples There is no need to construct target detection supervision labels for positive samples. The methods for constructing normal samples are any of the following: Method 1: Calculate the pixel difference between the normal image I and the aligned template image to obtain the intra-class difference map Idiff, and perform channel splicing on the normal image, the aligned template image, and the difference image; Method 2: Initialize an image difference map with a single channel pixel value of 0, copy the abnormal image Ig to obtain the abnormal image Ig1, and directly perform channel splicing on the abnormal image Ig, the abnormal image Ig1, and the difference map; Step 3.5: Build a deep learning workpiece defect detection model based on the training data set to obtain an industrial defect detection model; The deep learning workpiece defect detection model construction submodule builds a deep learning workpiece defect detection model based on the training data set to obtain an industrial defect detection model; The detection module is used to detect abnormal images Isrc in actual production applications and output abnormal areas.
6. The device according to claim 5, It is characterized in that The preprocessing module further includes: The sample deduplication submodule uses the hash deduplication method to deduplicate the normal sample data set DatasetA and obtain the deduplicated data set DatasetA.
7. The device according to claim 5, It is characterized in that The first-level detection network training module further includes: The labeling and data enhancement submodule is used to label the region of interest and enhance the data of the dataset DatasetA to obtain the labeled and data enhanced dataset DatasetA; The supervised learning submodule uses the yolov5 detection model for supervised learning to train the enhanced dataset DatasetA to obtain the region of interest positioning model DetectModel.
8. The device according to claim 5, It is characterized in that The detection module further comprises: The region of interest positioning submodule is used to input the region of interest positioning model DetectModel into the abnormal image Isrc, obtain the roi image of the region to be detected, and perform preprocessing operations on the roi image; The image processing submodule is used to grayscale and scale the image of the detection area roi to obtain the image gray_roi; The template matching and alignment submodule is used to match and align the gray_roi image with the template image, calculate the difference, and splice the roi image, the aligned template image, and the difference image, and send them to the industrial defect detection model; The abnormal region output submodule is used to output the abnormal defect position relative to the roi image and project it to the original image Isrc to obtain the final abnormal region.
Citation Information
Patent Citations
Few-sample defect detection method using defect-free image
CN114140398A
Workpiece surface defect detection method based on anomaly detection
CN115018790A
Depth template-based defect detection method and system
CN116109621A
Surface defect detection method based on deep learning and global difference information
CN116228754A
Defect detection method for X-ray image of laser welding seam
CN116245869A
