An industrial defect detection method based on image restoration

By using GAN networks for image restoration in industrial defect detection, combined with self-supervised training and edge feature fusion, the problem of detection accuracy and manual annotation requirements is solved, efficient and accurate defect detection is achieved, and model training and deployment are simplified.

CN118212196BActive Publication Date: 2024-09-03SICHUAN SHUJU INTELLIGENT MFG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410309453.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-18
Publication Date
2024-09-03
Estimated Expiration
2044-03-18

AI Technical Summary

Technical Problem

Existing industrial defect detection technology has poor detection accuracy in complex environments and is difficult to adapt to product diversity. It requires a large number of manually labeled samples, and the repair quality of high-frequency areas of the image is poor, making it impossible to achieve real-time, efficient, and accurate detection.

Method used

The image repair method based on GAN network is used to establish a reference base library, match normal images similar to the image to be detected, fuse edge features for repair, use self-supervised training model to generate high-quality reconstructed images, and optimize the generation through the discriminator processor to improve the authenticity of image details.

Benefits of technology

There is no need to manually label samples, which improves the recall rate and accuracy of defect detection, reduces the false detection rate, achieves efficient and accurate detection in industrial environments, and simplifies the model training and deployment process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118212196B
    Figure CN118212196B
Patent Text Reader

Abstract

The present invention relates to the field of industrial image processing, and provides an industrial defect detection method based on image restoration. The main purpose is to solve the problem that the existing method performs poorly at the edge of the image and has poor reconstruction quality. The main scheme includes a positive sample and its corresponding feature vector. As the standard of a normal sample, the positive sample generates a feature vector through a feature extractor trained on the ImageNet data set and stores it in a library; input an image to be detected, calculate its cosine similarity with the feature vector in the reference background library, and select the reference background with the highest similarity; extract the edge of the reference background as the reference edge of the image to be detected, and fuse the reference edge with the image to be detected in the channel dimension to obtain a fusion feature; pass the fusion feature into the image restoration network for restoration, and output a reconstructed image aligned with the image to be detected; calculate the residual image between the generated reconstructed image and the image to be detected, screen the allowable defects, and judge whether the image to be detected has defects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of industrial image processing and provides an industrial defect detection method based on image restoration. Background Art

[0002] Industrial defect detection is a key link in the manufacturing industry, which is directly related to product quality and corporate competitiveness. In the past few decades, with the rapid development of industrial automation and artificial intelligence technology, the traditional defect detection method based on human eyes has gradually failed to meet the high efficiency and high precision requirements of modern industry. Manual detection has problems such as slow detection speed, low accuracy, and susceptibility to subjective factors, and it is impossible to achieve real-time detection in large-scale production.

[0003] In recent years, industrial defect detection technology based on machine vision has received extensive attention and research. This technology uses computer algorithms and image processing technology to perform high-speed and high-precision inspections on the surface or interior of products, and can identify tiny flaws and defects in products. Among them, deep learning algorithms, especially the application of convolutional neural networks (CNN), have brought revolutionary changes to industrial defect detection. By learning from a large number of defect samples, deep learning models can highly accurately identify various defect types, thereby greatly improving the accuracy and efficiency of detection.

[0004] However, existing industrial defect detection technologies still face many challenges. For example, interference factors such as light, shadow, and reflection in complex industrial environments can affect the accuracy of detection; the diversity and complexity of the products themselves also require continuous optimization and adjustment of defect detection algorithms; product defect samples are difficult to cover, and it is difficult to detect defects that have not appeared using existing algorithms; due to the diversity of defects, a large number of training samples need to be manually labeled, which consumes a lot of human resources; the existing algorithms have poor repair quality in high-frequency areas of images. In addition, as the pace of industrial production continues to accelerate, the requirements for detection technology are also getting higher and higher, and real-time, efficient, and accurate detection is needed.

[0005] In order to solve the above problems, the present invention proposes an industrial defect detection method based on image restoration. The method uses a GAN network to restore the defect image, compares it with the defect image after restoration, and outputs the defect position in the defect image. It can better meet the detection needs in complex industrial environments, and the model adopts a self-supervised training method to reduce personnel investment and shorten the development cycle. Summary of the invention

[0006] The technical solution of the present invention solves the problem that the existing methods perform poorly at the edges of images and have poor reconstruction quality. By fusing the edge features of normal images similar to defective images and using the complete edge features to guide the model to repair at the edges, the quality of the reconstructed image at the edges can be made closer to that of normal images. At the same time, the image repair model training of the present invention includes three steps: data set construction, data set automatic generation, and model training. Through these steps, an image repair model capable of repairing defective images is trained.

[0007] In order to achieve the above purpose, the present invention adopts the following technical means:

[0008] The present invention provides an industrial defect detection method based on image restoration, comprising the following steps:

[0009] Step 1: Establish a reference base map library, which includes positive samples and their corresponding feature vectors. As the standard of normal samples, positive samples generate feature vectors through feature extractors trained on the ImageNet dataset and store them in the library.

[0010] Step 2: Match the background image. Input an image to be detected, calculate the cosine similarity between the image and the feature vector in the reference background image library, and select the reference background image with the highest similarity.

[0011] Step 3: Feature fusion: extract the edge of the reference background image as the reference edge of the image to be detected, and fuse the reference edge with the image to be detected in the channel dimension to obtain the fusion feature;

[0012] Step 4: Image restoration: the fused features are passed into the image restoration network for restoration, and a reconstructed image aligned with the image to be detected is output;

[0013] Step 5: Post-processing: Calculate the residual image between the generated reconstructed image and the image to be detected, screen the allowable defects, and determine whether the input image has defects.

[0014] In the above method, step 1 specifically includes the following steps:

[0015] Step 1.1: Input the positive sample into the feature extractor trained on the ImageNet dataset.

[0016] Step 1.2: Generate a 512-dimensional feature vector for each positive sample and store it in the reference base map library.

[0017] In the above method, step 2 specifically includes the following steps:

[0018] Step 2.1, input the image to be detected into the feature extractor to obtain a 512-dimensional feature vector;

[0019] Step 2.2, calculate the cosine similarity with the feature vectors in the reference base map library respectively;

[0020] Step 2.3, select the sample with the highest similarity as the reference background;

[0021] The formula for calculating cosine similarity is as follows:

[0022]

[0023] where x i ,y i They represent a sample in the reference base map library and the i-th element of the feature vector of the image to be detected, respectively, and n is the dimension of the feature vector.

[0024] In the above method, step 3 specifically includes the following steps:

[0025] Extract the edge of the reference background image obtained from the reference background image library in step 2 as the reference edge of the image to be detected, and fuse the reference edge with the image to be detected in the channel dimension;

[0026] The fusion includes connecting the edge image with the image to be detected in the channel dimension. As the input of step 4, the size of the fused feature is (N, 4, H, W), where N is the number of images in a batch input to the model, and H and W are the height and width of the image to be detected, respectively.

[0027] In the above method, the structure of the image restoration network in step 4 includes a generator and a discriminator.

[0028] The generator consists of an encoder and a decoder.

[0029] The encoder extracts the features of the image to be detected that is fused with the reference edge in step 3 to obtain a feature map of the image to be detected;

[0030] The decoder decodes the feature map to generate a defect-free reconstructed image;

[0031] The discriminator is a fully convolutional neural network. By downsampling the reconstructed image, the output size is (N, 1, H / 16, W / 16) feature layer. Each element represents the authenticity of the 16×16 sub-block in the reconstructed image. If it is true, it indicates that the reconstructed image quality is good, otherwise it is poor.

[0032] At the same time, the discriminator provides gradient information for optimizing the parameters of the generator;

[0033] Using the gradient information provided by the discriminator, the parameters of the generator are optimized through the back-propagation algorithm, forcing the generator to generate more realistic reconstructed images;

[0034] Through fine-grained discriminator evaluation, the generation quality of each sub-block in the reconstructed image can be more accurately controlled, so that the generated image is closer to the real image in details.

[0035] In the above method, step 5 includes calculating a residual image between the normal image generated in step 4 and the image to be detected, the highlight part of the residual image is the defect position, and the allowable defects are screened through threshold segmentation, contour search, and contour filtering steps. If the number of contours outputted in the end is greater than 0, it is judged that the image to be detected has defects.

[0036] In the above method, the image restoration model training in step 4 includes the following steps:

[0037] Step 4.1, constructing a data set for the defect image to obtain a defect data set;

[0038] Step 4.2, automatically generate a data set for normal images to obtain a training data set;

[0039] Step 4.3, performing model training processing on the training data to obtain an image restoration model;

[0040] Step 4.4: After the model training is completed, the defect image is processed by model deployment to obtain a normal image.

[0041] In the above method, step 4.1 comprises the following steps:

[0042] Step 4.1.1, collecting defect sub-images and corresponding masks of the defect image from the existing data, wherein the defect sub-image is an image block where a horizontal enclosing rectangle of each defect area in the defect image is located;

[0043] Step 4.1.2: Store the defect sub-image and the corresponding mask into the defect library to ensure that the existing defect types are covered.

[0044] In the above method, step 4.2 comprises the following steps:

[0045] Step 4.2.1, select a batch of normal and defect-free images from the existing data, and select a batch of normal images that can cover different poses of the target and the corresponding 512-dimensional feature vectors as the base image library;

[0046] Step 4.2.2, mix the defect at a random position of each normal image, use the mixed image as the defect image, and search the base image library for the image with the highest similarity to the defect image as the reference image;

[0047] Step 4.2.3, perform threshold segmentation and edge extraction on the reference image to output the reference edge;

[0048] Step 4.2.4: A set of training data includes: defect images and reference edges as input, and normal images as output.

[0049] In the above method, step 4.3 comprises the following steps:

[0050] Step 4.3.1, fuse the defect image and the reference image in the channel dimension, and output a tensor with a shape of (N, 4, H, W) as the input of the image restoration model generator;

[0051] Step 4.3.2: After the generator calculates, the output is the reconstructed image, and the style loss is calculated with the real image;

[0052] Step 4.3.3: Input the reconstructed image into the discriminator for feature extraction, and use the pixel block with a width and height of 16 as the image sub-block to judge the authenticity of each sub-block;

[0053] Step 4.3.4, if the judgment is true, it indicates that the reconstructed image quality is good, otherwise it is poor; at the same time, the gradient optimization generator parameters are provided;

[0054] Step 4.3.5: More fine-grained control of the generation quality of each sub-block in the reconstructed image makes the generated image more realistic in details.

[0055] In the above method, step 4.4 comprises the following steps:

[0056] Step 4.4.1, take out the generator part as the image restoration model;

[0057] Step 4.4.2, input the image to be detected and the reference edge image, and reconstruct the normal image after calculation by the generator;

[0058] Step 4.4.3: Post-process the reconstructed image to output defect information.

[0059] Because the present invention adopts the above technical means, it has the following beneficial effects:

[0060] 1. No need to manually label defect locations: Traditional defect detection methods usually require labeling of a large number of defect samples for supervised training of the model. This method collects defect sub-images and corresponding masks from images with existing defects, mixes them on normal images, randomly generates different defect images, and generates corresponding labels. A large number of labeled data sets can be automatically generated without manual labeling.

[0061] 2. Template edge guidance: The existing image restoration methods based on image generation have poor restoration quality for high-frequency parts in images. The present invention matches images with high similarity to defective images in the base image library, extracts edges from them, and inputs reference edges and defective images into the image restoration model to generate normal images. The present invention inputs the edge features of the normal image that is most similar to the defective image into the network together with the defective image. The edge features of the normal image can guide the model to more accurately restore the defective image at the edge, thus solving the problem of poor restoration quality at the edge of the existing algorithm, improving the recall rate of defect detection and reducing the false detection rate at the edge of the image.

[0062] 3. The details of the reconstructed image are more realistic: The reconstructed image should differ from the defect image only at the defect location, so it is necessary to ensure the consistency between the reconstructed image and the defect image in the non-defect area, otherwise redundant noise will be generated when calculating the residual image between the defect image and the reconstructed image. By judging the authenticity of each sub-block of the reconstructed image and controlling the generation quality of the reconstructed image in a more fine-grained manner, the reconstructed image is more similar to the defect image in the non-defect area, solving the problem of redundant noise in the residual image between the reconstructed image and the defect image, and reducing the false detection rate of the defect image in the non-defect area.

[0063] 4. Strong generalization ability: In the generated defect images, the location and number of defects are diverse and random, which can force the model to repair a normal image aligned with any type of defect image. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 A simplified flow chart of the solution of the present invention;

[0065] Figure 2 It is the model structure diagram;

[0066] Figure 3 Automatically generate a simple diagram of the process for the dataset. DETAILED DESCRIPTION

[0067] 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.

[0068] 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.

[0069] Example 1

[0070] The system used in the present invention is based on a product assembly line. The product of the photoelectric switch triggers a specific stroboscopic light source and camera shooting. The acquired pictures are input into the algorithm server for defect detection.

[0071] The implementation of the present invention consists of the following steps, as shown in the flow chart: Figure 1 As shown:

[0072] Step 1: Establishment of reference basemap library

[0073] The reference base map library consists of several positive samples and their corresponding feature vectors, which is the standard for normal samples. All positive samples are input into the feature extractor trained on the ImageNet dataset, and a 512-dimensional feature vector is generated for each positive sample and stored in the reference base map library.

[0074] Step 2: Match the base map

[0075] Input an image to be detected, input it into the feature extractor to obtain a 512-dimensional feature vector, calculate the cosine similarity with the feature vectors in the reference base map library, and select the sample with the highest similarity as the reference base map. The formula for calculating cosine similarity is as follows:

[0076]

[0077] where x i ,y i They represent a sample in the reference base map library and the i-th element of the feature vector of the image to be detected, respectively, and n is the dimension of the feature vector.

[0078] Step 3: Feature Fusion

[0079] The reference background image obtained from the reference background image library in step 2 is subjected to edge extraction as the reference edge of the image to be detected, which is used to guide the model to repair the image to be detected. The reference edge is fused with the image to be detected in the channel dimension. The fusion includes connecting the edge image with the image to be detected in the channel dimension as the input of step 4. The size of the fused feature is (N, 4, H, W), where N is the number of images in a batch input to the model, and H and W are the height and width of the input image, respectively. Existing methods usually reconstruct normal images directly from defective images. Such methods perform poorly at the edges of the image and have poor reconstruction quality. The present invention fuses the edge features of normal images similar to the defective images, and uses the complete edge features to guide the model to repair at the edges, so that the quality of the reconstructed image at the edges can be closer to that of the normal image.

[0080] Step 4: Image restoration

[0081] The features fused in step 3 are passed to the image restoration network for restoration, and finally a reconstructed image aligned with the image to be detected is output. The structure of the image restoration network is as follows: Figure 2 As shown in the figure, it includes a generator and a discriminator. The generator includes an encoder and a decoder. The encoder extracts features from the image to be detected that is fused with the reference edge in step 3 to obtain a feature map of the image to be detected. The decoder decodes the feature map to generate a defect-free reconstructed image. The discriminator is a fully convolutional neural network. By downsampling the reconstructed image, the output size is (N, 1, H / 16, W / 16) feature layer. Each element represents the authenticity of the 16×16 sub-block in the reconstructed image. If it is judged to be true, it indicates that the reconstructed image quality is good, otherwise it is poor. At the same time, the gradient is provided to optimize the generator parameters, forcing the generator to generate a more realistic reconstructed image. Finer-grained control of the generation quality of each sub-block in the reconstructed image makes the details of the generated image more realistic.

[0082] Step 5: Post-processing

[0083] The residual image is calculated by comparing the normal image generated in step 4 with the image to be tested. The highlighted part of the residual image is the defect location. The allowed defects are screened through threshold segmentation, contour search, and contour filtering steps. If the number of contours outputted in the end is greater than 0, it is judged that the input image has defects.

[0084] The above is the completion of a defect detection. The reasoning time for this detection is 40ms, which meets the cycle time of most production lines.

[0085] Furthermore, the image restoration model training in step 4 includes the following steps:

[0086] Building a defect dataset

[0087] The defect sub-images and corresponding masks of the defect images are collected from the existing data, where the defect sub-image is the image block where the horizontal enclosing rectangle of each defect area in the defect image is located. The defect dataset is guaranteed to cover the existing defect types, and the defect sub-images and corresponding masks are stored in the defect library.

[0088] Automatic data set generation

[0089] The process of generating the dataset is as follows: Figure 3As shown. The dataset is constructed by selecting a batch of normal images without defects from the existing data, and selecting a batch of normal images that can cover different positions of the target and the corresponding 512-dimensional feature vectors as the base map library. The random position of each normal image is mixed with the defect, and the mixed image is used as the defect image. The image with the highest similarity to the defect image is searched in the base map library as the reference image. The reference image is thresholded and edge extracted to output the reference edge. A set of training data contains: defect images and reference edges as input, and normal images as output.

[0090] Model Training

[0091] The defect image and the reference image are fused in the channel dimension, and the output tensor of shape (N, 4, H, W) is used as the input of the image restoration model generator. After calculation by the generator, the output is the reconstructed image. The style loss is calculated between the reconstructed image and the real image. The reconstructed image is input into the discriminator for feature extraction, and the pixel blocks with a width and height of 16 are used as image sub-blocks. The authenticity of each sub-block is judged separately. If it is judged to be true, it indicates that the reconstructed image quality is good, otherwise it is poor; at the same time, the gradient optimization generator parameters are provided. More fine-grained control of the generation quality of each sub-block in the reconstructed image makes the details of the generated image more realistic.

[0092] Model deployment

[0093] After the model training is completed, the generator part is taken out as the image restoration model, the image to be detected and the reference edge image are input, the normal image is reconstructed after calculation by the generator, and the reconstructed image is post-processed to output the defect information.

[0094] Based on the description of the above embodiments, the technical solution of the present invention has the following features:

[0095] The image restoration algorithm based on the edge guidance of the reference background selects the image most similar to the image to be detected from the existing normal images as the reference edge to guide the model to repair the defective image.

[0096] The reconstructed image sub-block discriminator discriminates the authenticity of each 16×16 sub-block of the reconstructed image, controls the quality of the reconstructed image in a finer granularity, reduces the noise of the residual image between the reconstructed image and the defective image, and reduces the false detection rate.

[0097] The data set is automatically generated, and the defect sub-image and the corresponding mask are randomly mixed in the normal image to generate the defect image. At the same time, the base image that is most similar to the generated defect image is matched in the base image library as the reference image, and the edge of the reference image is extracted as the reference edge. The defect image, reference edge and normal image are taken as a set of samples.

[0098] Defective images are randomly synthesized using defect sub-images and corresponding defect masks with normal images. This method does not require manual image annotation and can automatically generate a large number of annotated data sets, reducing the investment of a lot of manpower and material resources.

[0099] The edge of the normal image that is most similar to the defect image is used as a guide, so that the reconstructed image generated by the model has a more natural transition at the edge and the generated reconstructed image is more realistic.

Claims

1. An industrial defect detection method based on image restoration, characterized in that: The following steps are involved: Step 1: Establish a reference base map library, which includes positive samples and their corresponding feature vectors. As the standard of normal samples, positive samples generate feature vectors through feature extractors trained on the ImageNet dataset and store them in the library. Step 2: Match the background image. Input an image to be detected, calculate the cosine similarity between the image and the feature vector in the reference background image library, and select the reference background image with the highest similarity. Step 3: Feature fusion: extract the edge of the reference background image as the reference edge of the image to be detected, and fuse the reference edge with the image to be detected in the channel dimension to obtain the fusion feature; Step 4: Image restoration: the fused features are passed into the image restoration network for restoration, and a reconstructed image aligned with the image to be detected is output; The structure of the image restoration network in step 4 includes a generator and a discriminator. The generator consists of an encoder and a decoder. The encoder extracts the features of the image to be detected that is fused with the reference edge in step 3 to obtain a feature map of the image to be detected; The decoder decodes the feature map to generate a defect-free reconstructed image; The discriminator is a fully convolutional neural network. By downsampling the reconstructed image, the output size is (N, 1, H / 16, W / 16) feature layer. Each element represents the authenticity of the 16×16 sub-block in the reconstructed image. If it is true, it indicates that the reconstructed image quality is good, otherwise it is poor; At the same time, the discriminator provides gradient information for optimizing the parameters of the generator; Using the gradient information provided by the discriminator, the parameters of the generator are optimized through the back-propagation algorithm, forcing the generator to generate more realistic reconstructed images; Through fine-grained discriminator evaluation, the generation quality of each sub-block in the reconstructed image can be more accurately controlled, so that the generated image is closer to the real image in details; Step 5: Post-processing: Calculate the residual image between the generated reconstructed image and the image to be detected, screen the allowable defects, and determine whether the image to be detected has defects.

2. The industrial defect detection method based on image restoration according to claim 1 is characterized in that: Step 1 specifically includes the following steps: Step 1.1: Input the positive sample into the feature extractor trained on the ImageNet dataset. Step 1.2: Generate a 512-dimensional feature vector for each positive sample and store it in the reference base map library.

3. The industrial defect detection method based on image restoration according to claim 1 is characterized in that: Step 2 specifically includes the following steps: Step 2.1, input the image to be detected into the feature extractor to obtain a 512-dimensional feature vector; Step 2.2, calculate the cosine similarity with the feature vectors in the reference base map library respectively; Step 2.3, select the sample with the highest similarity as the reference background; The formula for calculating cosine similarity is as follows: in They represent a sample in the reference base map library and the i-th element of the feature vector of the image to be detected, respectively, and n is the dimension of the feature vector.

4. The industrial defect detection method based on image restoration according to claim 1 is characterized in that: Step 3 specifically includes the following steps: Extract the edge of the reference background image obtained from the reference background image library in step 2 as the reference edge of the image to be detected, and fuse the reference edge with the input image in the channel dimension; The fusion includes connecting the edge image with the image to be detected in the channel dimension. As the input of step 4, the size of the fused feature is (N, 4, H, W), where N is the number of images in a batch input to the model, and H and W are the height and width of the image to be detected, respectively.

5. The industrial defect detection method based on image restoration according to claim 1 is characterized in that: Step 5 includes calculating a residual image between the reconstructed image generated in step 4 and the image to be detected. The highlighted portion of the residual image is the defect location. The allowable defects are screened through threshold segmentation, contour search, and contour filtering steps. If the number of contours outputted in the end is greater than 0, it is determined that the image to be detected has defects.

6. The industrial defect detection method based on image restoration according to claim 1 is characterized in that: The image restoration model training in step 4 includes the following steps: Step 4.1, constructing a data set for the defect image to obtain a defect data set; Step 4.2, automatically generate a data set for normal images to obtain a training data set; Step 4.3, performing model training processing on the training data to obtain an image restoration model; Step 4.4: After the model training is completed, use the model to process the defect image to obtain a normal image.

7. The industrial defect detection method based on image restoration according to claim 5 is characterized in that: Step 4.1 includes the following steps: Step 4.1.1, collecting defect sub-images and corresponding masks of the defect image from the existing data, wherein the defect sub-image is an image block where a horizontal enclosing rectangle of each defect area in the defect image is located; Step 4.1.2: Store the defect sub-image and the corresponding mask into the defect library to ensure that the existing defect types are covered.

8. The industrial defect detection method based on image restoration according to claim 5 is characterized in that: Step 4.2 includes the following steps: Step 4.2.1, select a batch of normal and defect-free images from the existing data, and select a batch of normal images that can cover different poses of the target and the corresponding 512-dimensional feature vectors as the base image library; Step 4.2.2, mix the defect at a random position of each normal image, use the mixed image as the defect image, and search the base image library for the image with the highest similarity to the defect image as the reference image; Step 4.2.3, perform threshold segmentation and edge extraction on the reference image to output the reference edge; Step 4.2.4: A set of training data includes: defect images and reference edges as input, and normal images as output.

9. The industrial defect detection method based on image restoration according to claim 5, characterized in that: Step 4.3 includes the following steps: Step 4.3.1, fuse the defect image and the reference image in the channel dimension, and output a tensor of shape (N, 4, H, W) as the input of the image restoration model generator; Step 4.3.2: After the generator calculates, the output is the reconstructed image, and the style loss is calculated with the real image; Step 4.3.3: Input the reconstructed image into the discriminator for feature extraction, and use the pixel block with a width and height of 16 as the image sub-block to judge the authenticity of each sub-block; Step 4.3.4, if the judgment is true, it indicates that the reconstructed image quality is good, otherwise it is poor; at the same time, the gradient optimization generator parameters are provided; Step 4.3.5: Control the quality of each sub-block in the reconstructed image in a more fine-grained manner, so that the details of the generated image are more realistic; Step 4.4 includes the following steps: Step 4.4.1, take out the generator part as the image restoration model; Step 4.4.2, the image to be detected and the reference edge image are calculated by the generator to reconstruct a normal image; Step 4.4.3: Post-process the reconstructed image to output defect information.