A method for generating abnormal samples

By generating smooth closed areas in normal samples and weighted fusing with background images, the problem of insufficient abnormal samples in industrial quality inspection is solved, and a variety of abnormal samples are generated, which improves the robustness and adaptability of the model.

CN119091255BActive Publication Date: 2025-08-08GUANGDONG MICROPATTERN SOFTWARE CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411559633.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-04
Publication Date
2025-08-08
Estimated Expiration
2044-11-04

AI Technical Summary

Technical Problem

In the field of industrial quality inspection, it is difficult for the prior art to obtain sufficient anomaly samples, resulting in insufficient training or overfitting of deep learning models.

Method used

By randomly generating smooth closed areas in normal samples, selecting background images and performing weighted fusion, defective images are generated and enhanced to simulate abnormal samples.

Benefits of technology

Rapidly generate diverse exception samples, solve the problem of insufficient training and overfitting caused by the lack of exception samples, and improve the robustness and adaptability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119091255B_ABST
    Figure CN119091255B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for generating abnormal samples, which relates to the technical field of industrial quality inspection. The present invention first generates a smooth closed area at a random position in a normal sample, then randomly selects a background image, randomly selects a position in the background image, cuts out a closed area of the same shape, then attaches the cut-out area to the normal sample in a weighted fusion manner to obtain a defect image, and finally performs image enhancement on the defect image to obtain an abnormal sample. The proposed method can quickly obtain a large number of rich, near-real abnormal samples based on normal samples, thereby solving the problem in the field of industrial quality inspection that a deep learning model cannot be trained due to a lack of abnormal samples or that the trained model suffers from overfitting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of industrial quality inspection, and in particular to a method for generating abnormal samples. Background Art

[0002] In industrial quality inspection, models need to be trained to detect various anomalies. Deep learning models require sufficient training samples. While normal samples are often readily available, a sufficient number of abnormal samples, nor can they capture all types of anomalies. To improve algorithm robustness, it's crucial to use normal samples to simulate abnormal samples. For example, among surface defects on magnetic tiles, both pores and wear appear darker than their surroundings, but their size and shape vary. Another example is in card quality inspection. Because cards require film coating, if the film is damaged, the damaged area will appear brighter than normal areas under normal lighting. Similarly, the location, size, and shape of the damage are also variable.

[0003] Therefore, in the process of automated detection, a large number of abnormal samples need to be collected to train a robust model. Summary of the Invention

[0004] In order to solve the technical problem of a large number of abnormal samples, the present invention provides a method for generating abnormal samples. The following technical solution is adopted:

[0005] A method for generating an abnormal sample comprises the following steps:

[0006] Step 1: Generate a smooth closed region at a random position in the normal sample;

[0007] Step 2: Select the closed area in step 1 as the location where the defect occurs, and determine the type of background image according to the type of defect;

[0008] Step 3: Randomly select a position in the background image and cut out a closed area of the same shape;

[0009] Step 4: Paste the extracted closed area onto the normal sample in a weighted fusion manner to obtain a defect image;

[0010] Step 5: Perform image enhancement on the defect image to obtain abnormal samples.

[0011] By adopting the above technical solution, a smooth closed area is first generated at a random position in the normal sample. Then, a background image is randomly selected, and a closed area of the same shape is randomly selected at a position in the background image. Then, the cut-out area is attached to the normal sample in a weighted fusion manner to obtain a defect image. Finally, the defect image is enhanced to obtain an abnormal sample.

[0012] Using the proposed solution, multiple abnormal samples can be quickly obtained based on normal samples, providing sufficient abnormal training samples for the detection model in the field of industrial quality inspection. The detection, classification or segmentation model can be trained based on the generated abnormal samples and normal samples, which can solve the problem of model overfitting caused by the lack of abnormal samples.

[0013] Optionally, step 1 generates a smooth closed region by performing the following steps:

[0014] Step 11, randomly select a point within the normal sample image range;

[0015] Step 12, with the selected point as the center, generate the x-coordinates and y-coordinates of N points respectively, where the x-coordinates and y-coordinates obey Gaussian distribution, uniform distribution, Beta distribution, Poisson distribution, or two-dimensional normal distribution, to obtain a set of N points; the distribution type of the x-coordinates and y-coordinates is not restricted here.

[0016] Step 13, obtain the convex hull of the point set;

[0017] Step 14: Generate smooth curves based on the points of the convex hull, and these smooth curves form a closed area.

[0018] By adopting the above technical solution, a variety of closed areas can be obtained, with random sizes and shapes. The distribution type of the x- and y-coordinates can be set according to the actual cause of the defect, and the distribution parameters can be adjusted appropriately to simulate the actual defect generation process as much as possible. In this way, a variety of abnormal samples can be obtained.

[0019] Optionally, use the ConvexHull function from the scipy library to compute the convex hull.

[0020] Optionally, use the splprep function of the advanced scientific computing library scipy to perform smooth curve fitting on the points on the convex hull.

[0021] Optionally, the type of the background image is determined according to the type of the defect, and the background image is a pure color image, a natural image, or is determined according to the actual defect type.

[0022] Optional enhancement methods include adjusting light intensity, saturation and hue, horizontal flipping and vertical flipping.

[0023] By employing the above technical solutions and adjusting light intensity, saturation, and hue, we can simulate samples acquired under different lighting conditions, enriching the lighting environment of generated samples. Training with these enhanced samples can improve the model's robustness to lighting. Horizontal and vertical flipping can increase the number of training samples while also increasing the model's robustness to horizontal and vertical flipping.

[0024] Optionally, in step 4, the weighted fusion coefficient k is a random number in the range [0, 1], and the defect image is calculated as follows:

[0025] ;

[0026] in is a normal sample image, is the background image, and k is the weighting coefficient.

[0027] By adopting the above technical solution, the weighted fusion coefficient of the normal sample image and the background image in the selected closed area can be flexibly adjusted, so that the generated defect image is more diversified and more in line with the actual defect generation process.

[0028] In summary, the present invention includes at least the following beneficial technical effects:

[0029] The present invention can provide a method for generating abnormal samples. First, a smooth closed area is generated at a random position in a normal sample. Then, a background image is randomly selected. A position is randomly selected in the background image to cut out a closed area of the same shape. Then, the cut-out area is attached to the normal sample in a weighted fusion manner to obtain a defect image. Finally, the defect image is enhanced to obtain an abnormal sample. The proposed method can quickly obtain a large number of rich and close-to-real abnormal samples based on normal samples, thereby solving the problem in the field of industrial quality inspection that deep learning models cannot be trained or the trained models are overfitted due to a lack of abnormal samples. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 It is a flow chart of a method for generating abnormal samples according to the present invention;

[0031] Figure 2 This is a schematic diagram of the effect of a real abnormal sample according to a specific embodiment of the abnormal sample generation method of the present invention. The left figure is a pore defect, and the right figure is a wear defect.

[0032] Figure 3 This is a schematic diagram of the effect of using real normal samples to generate abnormal samples in a specific embodiment of an abnormal sample generation method of the present invention. The left picture is a real normal sample, and the three pictures on the right are generated abnormal samples. DETAILED DESCRIPTION

[0033] The present invention is further described in detail below with reference to the accompanying drawings. An embodiment of the present invention discloses a method for generating abnormal samples.

[0034] Reference Figure 1-Figure 3 , a method for generating an abnormal sample, comprising the following steps:

[0035] Step 1: Generate a smooth closed region at a random position in the normal sample;

[0036] Step 2: Select the closed area in step 1 as the location where the defect occurs, and determine the type of background image according to the type of defect;

[0037] Step 3: Randomly select a position in the background image and cut out a closed area of the same shape;

[0038] Step 4: Paste the extracted closed area onto the normal sample in a weighted fusion manner to obtain a defect image;

[0039] Step 5: Perform image enhancement on the defect image to obtain abnormal samples.

[0040] First, a smooth closed area is generated at a random position in the normal sample. Then, a background image is randomly selected. A closed area of the same shape is cut out at a random position in the background image. The cut-out area is then attached to the normal sample in a weighted fusion manner to obtain a defect image. Finally, the defect image is enhanced to obtain an abnormal sample.

[0041] Using the proposed method, multiple abnormal samples can be quickly obtained based on normal samples, providing sufficient and diverse abnormal samples for detection models in the field of industrial quality inspection. Training detection, classification, or segmentation models based on the generated abnormal and normal samples can solve the problem of model overfitting caused by the lack of abnormal samples. Step 1 Generate a smooth closed region using the following steps:

[0042] Step 11, randomly select a point within the normal sample image range;

[0043] Step 12, with the selected point as the center, generate the x-coordinates and y-coordinates of N points respectively, where the x-coordinates and y-coordinates obey Gaussian distribution, uniform distribution, Beta distribution, Poisson distribution, or two-dimensional normal distribution, to obtain a set of N points; the distribution type of the x-coordinates and y-coordinates is not restricted here.

[0044] Step 13, obtain the convex hull of the point set;

[0045] Step 14: Generate smooth curves based on the points of the convex hull, and these smooth curves form a closed area.

[0046] A variety of closed regions can be obtained, with random sizes and shapes. The distribution type of the x- and y-coordinates can be set according to the actual cause of the defect, and the distribution parameters can be adjusted appropriately to simulate the actual defect generation process as much as possible. Based on this, a variety of abnormal samples can be obtained.

[0047] Use the ConvexHull function of the scipy library to calculate the convex hull.

[0048] Use the splprep function of the advanced scientific computing library scipy to perform smooth curve fitting on the points on the convex hull.

[0049] The type of the background image is determined according to the type of the defect. The background image is a solid color image, a natural image, or is determined according to the actual defect type.

[0050] Enhancement methods include adjusting light intensity, saturation and hue, horizontal flipping and vertical flipping.

[0051] Adjusting light intensity, saturation, and hue can simulate samples acquired under different lighting conditions, enriching the lighting environment of generated samples. Training with these enhanced samples can improve the model's robustness to lighting. Horizontal and vertical flipping can increase the number of training samples while also increasing the model's robustness to horizontal and vertical flipping.

[0052] In step 4, the weighted fusion coefficient k is a random number in the range [0, 1], and the defect image is calculated as follows:

[0053] ;

[0054] in is a normal sample image, is the background image, and k is the weighting coefficient.

[0055] The weighted fusion coefficients of the normal sample image and the background image in the selected closed area can be flexibly adjusted to make the generated defect image more diverse and more in line with the actual defect generation process.

[0056] The following describes an implementation principle of an abnormal sample generation method based on an embodiment:

[0057] The surface defects of the magnetic tile include pores and wear. Both defects are darker than the surrounding area. The real sample is as follows Figure 2 shown.

[0058] Since there are few real anomaly samples, it is difficult to obtain abundant anomaly samples to train a robust anomaly detection / segmentation model. To solve this problem, the following method can be used to generate anomaly samples.

[0059] Step 1: Get a normal sample and generate a smooth closed area at a random position of the normal sample as follows:

[0060] Randomly select a point within the normal sample image range with coordinates x0, y0;

[0061] With this point as the center, a set of 80 random points is generated. The x-coordinates of these random points follow a Gaussian distribution with mean x0 and variance d1, and the y-coordinates follow a Gaussian distribution with mean y0 and variance d2. By adjusting the values of d1 and d2, regions of different sizes and shapes can be obtained.

[0062] Get the convex hull of the point set. You can use the ConvexHull function of the advanced scientific computing library Scipy to calculate the convex hull.

[0063] Based on the points on the convex hull, a spline interpolation algorithm is used to generate smooth curves, which form a closed region. The splprep function of the advanced scientific computing library scipy can be used to fit smooth curves to the points on the convex hull.

[0064] Step 2: Select the closed area in step 1 as the location of the defect. Since the defect is darker than the surrounding area, the background image can be set to a pure black image. The background image here can also be a real defect image.

[0065] Step 3: Randomly select a position in the background image and cut out a closed area of the same shape. Since the background image is a pure black image, only a pure black image of the same size as the normal sample is needed to cut out a closed area of the same shape at the same position.

[0066] Step 4: Paste the extracted area into the normal image in a weighted fusion manner to obtain an abnormal sample. The weighting coefficient can be set to a random number between 0 and 1.

[0067] Steps 3 and 4 are equivalent to the following operations:

[0068] The weighting coefficient k is a random number in the range [0,1].

[0069] The final defect image is calculated as follows:

[0070] ;

[0071] normal_img is the normal sample image, back_img is the background image, and a pure black image is used here.

[0072] Image enhancement is performed on abnormal samples. Enhancement methods include adjusting light intensity, saturation, and hue, as well as horizontal and vertical flipping. Since real samples are grayscale images, only light intensity adjustment is required, not saturation and hue. Horizontal and vertical flipping are acceptable.

[0073] The abnormal samples generated by the above steps are as follows Figure 3 shown.

[0074] The above are all preferred embodiments of the present invention, and are not intended to limit the scope of protection of the present invention. Therefore, any equivalent changes made based on the structure, shape, and principle of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for generating abnormal samples, characterized in that: The following steps are involved: Step 1: Generate a smooth closed region at a random position in the normal sample; Step 2: Select the closed area in step 1 as the location where the defect occurs, and determine the type of background image according to the type of defect; Step 3: Randomly select a position in the background image and cut out a closed area of the same shape; Step 4: Paste the extracted closed area onto the normal sample in a weighted fusion manner to obtain a defect image; Step 5: Perform image enhancement on the defect image to obtain abnormal samples; Step 1 Generate a smooth closed area using the following steps: Step 11, randomly select a point within the normal sample image range; Step 12: Generate the x-coordinates and y-coordinates of N points with the selected point as the center, where the x-coordinates and y-coordinates obey Gaussian distribution, uniform distribution, Beta distribution, Poisson distribution, or two-dimensional normal distribution, to obtain a set of N points; Step 13, obtain the convex hull of the point set; Step 14: Generate smooth curves based on the points of the convex hull, and these smooth curves form a closed area; In step 4, the weighted fusion coefficient k is a random number in the range [0, 1], and the defect image is calculated as follows: ; in is a normal sample image, is the background image, k is the weighting coefficient; In step 5, the enhancement methods include adjusting light intensity, saturation and hue, horizontal flipping and vertical flipping.

2. The abnormal sample generation method according to claim 1, characterized in that: In step 13, the convex hull is calculated using the ConvexHull function of the advanced scientific computing library scipy.

3. The abnormal sample generation method according to claim 2, characterized in that: In step 14, the splprep function of the advanced scientific computing library scipy is used to perform smooth curve fitting on the points on the convex hull.

4. The abnormal sample generation method according to claim 1, characterized in that: In step 2, the type of the background image is determined according to the type of the defect. The background image is a pure color image, a natural image, or is determined according to the actual defect type.

Citation Information

Patent Citations

  • Defect sample generation method and device, electronic equipment and storage medium

    CN111681162A