Defect detection method and device, equipment, storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI WINGTECH INFORMATION TECH CO LTD
- Filing Date
- 2022-07-28
- Publication Date
- 2026-08-07
AI Technical Summary
但在实际生产过程中,工业产品上存在的缺陷种类是千变万化的,显然无法获取到各种未知的缺陷类型;并且获取已知类型的缺陷的成本也是极高的,有时几千个样品中只有几例缺陷样品,甚至有些类别缺陷从未出现过
确定模块,用于根据待检测图像的第一特征向量和第一生成图像的第二特征向量、以及待检测图像的像素值和第一生成图像的像素值,确定待检测图像是否为缺陷图像。
Smart Images

Figure CN115239672B_ABST
Abstract
Description
Technical Field
[0001] This application relates to image processing technology, and to, but is not limited to, a defect detection method, apparatus, device, and storage medium. Background Technology
[0002] In industrial production, it is necessary to detect defects such as misalignment, breakage, and foreign objects in various industrial products. For example, in the quality inspection of mobile phone products, it is necessary to inspect the appearance of the front shell of the phone. The important component of the front shell of the phone is the rubber sleeve. Therefore, in this case, the main purpose is to detect defects in the rubber sleeve.
[0003] In related technologies, defect detection in industrial products mostly relies on training detection models based on positive and negative samples, which requires a large number of defect samples. However, in actual production processes, the types of defects present in industrial products are extremely diverse, making it impossible to obtain all unknown defect types. Furthermore, the cost of obtaining known defect types is extremely high; sometimes only a few defective samples out of thousands are found, and some defect categories have never even appeared before. Therefore, defect detection models trained using the above methods require manual collection and labeling of a large number of defect samples, and are only applicable to specific defect categories, not to a wider range of defect types, resulting in insufficient detection accuracy. Summary of the Invention
[0004] In view of this, the defect detection method, apparatus, device, and storage medium provided in the embodiments of this application do not rely on defect samples when training the detection model, thereby reducing the cost of manually collecting various types of defect samples, and can be applied to more types of defect detection, while improving detection accuracy. The defect detection method, apparatus, device, and storage medium provided in the embodiments of this application are implemented as follows: The defect detection method provided in this application includes: In the trained generative adversarial network, the image to be detected is dimensionality reduced to obtain the first feature vector in the lower dimension; the image to be detected includes defect-free images and defective images; the trained generative adversarial network is obtained by training the generative adversarial network to be trained based on multiple defect-free images; The first feature vector in the low dimension is subjected to high-dimensional mapping to obtain a first generated image with a dimension higher than that of the image to be detected. The first generated image is subjected to dimensionality reduction processing to obtain a second feature vector in a lower dimension; the dimension of the second feature vector is the same as the dimension of the first feature vector. Based on the first feature vector of the image to be detected, the second feature vector of the first generated image, and the pixel values of the image to be detected and the first generated image, it is determined whether the image to be detected is a defective image.
[0005] In the embodiments of this application, on the one hand, when training the defect detection model, it is trained only on defect-free images and does not rely on defect samples, thereby reducing the cost of manually collecting various types of defect samples and being applicable to more types of defect detection; on the other hand, defect detection of the image to be detected is performed from both the feature vector and pixel value of the image, which can improve the detection accuracy.
[0006] In some embodiments, determining whether an image to be detected is a defective image based on a first feature vector of the image to be detected and a second feature vector of the first generated image, as well as pixel values of the image to be detected and pixel values of the first generated image, includes: If the difference between the first feature vector and the second feature vector is greater than the first threshold, the image to be detected is determined to be an abnormal image; based on the difference between the pixel value of the image to be detected that is determined to be an abnormal image and the pixel value of the corresponding first generated image, a differential heat map corresponding to the image to be detected that is determined to be an abnormal image is obtained; based on the number of pixels in the defect area in the differential heat map, it is determined whether the image to be detected is a defective image.
[0007] In some embodiments, determining whether an image to be detected is a defective image based on the number of pixels in the defect region of the differential heatmap includes: The differential heatmap is processed to extract the defect region from the differential heatmap; if the number of pixels in the defect region is greater than the second threshold, the image to be detected is determined to be a defect image.
[0008] In some embodiments, the generative adversarial network includes a generator network and a discriminator network, and the generative adversarial network is obtained in advance by the following method: The defect-free image is input into the generator network to be trained for dimensionality reduction, resulting in a third feature vector in the lower dimension. This third feature vector is then input into the generator of the generator network to be trained for high-dimensional mapping, resulting in a second generated image with a higher dimension than the defect-free image. The defect-free image and the second generated image are then input into the discriminator network to be trained for authenticity determination, obtaining the similarity probability that the second generated image is a defect-free image. If the similarity probability is less than a third threshold, a target loss function is determined. Based on the target loss function, the parameter values of the generator network and the discriminator network are adjusted, resulting in the adjusted generator network and the adjusted discriminator network. The parameter values of the generator network and the discriminator network are further adjusted based on the next defect-free image until the probability output by the current discriminator network is greater than or equal to the third threshold. The currently trained generative adversarial network is then used as the trained generative adversarial network.
[0009] In some embodiments, if the similarity probability is less than a third threshold, the target loss function is determined, including: If the similarity probability is less than the third threshold, a first loss function is determined based on the third feature vector of the defect-free image and the fourth feature vector corresponding to the second generated image. The fourth feature vector is obtained by inputting the second generated image into the discriminative network to be trained and performing dimensionality reduction. The dimension of the fourth feature vector is the same as the dimension of the third feature vector. The first loss function is used to characterize the feature differences between the second generated image and the defect-free image in low dimension. A second loss function is determined based on the pixel values of the defect-free image and the second generated image. The second loss function is used to characterize the similarity between the second generated image and the defect-free image. A third loss function is determined based on the differences between the image features of the defect-free image and the image features of the second generated image. A target loss function is determined based on the first loss function, the second loss function, and the third loss function.
[0010] In some embodiments, the method further includes: acquiring detection results of multiple images to be detected obtained within a preset time period; determining the accuracy of each detection result; and adjusting the first threshold if the number of accuracy rates less than a preset standard exceeds a fourth threshold.
[0011] In some embodiments, before performing dimensionality reduction processing on the image to be detected, the method further includes: preprocessing the image to be detected to obtain an image to be detected with a standard size.
[0012] The defect detection device provided in this application includes: The dimensionality reduction module is used to perform dimensionality reduction processing on the image to be detected in the trained generative adversarial network to obtain the first feature vector in the lower dimension; the image to be detected includes defect-free images and defective images; the trained generative adversarial network is obtained by training the generative adversarial network to be trained based on multiple defect-free images; The high-dimensional mapping module is used to perform high-dimensional mapping processing on the first feature vector in the low dimension to obtain a first generated image with a dimension higher than the image to be detected. The dimensionality reduction processing module is further used to perform dimensionality reduction processing on the first generated image to obtain a second feature vector in a lower dimension; the dimension of the second feature vector is the same as the dimension of the first feature vector. The determination module is used to determine whether the image to be detected is a defective image based on the first feature vector of the image to be detected and the second feature vector of the first generated image, as well as the pixel values of the image to be detected and the pixel values of the first generated image.
[0013] The computer device provided in this application includes a memory and a processor. The memory stores a computer program that can run on the processor. When the processor executes the program, it implements the method described in this application.
[0014] The computer-readable storage medium provided in this application embodiment stores a computer program thereon, which, when executed by a processor, implements the method described in this application embodiment.
[0015] The defect detection method, apparatus, computer equipment, and computer-readable storage medium provided in this application embodiment, on the one hand, train the defect detection model only based on defect-free images and do not rely on defect samples, thereby reducing the cost of manually collecting various types of defect samples and being applicable to more types of defect detection; on the other hand, by performing defect detection on the image to be detected from both the feature vector and pixel value aspects of the image, the detection accuracy can be improved, thereby solving the technical problems proposed in the background art. Attached Figure Description
[0016] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application.
[0017] Figure 1 Example images of defective and defect-free images provided in embodiments of this application; Figure 2 A schematic diagram illustrating the implementation flow of the defect detection method provided in the embodiments of this application; Figure 3 This is a schematic diagram of the structure of a generative adversarial network provided in an embodiment of this application; Figure 4 A schematic diagram illustrating the implementation flow of the defect detection method provided in the embodiments of this application; Figure 5 Comparison chart of results of the defect detection method provided in the embodiments of this application; Figure 6 A schematic diagram illustrating the training implementation process of the generative adversarial network provided in this application embodiment; Figure 7 A schematic diagram illustrating the implementation flow of the defect detection method provided in the embodiments of this application; Figure 8 This is a schematic diagram of the defect detection device provided in the embodiments of this application; Figure 9 A schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the specific technical solutions of this application will be further described in detail below with reference to the accompanying drawings of the embodiments of this application. The following embodiments are used to illustrate this application, but are not intended to limit the scope of this application.
[0019] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0020] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0021] It should be noted that the terms "first, second, third" used in the embodiments of this application are used to distinguish similar or different objects and do not represent a specific order of objects. It can be understood that "first, second, third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0022] In industrial production, it is necessary to detect defects such as misalignment, breakage, and foreign objects in various industrial products. Figure 1 As shown, exemplary illustrations of defect-free and defective images are provided. Figure 1 It can be seen that defect-free images can tolerate a certain range of fluctuations, including minor positional variations, small particles or foreign objects, and slight changes in brightness; while defective images exhibit distinct differences, including clearly visible misalignment, damage, and the presence of foreign objects. For example... Figure 1 The provided defective image examples, from left to right, are: image damage, excessive image deflection, excessive image misalignment, foreign objects in the image, and image holes. However, in actual production, defects include, but are not limited to, the above types.
[0023] Currently, defect detection for most industrial products still relies primarily on manual observation. Compared to large-scale automated inspection, manual inspection is susceptible to subjective factors and is inefficient. In recent years, with advancements in computer hardware, computer vision technology has been gradually applied to the automated inspection of products on industrial production lines.
[0024] Appearance defect detection is an important branch of computer vision tasks, mainly divided into two categories: traditional algorithms and deep learning algorithms. In the field of traditional image processing, fixed operators are designed to detect defects of a specified category. This type of method has good detection performance for defects with fixed shapes. In the field of deep learning, defect detection is mainly accomplished in a data-driven manner. A large number of positive and negative samples are collected and labeled to train the detection model. The model has good generalization performance for labeled defect types and good detection applicability.
[0025] In traditional image processing, fixed operator detection patterns are only applicable to specific defect types and lack generalization. In deep learning, while general detection models can detect multiple defect types through self-learning, their training relies heavily on high-quality data annotation (i.e., defective sample data). This requires manual collection and annotation of large amounts of high-quality data, which limits the detection of defect types beyond the labeled range. In actual production, the types of defects on industrial products are highly varied, making it impossible to obtain information on all unknown defect types. Furthermore, acquiring known defect types is extremely costly; sometimes only a few defective samples out of thousands are found, and some defect categories have never even appeared before. Therefore, in actual production, training a defect model using traditional methods requires manually collecting and annotating a large number of defect samples, and it is only applicable to specific defect categories, not a wider range of defect types. Additionally, defect detection models trained using these traditional methods lack sufficient accuracy when performing product inspections.
[0026] In view of this, embodiments of this application provide a defect detection method. This method is applied to an electronic device, which can be various types of devices with information processing capabilities. For example, the electronic device may include a personal computer, laptop computer, PDA, or server; the electronic device may also be a mobile terminal, such as a mobile phone, in-vehicle computer, tablet computer, or projector. The function implemented by this method can be achieved by the processor in the electronic device calling program code. Of course, the program code can be stored in a computer storage medium. Therefore, the electronic device includes at least a processor and a storage medium.
[0027] Figure 2 This is a schematic diagram illustrating the implementation process of the defect detection method provided in this application. When training the defect detection model, it is trained only on defect-free images, thereby reducing the cost of manually collecting various types of defect samples, making it applicable to more types of defect detection, and improving detection accuracy. Figure 2 As shown, the method may include the following steps 201 to 204: Step 201: In the trained generative adversarial network, the image to be detected is dimensionality reduced to obtain the first feature vector in the lower dimension; the image to be detected includes defect-free images and defective images; the trained generative adversarial network is obtained by training the generative adversarial network to be trained based on multiple defect-free images.
[0028] Understandably, in actual production processes, the types of defects on industrial products are incredibly diverse, making it impossible to obtain all unknown defect types. Furthermore, acquiring known defect types is extremely costly; sometimes only a few defective samples out of thousands are found, and some defect categories have never even appeared before. Therefore, training a generative adversarial network (GAN) based on positive and negative samples (i.e., defective and non-defective images) requires manually collecting and labeling a large number of defect samples, and it is only applicable to specific defect categories, not a wider range of defect types. Based on this, in this embodiment, when training the GAN, it relies only on non-defective sample images and not on defective samples, thereby reducing the cost of manually collecting various types of defect samples and enabling its application to more types of defect detection.
[0029] In the embodiments of this application, the images to be detected used for defect detection are all the same size, and the method for obtaining images of the same size is not limited. For example, in some embodiments, different products can be photographed using the same acquisition device with a fixed shooting height to obtain images of the same size taken at the same shooting angle. To improve the accuracy of detection, multiple candidate images can be acquired for the same product surface by adjusting the angle, lighting, filter, magnification, and focus of the acquisition device. These candidate images can then be processed using preset screening criteria, such as sharpness, to select the images to be detected before subsequent detection.
[0030] In other embodiments, if the initial images to be detected are of different sizes, they can be preprocessed before being input into the trained generative adversarial network to obtain images of standard size. Specifically, the preprocessing process can involve cutting the images to be detected according to a preset standard to obtain images of standard size.
[0031] In some embodiments, if the captured image to be detected is too large, it can be divided into multiple sub-images for easier detection. The specific sub-image size can be preset according to the actual situation. For example, for a 1000*800 image to be detected, the preset size is 100*8. Therefore, the image to be detected can be divided into 100*8 sub-images. In this way, each sub-image contains some features of the image to be detected, so that the characteristics of multiple sub-images can be used to jointly determine whether the image to be detected is a defective image.
[0032] In some embodiments, the generative adversarial network is a GANomaly network. The network structure of a GANomaly is as follows: Figure 3 As shown, the overall framework consists of three parts: The first part includes a generator network consisting of encoder 1 and generator, the second part includes discriminator encoder 2, and the third part includes discriminator encoder 3.
[0033] Understandably, when a model trained on a GANomaly network detects product defects, it no longer compares the distribution of products on an image, but rather makes a comparison within the latent space encoded in the image. The trained GANomaly network encodes positive sample images (i.e., defect-free images) and negative sample images (i.e., defective images). decoding The spatial differences generated after encoding are different. A defect detection model trained on normal samples will have different spatial differences when encoding negative sample images. decoding The spatial difference generated after encoding is greater than the spatial difference of the positive sample image.
[0034] Based on the above principles, in the embodiments of this application, the image to be detected can be... The image is input into encoder 1 of the GANomaly network, where it is encoded to obtain a low-dimensional encoded vector. (i.e., the first eigenvector).
[0035] Step 202: Perform high-dimensional mapping processing on the first feature vector in the low dimension to obtain a first generated image with a dimension higher than that of the image to be detected.
[0036] In some embodiments, after obtaining the first feature vector Then, it can be input into the generator of the GANomaly network for high-dimensional mapping processing, thereby obtaining a first generated image with a dimension higher than that of the image to be detected. .
[0037] Step 203: Perform dimensionality reduction processing on the first generated image to obtain a second feature vector in a lower dimension; the dimension of the second feature vector is the same as the dimension of the first feature vector.
[0038] In some embodiments, after obtaining the first generated image Then, it is input into the discriminative encoder 2 of the GANomaly network, which encodes the first generated image to obtain a low-dimensional encoded vector. (i.e., the second eigenvector).
[0039] By performing steps 201 to 203 above, feature vectors of the image to be detected and the corresponding first generated image in the same dimension can be obtained, thereby allowing for further determination of the differences between the two feature vectors in the latent space.
[0040] Step 204: Determine whether the image to be detected is a defective image based on the first feature vector of the image to be detected, the second feature vector of the first generated image, the pixel values of the image to be detected, and the pixel values of the first generated image.
[0041] In this embodiment of the application, when determining whether the image to be detected is a defective image, the determination is not based solely on the feature vectors of the obtained image to be detected and the corresponding first generated image in the same dimension, but rather comprehensively considers the feature vectors of the image and the pixel values of the image to be detected and the corresponding first generated image, thereby improving the detection accuracy.
[0042] In the embodiments of this application, on the one hand, when training the defect detection model, it is trained only on defect-free images and does not rely on defect samples, thereby reducing the cost of manually collecting various types of defect samples and being applicable to more types of defect detection; on the other hand, defect detection of the image to be detected is performed from both the feature vector and pixel value of the image, which can improve the detection accuracy.
[0043] This application provides another defect detection method. Figure 4 This is a schematic diagram illustrating the implementation process of the defect detection method in an embodiment of this application, as shown below. Figure 4 As shown, the method may include the following steps 401 to 408: Step 401: In the trained generative adversarial network, the image to be detected is dimensionality reduced to obtain the first feature vector in the lower dimension; the image to be detected includes defect-free images and defective images; the trained generative adversarial network is obtained by training the generative adversarial network to be trained based on multiple defect-free images.
[0044] Step 402: Perform high-dimensional mapping processing on the first feature vector in the low dimension to obtain a first generated image with a dimension higher than that of the image to be detected.
[0045] Step 403: Perform dimensionality reduction processing on the first generated image to obtain a second feature vector in a lower dimension; the dimension of the second feature vector is the same as the dimension of the first feature vector.
[0046] Step 404: Determine whether the difference between the first feature vector and the second feature vector is greater than the first threshold; if yes, proceed to step 405; otherwise, proceed to step 408.
[0047] Here, if it is determined that the difference between the first feature vector corresponding to the image to be detected and the second feature vector corresponding to the first generated image is large, based on the characteristic that the feature vector difference in the latent space after reconstruction of the positive sample image (i.e. the defect-free image) is small, it can be determined that the image with a large difference in the feature vector in the latent space after reconstruction is an abnormal image.
[0048] Of course, if the feature vectors of the image to be detected have small differences in the latent space after reconstruction, it can be said that the image to be detected is a defect-free image.
[0049] In this process, when training the generative adversarial network, steps 601 to 605 in the following embodiment can be executed to obtain the third feature vector corresponding to the defect-free image and the fourth feature vector corresponding to the second generated image corresponding to the defect-free image, thereby obtaining the difference between the third feature vector and the fourth feature vector. After obtaining the difference between the feature vectors corresponding to multiple defect-free images, a first threshold can be determined from it.
[0050] In some embodiments, the largest gap among multiple gaps can be determined as the first threshold.
[0051] Step 405: Determine that the image to be detected is an abnormal image.
[0052] Here, the image to be detected is determined to be an abnormal image only based on the large difference in feature vectors in the latent space, and is not directly determined to be a defective image. In this embodiment of the application, in order to avoid over-detection, images to be detected that should not originally be evaluated as defective images are evaluated as defective images. After determining that the image to be detected is an abnormal image, step 406 can be executed to continue to re-detect the images to be detected that have been determined to be abnormal images, thereby improving the detection accuracy.
[0053] Step 406: Based on the difference between the pixel values of the image to be detected that is determined to be an abnormal image and the pixel values of the corresponding first generated image, a differential heatmap corresponding to the image to be detected that is determined to be an abnormal image is obtained.
[0054] Here, to obtain the differential heatmap corresponding to the image to be detected that is determined to be an anomaly, the image to be detected and the corresponding first generated image can be normalized to obtain a first tensor corresponding to the image to be detected and a second tensor corresponding to the first generated image. A tensor can be considered a container for storing feature data, representing the sum of features. Calculating the difference between the first and second tensors yields the differential tensor, which is then mapped back to an image to obtain the differential heatmap. This process maximizes the highlighting of the differences between the generated image and the image to be detected.
[0055] like Figure 5 As shown, a schematic diagram of the image to be detected, the generated image, and the differential heatmap between the two is presented. It can be seen that the differential heatmap can highlight the pixel differences between the generated image and the image to be detected to the greatest extent, that is, it can display the defective parts in the defective image.
[0056] Step 407: Determine whether the image to be detected is a defective image based on the number of pixels in the defect area in the differential heat map.
[0057] In some embodiments, step 407 can be achieved by performing the following steps 4071 to 4072: Step 4071: Extract the differential heat map to obtain the defect area in the differential heat map.
[0058] Here, the method of extracting and processing the differential heatmap is not limited. For example, Gaussian filtering can be applied to the differential heatmap to obtain a noise-filtered differential heatmap; then, morphological processing can be performed on the noise-filtered differential heatmap to obtain the final mask result. The mask result can well express the differences between pixels.
[0059] Step 4072: If the number of pixels in the defective region is greater than the second threshold, the image to be detected is determined to be a defective image.
[0060] like Figure 5 As shown, the mask result image can clearly display the defect area. The more pixels in the defect area, the larger the defect in the image to be detected, and the easier it is to be identified as a defective image.
[0061] In some embodiments, the number of pixels in the defective region can be controlled within 8*8. By comparison, the defective image can be finally identified from the image to be detected that is determined to be an abnormal image.
[0062] As can be seen from the image results, for defect-free samples, the resulting mask image shows almost no obvious white areas, while for samples with foreign objects, large offsets, or significant misalignments, the mask image shows more white areas. Post-processing quantifies these characteristics, and threshold filtering yields the detection results.
[0063] Step 408: Determine that the image to be detected is a defect-free image.
[0064] In some embodiments, after defect detection is completed on multiple images to be detected, the detection results of multiple images to be detected obtained within a preset time period can be obtained; the accuracy of each detection result can be determined; if the number of accuracy rates less than the preset standard exceeds the fourth threshold, the first threshold can be adjusted.
[0065] Specifically, after a period of testing, it can be determined whether the accuracy of the test results within a certain period of time reaches the preset standard. If it is less than the preset standard, the preset threshold is adjusted accordingly, so that the defect detection model can detect defective products more accurately and improve the efficiency of defect detection.
[0066] For example, if the calculated accuracy rate over a period of time is 92%, which is less than the preset standard of 95%, then the previously preset first threshold can be adjusted, or the model can be updated to improve the detection accuracy.
[0067] In this embodiment of the application, the generative adversarial network includes a generator network and a discriminator network. A training method for a generative adversarial network is given below, including the following steps 601 to 606: Step 601: Input the defect-free image into the generator network to be trained for dimensionality reduction processing to obtain the third feature vector in low dimension.
[0068] It should be noted that the generative adversarial network is trained on defect-free images, which reduces the cost of manually collecting various types of defect samples and makes it applicable to more types of defect detection.
[0069] Step 602: Input the third feature vector into the generator of the generator network to be trained for high-dimensional mapping processing to obtain a second generated image with a dimension higher than that of the defect-free image.
[0070] As can be seen from the above embodiments, such as Figure 3 As shown, the generative adversarial network to be trained consists of three parts: the first part is a generative network composed of encoder 1 and generator; the second part is a discriminative encoder 2; and the third part is a discriminative encoder 3.
[0071] When training a generative adversarial network, defect-free images can be used. The image is input into encoder 1 of the GANomaly network, where it is encoded to obtain a low-dimensional encoded vector. (That is, the third eigenvector). Then, the third eigenvector... The image is fed into the generator of the GANomaly network for high-dimensional mapping, resulting in a second generated image with dimensions higher than the image to be detected. .
[0072] Step 603: Input the defect-free image and the second generated image into the discrimination network to be trained for authenticity discrimination, and obtain the similarity probability that the second generated image is a defect-free image.
[0073] Here, the defect-free image and the corresponding second generated image are input into the discriminative encoder 3 in the third part for authenticity judgment. Initially, the discriminative encoder 3 can classify the defect-free image as real and the second generated image as fake, and output the similarity probability between the second generated image and the defect-free image. Understandably, as the generative adversarial network iterates through training, it can continuously reduce the gap between the generated image and the corresponding defect-free image, enabling the generator to reconstruct a generated image similar to the defect-free image, that is, continuously increasing the similarity probability that the second generated image is a defect-free image.
[0074] In a specific training process, such as Figure 3 As shown, the latent variable can be set to 2000, the learning rate to 0.0001, the batch size to 8, the input image size to 128×128, and the number of iterations to 1000 epoches.
[0075] The specific parameters of the model are described below: Encoder 1 consists of 5 convolutional layers and 4 Leaky ReLU layers, with BtachNorm in the middle. The generator consists of 5 transposed convolutional layers and 4 RuLU layers, with BtachNorm in the middle, and the activation layer is the Tanh function. Discriminant encoder 2 consists of 5 convolutional layers and 4 Leaky ReLU layers, with BtachNorm in the middle. Discriminant encoder 3 consists of 5 convolutional layers and 4 Leaky ReLU layers, with BtachNorm in the middle, and the output layer is the sigmoid activation function. The specific structure is shown in Table 1. Table 1. GANormaly Model Structure
[0076] Step 604: If the similarity probability is less than the third threshold, determine the target loss function.
[0077] To improve the recognition accuracy of generative adversarial networks, the target loss function is defined as consisting of three parts. In some embodiments, the target loss function can be determined by performing steps 6041 to 6044 in the following embodiments: Step 6041: If the similarity probability is less than the third threshold, determine the first loss function based on the third feature vector of the defect-free image and the fourth feature vector corresponding to the second generated image. The fourth feature vector is obtained by inputting the second generated image into the discriminant network to be trained for dimensionality reduction. The dimension of the fourth feature vector is the same as the dimension of the third feature vector. The first loss function is used to characterize the feature differences between the second generated image and the defect-free image in low dimension.
[0078] In some embodiments, the first loss function is the encoding loss, and the encoding loss The determination is shown in Formula 1: (Formula 1); By calculating the encoding vector of the real image and the encoding vector of the generated image The model encoding loss can be obtained, where This represents the mean square error.
[0079] Step 6042: Determine a second loss function based on the pixel values of the defect-free image and the second generated image; the second loss function is used to characterize the similarity between the second generated image and the defect-free image.
[0080] In some embodiments, the second loss function is the context loss. As shown in Formula 2: (Formula 2); in For defect-free images, To generate an image, The mean absolute error is denoted as . Context loss controls the fidelity of the reconstructed image.
[0081] Step 6043: Determine the third loss function based on the difference between the image features of the defect-free image and the image features of the second generated image.
[0082] In some embodiments, the third loss function is an adversarial loss. As shown in Formula 3: (Formula 3); in This represents the processing of defect-free images by discriminative encoder 3, and the context loss function. Calculate defect-free images and generating images The L2 loss is obtained, where This represents the mean square error.
[0083] Step 6044: Determine the target loss function based on the first loss function, the second loss function, and the third loss function.
[0084] In some embodiments, the target loss function can be calculated by assigning different weight values to the first loss function, the second loss function, and the third loss function. The target loss function is obtained by weighted summation of the three loss functions mentioned above, as shown in Formula 4: (Formula 4); Step 605: Adjust the parameter values of the generator network and the discriminator network according to the target loss function to obtain the adjusted generator network and the adjusted discriminator network.
[0085] In this way, the parameter values of the generator network and the discriminator network in the generative adversarial network are adjusted based on the obtained target loss function, so that the generator can generate more realistic generated images and the discriminator can have more accurate discrimination ability.
[0086] The difference between the feature vectors of a defect-free image The determination is shown in Formula 5: (Formula 5); in This represents the encoding of a defect-free image. This indicates the encoding of the generated image by the discriminant encoder 2. This represents the difference between the two encoded values (i.e., the third feature vector and the fourth feature vector).
[0087] Here, by calculating the difference value for each defect-free image pair, the largest difference value is selected as the first threshold. Thus, after the generative adversarial network is trained, it is possible to determine whether the image to be detected is an abnormal image based on the first threshold.
[0088] Step 606: Continue to adjust the parameter values of the generator network and the discriminator network based on the next defect-free image until the probability output by the current discriminator network is greater than or equal to the third threshold. Then, use the currently trained generator adversarial network as the trained generator adversarial network.
[0089] The following describes an exemplary application of the embodiments of this application in a real-world application scenario.
[0090] Figure 7 The overall flow of the defect detection method provided in the embodiments of this application is as follows. Figure 7 As shown, the method includes the following steps 701 to 707: Step 701: Manually select 200 defect-free sample images that meet the requirements for use as the dataset for model training.
[0091] Step 702: Configure the model training hyperparameters and train the GANormaly model until it converges.
[0092] Step 703: Detect the image to be detected, calculate the anomaly score (i.e., the difference in feature vectors in the latent space) of the image to be detected and generate the image.
[0093] Step 704: Filter out abnormal images by abnormal scores.
[0094] Step 705: Perform a second judgment on the abnormal image. Obtain a mask result image by generating a differential heat map between the image and the image to be detected. Determine whether the pixel count of the mask result image is less than the threshold pixel count. If yes, proceed to step 706; otherwise, proceed to step 707.
[0095] Step 706: Determine that the image to be detected is a defect-free image.
[0096] Step 707: Determine that the image to be detected is a defective image.
[0097] The embodiments of this application are based on an unsupervised model, GANormaly, to detect defects in rubber sleeves. Training can be completed by modeling positive samples only. It can detect various obvious abnormal defects, solve the problem of excessive reliance on negative samples in actual detection, reduce manual annotation costs, and improve production line deployment efficiency.
[0098] In this embodiment, GANormly's unsupervised learning-based characteristics reduce the reliance on negative samples, making it easier to apply to real-world industrial production scenarios, reducing deployment costs, and improving detection applicability. This increases deployment efficiency and saves costs.
[0099] Similar detection methods can be used for industrial-type images with little variation in pattern and scale, such as those of rubber sleeves. Only a few parameters, such as the threshold, need to be adjusted to train the detection of anomalies in similar workpieces.
[0100] It should be understood that, although Figure 2 , 4 The steps in flowcharts 6 and 7 are shown sequentially as indicated by the arrows; however, these steps are not necessarily executed in the exact order indicated by the arrows. Unless otherwise specified herein, there is no strict order requirement for the execution of these steps, and they can be performed in other orders. Furthermore, Figure 2 , 4 At least some of the steps in 6 and 7 may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but may be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but may be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0101] Based on the foregoing embodiments, this application provides a defect detection device, which includes various modules and units included in each module, and can be implemented by a processor; of course, it can also be implemented by specific logic circuits; in the implementation process, the processor can be a central processing unit (CPU), microprocessor (MPU), digital signal processor (DSP) or field programmable gate array (FPGA), etc.
[0102] Figure 8 This is a schematic diagram of the defect detection device provided in the embodiments of this application, as shown below. Figure 8 As shown, the device 800 includes a dimensionality reduction processing module 801, a high-dimensional mapping module 802, and a determination module 803, wherein: The dimensionality reduction module is used to perform dimensionality reduction processing on the image to be detected in the trained generative adversarial network to obtain the first feature vector in the lower dimension; the image to be detected includes defect-free images and defective images; the trained generative adversarial network is obtained by training the generative adversarial network to be trained based on multiple defect-free images; The high-dimensional mapping module is used to perform high-dimensional mapping processing on the first feature vector in the low dimension to obtain a first generated image with a dimension higher than the image to be detected. The dimensionality reduction processing module is further used to perform dimensionality reduction processing on the first generated image to obtain a second feature vector in a lower dimension; the dimension of the second feature vector is the same as the dimension of the first feature vector. The determination module is used to determine whether the image to be detected is a defective image based on the first feature vector of the image to be detected and the second feature vector of the first generated image, as well as the pixel values of the image to be detected and the pixel values of the first generated image.
[0103] In some embodiments, the determining module is further configured to: determine that the image to be detected is an abnormal image if the difference between the first feature vector and the second feature vector is greater than a first threshold; obtain a differential heatmap corresponding to the image to be detected that is determined to be an abnormal image based on the difference between the pixel value of the image to be detected that is determined to be an abnormal image and the pixel value of the corresponding first generated image; and determine whether the image to be detected is a defective image based on the number of pixels in the defective region in the differential heatmap.
[0104] In some embodiments, the apparatus further includes an extraction module, which is used to extract the differential heatmap to obtain a defect region in the differential heatmap; the determination module is further used to determine the image to be detected as a defect image if the number of pixels in the defect region is greater than a second threshold.
[0105] In some embodiments, the apparatus further includes an adjustment module; a dimensionality reduction module, further configured to input the defect-free image into the generator network to be trained for dimensionality reduction processing to obtain a third feature vector in a low dimension; a high-dimensional mapping module, further configured to input the third feature vector into the generator of the generator network to be trained for high-dimensional mapping processing to obtain a second generated image with a dimension higher than that of the defect-free image; the dimensionality reduction module, further configured to input the defect-free image and the second generated image into the discriminator network to be trained for authenticity discrimination to obtain a similarity probability that the second generated image is a defect-free image; a determination module, further configured to determine a target loss function if the similarity probability is less than a third threshold; the adjustment module, configured to adjust the parameter values of the generator network and the discriminator network according to the target loss function to obtain the adjusted generator network and the adjusted discriminator network; continue to adjust the parameter values of the generator network and the discriminator network according to the next defect-free image until the probability output by the current discriminator network is greater than or equal to the third threshold, and use the currently trained generative adversarial network as the trained generative adversarial network.
[0106] In some embodiments, the determining module is further configured to: if the similarity probability is less than a third threshold, determine a first loss function based on the third feature vector of the defect-free image and the fourth feature vector corresponding to the second generated image; the fourth feature vector is obtained by inputting the second generated image into the discriminative network to be trained for dimensionality reduction, and the dimension of the fourth feature vector is the same as the dimension of the third feature vector; the first loss function is used to characterize the feature differences between the second generated image and the defect-free image in low dimension; determine a second loss function based on the pixel values of the defect-free image and the second generated image; the second loss function is used to characterize the similarity between the second generated image and the defect-free image; determine a third loss function based on the differences between the image features of the defect-free image and the image features of the second generated image; and determine the target loss function based on the first loss function, the second loss function, and the third loss function.
[0107] In some embodiments, the apparatus further includes an acquisition module; the acquisition module is configured to acquire detection results of multiple images to be detected obtained within a preset time period; the determination module is further configured to determine the accuracy of each detection result; the adjustment module is further configured to adjust the first threshold if the number of accuracy rates less than a preset standard exceeds a fourth threshold.
[0108] In some embodiments, the apparatus further includes a preprocessing module for preprocessing the image to be detected to obtain an image to be detected with a standard size.
[0109] In the embodiments of this application, on the one hand, when training the defect detection model, it is trained only on defect-free images and does not rely on defect samples, thereby reducing the cost of manually collecting various types of defect samples and being applicable to more types of defect detection; on the other hand, defect detection of the image to be detected is performed from both the feature vector and pixel value of the image, which can improve the detection accuracy.
[0110] The descriptions of the above device embodiments are similar to those of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0111] It should be noted that, in the embodiments of this application... Figure 8 The module division of the defect detection device shown is illustrative and represents only one logical functional division; in actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, exist as separate physical units, or be integrated into one unit by two or more units. The integrated units can be implemented in hardware, as software functional units, or a combination of both.
[0112] It should be noted that, in the embodiments of this application, if the above-described methods are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.
[0113] This application provides a computer device, which may be a server, and its internal structure diagram may be as follows: Figure 9As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements an interactive mode switching method.
[0114] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the method provided in the above embodiments.
[0115] This application provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps in the method provided in the above-described method embodiments.
[0116] Those skilled in the art will understand that Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0117] In one embodiment, the sampling device provided in this application can be implemented as a computer program, and the computer program can be implemented as follows: Figure 9 It runs on the computer device shown. The computer device's memory can store the various program modules that make up the sampling device, for example, Figure 9 The diagram shows a dimensionality reduction module, a high-dimensional mapping module, and a determination module. The computer program, comprised of these modules, causes the processor to execute the steps of the sampling methods described in the various embodiments of this application.
[0118] In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to perform the following steps: in a trained generative adversarial network (GAN), performing dimensionality reduction processing on an image to be detected to obtain a first feature vector in a lower dimension; the image to be detected includes a defect-free image and a defective image; the trained GAN is obtained by training the GAN on multiple defect-free images; performing high-dimensional mapping processing on the first feature vector in the lower dimension to obtain a first generated image with a dimension higher than that of the image to be detected; performing dimensionality reduction processing on the first generated image to obtain a second feature vector in a lower dimension; the dimension of the second feature vector is the same as that of the first feature vector; determining whether the image to be detected is a defective image based on the first feature vector of the image to be detected, the second feature vector of the first generated image, and the pixel values of the image to be detected and the pixel values of the first generated image.
[0119] In one embodiment, when the processor executes the computer program, it further implements the following steps: if the difference between the first feature vector and the second feature vector is greater than a first threshold, the image to be detected is determined to be an abnormal image; based on the difference between the pixel value of the image to be detected determined to be an abnormal image and the pixel value of the corresponding first generated image, a differential heatmap corresponding to the image to be detected determined to be an abnormal image is obtained; based on the number of pixels in the defect area in the differential heatmap, it is determined whether the image to be detected is a defective image.
[0120] In one embodiment, when the processor executes the computer program, it further performs the following steps: extracting the differential heatmap to obtain the defect region in the differential heatmap; if the number of pixels in the defect region is greater than a second threshold, the image to be detected is determined to be a defect image.
[0121] In one embodiment, when the processor executes the computer program, it further implements the following steps: inputting a defect-free image into a generator network to be trained for dimensionality reduction processing to obtain a third feature vector in a low dimension; inputting the third feature vector into the generator of the generator network to be trained for high-dimensional mapping processing to obtain a second generated image with a dimension higher than that of the defect-free image; inputting the defect-free image and the second generated image into a discriminator network to be trained for authenticity discrimination to obtain the similarity probability that the second generated image is a defect-free image; if the similarity probability is less than a third threshold, determining a target loss function; adjusting the parameter values of the generator network and the discriminator network according to the target loss function to obtain the adjusted generator network and the adjusted discriminator network; continuing to adjust the parameter values of the generator network and the discriminator network according to the next defect-free image until the probability output by the current discriminator network is greater than or equal to the third threshold, and using the currently trained generative adversarial network as the trained generative adversarial network.
[0122] In one embodiment, when the processor executes the computer program, it further performs the following steps: if the similarity probability is less than the third threshold, a first loss function is determined based on the third feature vector of the defect-free image and the fourth feature vector corresponding to the second generated image; the fourth feature vector is obtained by inputting the second generated image into the discriminative network to be trained for dimensionality reduction processing, and the dimension of the fourth feature vector is the same as the dimension of the third feature vector; the first loss function is used to characterize the feature difference between the second generated image and the defect-free image in low dimension; a second loss function is determined based on the pixel values of the defect-free image and the second generated image; the second loss function is used to characterize the similarity between the second generated image and the defect-free image; a third loss function is determined based on the difference between the image features of the defect-free image and the image features of the second generated image; and a target loss function is determined based on the first loss function, the second loss function, and the third loss function.
[0123] In one embodiment, when the processor executes the computer program, it further performs the following steps: acquiring detection results of multiple images to be detected obtained within a preset time period; determining the accuracy of each detection result; and adjusting the first threshold if the number of accuracy rates less than a preset standard exceeds a fourth threshold.
[0124] In one embodiment, the processor, when executing the computer program, further performs the following steps: preprocessing the image to be detected to obtain an image to be detected with a standard size.
[0125] In the embodiments of this application, on the one hand, when training the defect detection model, it is trained only on defect-free images and does not rely on defect samples, thereby reducing the cost of manually collecting various types of defect samples and being applicable to more types of defect detection; on the other hand, defect detection of the image to be detected is performed from both the feature vector and pixel value of the image, which can improve the detection accuracy.
[0126] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon. When executed by a processor, the computer program performs the following steps: in a trained generative adversarial network (GAN), dimensionality reduction is performed on an image to be detected to obtain a first feature vector in a lower dimension; the image to be detected includes a defect-free image and a defective image; the trained GAN is obtained by training the GAN on multiple defect-free images; high-dimensional mapping is performed on the first feature vector in the lower dimension to obtain a first generated image with a dimension higher than that of the image to be detected; dimensionality reduction is performed on the first generated image to obtain a second feature vector in the lower dimension; the dimension of the second feature vector is the same as that of the first feature vector; and based on the first feature vector of the image to be detected, the second feature vector of the first generated image, and the pixel values of the image to be detected and the pixel values of the first generated image, it is determined whether the image to be detected is a defective image.
[0127] In one embodiment, when the computer program is executed by the processor, it further implements the following steps: if the difference between the first feature vector and the second feature vector is greater than a first threshold, the image to be detected is determined to be an abnormal image; based on the difference between the pixel value of the image to be detected determined to be an abnormal image and the pixel value of the corresponding first generated image, a differential heatmap corresponding to the image to be detected determined to be an abnormal image is obtained; based on the number of pixels in the defect area in the differential heatmap, it is determined whether the image to be detected is a defective image.
[0128] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: extracting the differential heatmap to obtain the defect region in the differential heatmap; if the number of pixels in the defect region is greater than a second threshold, the image to be detected is determined to be a defect image.
[0129] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: inputting a defect-free image into a generator network to be trained for dimensionality reduction processing to obtain a third feature vector in a low dimension; inputting the third feature vector into the generator of the generator network to be trained for high-dimensional mapping processing to obtain a second generated image with a dimension higher than that of the defect-free image; inputting the defect-free image and the second generated image into a discriminator network to be trained for authenticity discrimination to obtain the similarity probability that the second generated image is a defect-free image; if the similarity probability is less than a third threshold, determining a target loss function; adjusting the parameter values of the generator network and the discriminator network according to the target loss function to obtain the adjusted generator network and the adjusted discriminator network; continuing to adjust the parameter values of the generator network and the discriminator network according to the next defect-free image until the probability output by the current discriminator network is greater than or equal to the third threshold, and using the currently trained generator adversarial network as the trained generator adversarial network.
[0130] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: if the similarity probability is less than the third threshold, a first loss function is determined based on the third feature vector of the defect-free image and the fourth feature vector corresponding to the second generated image; the fourth feature vector is obtained by inputting the second generated image into the discriminative network to be trained for dimensionality reduction processing, and the dimension of the fourth feature vector is the same as the dimension of the third feature vector; the first loss function is used to characterize the feature difference between the second generated image and the defect-free image in low dimension; a second loss function is determined based on the pixel values of the defect-free image and the second generated image; the second loss function is used to characterize the similarity between the second generated image and the defect-free image; a third loss function is determined based on the difference between the image features of the defect-free image and the image features of the second generated image; and a target loss function is determined based on the first loss function, the second loss function, and the third loss function.
[0131] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: acquiring detection results of multiple images to be detected obtained within a preset time period; determining the accuracy of each detection result; and adjusting the first threshold if the number of accuracy rates less than a preset standard exceeds a fourth threshold.
[0132] In one embodiment, when the computer program is executed by the processor, it further performs the following steps: preprocessing the image to be detected to obtain an image to be detected with a standard size.
[0133] In the embodiments of this application, on the one hand, when training the defect detection model, it is trained only on defect-free images and does not rely on defect samples, thereby reducing the cost of manually collecting various types of defect samples and being applicable to more types of defect detection; on the other hand, defect detection of the image to be detected is performed from both the feature vector and pixel value of the image, which can improve the detection accuracy.
[0134] It should be noted that the descriptions of the storage medium and device embodiments above are similar to the descriptions of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the storage medium, storage medium, and device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0135] It should be understood that the phrases "one embodiment," "an embodiment," or "some embodiments" mentioned throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment," "in one embodiment," or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. The descriptions of the various embodiments above tend to emphasize the differences between the various embodiments; their similarities or commonalities can be referred to mutually, and for the sake of brevity, they will not be repeated here.
[0136] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three kinds of relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist simultaneously, and object B exists alone.
[0137] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0138] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or modules can be electrical, mechanical, or other forms.
[0139] The modules described above as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules. They may be located in one place or distributed across multiple network units. Some or all of the modules may be selected to achieve the purpose of this embodiment according to actual needs.
[0140] In addition, each functional module in the various embodiments of this application can be integrated into one processing unit, or each module can be a separate unit, or two or more modules can be integrated into one unit; the integrated modules can be implemented in hardware or in the form of hardware plus software functional units.
[0141] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.
[0142] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0143] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0144] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0145] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.
[0146] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A defect detection method, characterized in that, The method includes: In the trained generative adversarial network, the image to be detected is subjected to dimensionality reduction processing to obtain the first feature vector in low dimension; the image to be detected includes defect-free images and defective images; the trained generative adversarial network is obtained by training the generative adversarial network to be trained based on multiple defect-free images; The first feature vector in the low dimension is subjected to high-dimensional mapping processing to obtain a first generated image with a dimension higher than the image to be detected; The first generated image is subjected to dimensionality reduction processing to obtain a second feature vector in a lower dimension; the dimension of the second feature vector is the same as the dimension of the first feature vector. Based on the first feature vector of the image to be detected and the second feature vector of the first generated image, as well as the pixel values of the image to be detected and the pixel values of the first generated image, it is determined whether the image to be detected is a defective image; The step of determining whether the image to be detected is a defective image based on the first feature vector of the image to be detected, the second feature vector of the first generated image, and the pixel values of the image to be detected and the first generated image includes: If the difference between the first feature vector and the second feature vector is greater than the first threshold, the image to be detected is determined to be an abnormal image; Based on the difference between the pixel values of the image to be detected, which is determined to be an abnormal image, and the corresponding pixel values of the first generated image, a differential heatmap corresponding to the image to be detected, which is determined to be an abnormal image, is obtained. Based on the number of pixels in the defect region of the differential heatmap, it is determined whether the image to be detected is a defective image.
2. The method according to claim 1, characterized in that, The step of determining whether the image to be detected is a defective image based on the number of pixels in the defect region of the differential heatmap includes: The differential heat map is extracted to obtain the defect region in the differential heat map; If the number of pixels in the defective region is greater than the second threshold, the image to be detected is determined to be a defective image.
3. The method according to claim 1, characterized in that, Generative adversarial networks (GANs) consist of a generator network and a discriminator network, and the GAN is obtained in advance through the following method: The defect-free image is input into the generative network to be trained for dimensionality reduction to obtain the third feature vector in low dimension. The third feature vector is input into the generator of the generator network to be trained for high-dimensional mapping processing to obtain a second generated image with a dimension higher than that of the defect-free image; The defect-free image and the second generated image are input into the discrimination network to be trained for authenticity determination, and the similarity probability of the second generated image being the defect-free image is obtained. If the similarity probability is less than the third threshold, determine the target loss function; Based on the target loss function, the parameter values of the generator network and the discriminator network are adjusted to obtain the adjusted generator network and the adjusted discriminator network; Continue adjusting the parameter values of the generator network and the discriminator network based on the next defect-free image until the probability output by the current discriminator network is greater than or equal to the third threshold. Then, use the currently trained generator adversarial network as the trained generator adversarial network.
4. The method according to claim 3, characterized in that, If the similarity probability is less than the third threshold, the target loss function is determined, including: If the similarity probability is less than the third threshold, a first loss function is determined based on the third feature vector of the defect-free image and the fourth feature vector corresponding to the second generated image. The fourth feature vector is obtained by inputting the second generated image into the discriminative network to be trained for dimensionality reduction. The dimension of the fourth feature vector is the same as the dimension of the third feature vector. The first loss function is used to characterize the feature differences between the second generated image and the defect-free image in low dimension. A second loss function is determined based on the pixel values of the defect-free image and the pixel values of the second generated image; the second loss function is used to characterize the degree of similarity between the second generated image and the defect-free image. A third loss function is determined based on the difference between the image features of the defect-free image and the image features of the second generated image; The target loss function is determined based on the first loss function, the second loss function, and the third loss function.
5. The method according to any one of claims 1 to 4, characterized in that, The method further includes: Obtain the detection results of multiple images to be detected within a preset time period; Determine the accuracy of each of the aforementioned test results; If the number of accuracy rates below the preset standard exceeds the fourth threshold, the first threshold is adjusted.
6. The method according to claim 1, characterized in that, Before performing dimensionality reduction processing on the image to be detected, the method further includes: The image to be detected is preprocessed to obtain an image to be detected with a standard size.
7. A defect detection device, characterized in that, include: The dimensionality reduction module is used to perform dimensionality reduction processing on the image to be detected in the trained generative adversarial network to obtain the first feature vector in the lower dimension. The images to be detected include defect-free images and defective images; the trained generative adversarial network is obtained by training a generative adversarial network to be trained based on multiple defect-free images; The high-dimensional mapping module is used to perform high-dimensional mapping processing on the first feature vector in the low dimension to obtain a first generated image with a dimension higher than the image to be detected; The dimensionality reduction processing module is further configured to perform dimensionality reduction processing on the first generated image to obtain a second feature vector in a lower dimension; the dimension of the second feature vector is the same as the dimension of the first feature vector. The determination module is used to determine whether the image to be detected is a defective image based on the first feature vector of the image to be detected and the second feature vector of the first generated image, as well as the pixel values of the image to be detected and the pixel values of the first generated image. The determining module is specifically used to: determine the image to be detected as an abnormal image if the difference between the first feature vector and the second feature vector is greater than a first threshold; obtain a differential heatmap corresponding to the image to be detected as an abnormal image based on the difference between the pixel value of the image to be detected as an abnormal image and the pixel value of the corresponding first generated image; and determine whether the image to be detected is a defective image based on the number of pixels in the defective region in the differential heatmap.
8. A computer device comprising a memory and a processor, the memory storing a computer program executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Rubber glove defect detection method based on generative adversarial network
CN112837295A
Image processing method and device, equipment and storage medium
CN113689383A