Defect detection method and device and machine readable storage medium
By segmenting images and training with defect-free samples, and utilizing image reconstruction and mosaic generation models, the problem of poor defect detection performance in high-quality industrial products is solved, achieving high-precision identification and flexible detection of minute defects.
Patent Information
- Application Number
- CN202510889882.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-10-28
AI Technical Summary
Existing industrial vision inspection methods based on supervised deep learning perform poorly in defect detection of high-quality industrial products, especially when defect samples are scarce and imbalanced. The model tends to overfit to normal samples, leading to a decline in detection performance.
The method employs image block processing and defect-free sample training. By segmenting the original image into multiple blocks and shuffling their order, an image reconstruction model and a jigsaw puzzle generation model are used, combined with an encoder, bottleneck layer, and decoder architecture, to learn the feature distribution of defect-free images. The presence of defects is determined by the difference value, thus avoiding reliance on defect annotation.
It improves the accuracy and flexibility of defect detection, enabling the effective identification of minute defects in high-quality industrial products even in the absence of defect data, and enhances the sensitivity and detection accuracy of local defects.
Smart Images

Figure CN120852298A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of defect detection technology, and more specifically to a method, apparatus and machine-readable storage medium for defect detection. Background Technology
[0002] Existing widely used supervised deep learning-based industrial vision inspection methods perform excellently when data is plentiful, but their main bottleneck is the need for large amounts of labeled data. However, in industrial applications, data labeling often requires professional personnel, which is not only time-consuming and labor-intensive but also prone to errors. Furthermore, manual labeling is difficult to implement in cases requiring the identification of minute or extremely rare defects. In addition, industrial products are typically high-quality, resulting in a very small number of defect samples, with a severe imbalance in the number of different defect types. Under such conditions, supervised learning models are prone to overfitting to normal samples while neglecting defect samples, leading to a decline in detection performance. Therefore, existing defect detection methods suffer from poor performance in detecting defects in high-quality industrial products. Summary of the Invention
[0003] The purpose of this application is to provide a method, apparatus, and machine-readable storage medium for defect detection, in order to solve the problem that existing defect detection methods have poor defect detection effects on high-quality industrial products.
[0004] To achieve the above objectives, a first aspect of this application provides a method for defect detection, comprising: Acquire the original image containing the object being measured; The original image is divided into multiple original image blocks, and the order of these blocks is shuffled. The shuffled original image blocks are input into a pre-built image reconstruction model to obtain reconstructed image blocks. The training data of the image reconstruction model includes sample images of defect-free objects of the same type as the object being tested. Each reconstructed image block is input into a pre-built jigsaw puzzle generation model to restore the original arrangement order of the image blocks and obtain a reconstructed image corresponding to the original image. Determine the difference between the original image and the reconstructed image; The difference value is used to determine whether there are defects in the object being tested in the original image.
[0005] In this embodiment, the image reconstruction model includes an encoder, a bottleneck layer, and a decoder. The scrambled original image blocks are input into the pre-constructed image reconstruction model to obtain reconstructed image blocks. The process includes: for each original image block, the encoder converts the original image block into a corresponding latent feature vector, the latent feature vector containing the abstract features of the original image block; the bottleneck layer processes the latent feature vector to obtain the corresponding feature distribution; and the decoder reconstructs the feature distribution to obtain the reconstructed image block.
[0006] In this embodiment of the application, the latent feature vector is processed by the bottleneck layer to obtain the corresponding feature distribution, including: mapping the latent feature vector to the latent feature space, which is composed of multiple different Gaussian distributions, each representing the normal data features of different parts of the measured object; determining the target Gaussian distribution corresponding to the latent feature vector from the multiple Gaussian distributions in the latent feature space; and assigning the feature vector to the target Gaussian distribution to obtain the corresponding feature distribution.
[0007] In this embodiment, the loss function of the jigsaw puzzle generation model includes an HSIC regularization term, which constrains the independence between each reconstructed image patch through HSIC information.
[0008] In this embodiment of the application, determining the difference value between the original image and the reconstructed image includes: determining the difference value between each reconstructed image block in the reconstructed image and the corresponding original image block in the original image, so as to obtain multiple difference values.
[0009] In this embodiment of the application, determining whether the object under test in the original image has a defect based on the difference value includes: if there is at least a preset number of difference values that are greater than a preset difference threshold among multiple difference values, it is determined that the object under test in the original image has a defect; if multiple difference values are all less than or equal to the preset difference threshold, it is determined that the object under test in the original image does not have a defect.
[0010] In this embodiment of the application, the method further includes: when there is a defect in the object under test in the original image, performing differential processing on the original image and the reconstructed image to obtain a corresponding residual map; and determining the location of the detected defect in the original image based on the residual map.
[0011] In this embodiment, the steps for constructing the image reconstruction model include: constructing an initial image reconstruction model based on a deep convolutional neural network model. The framework of the initial image reconstruction model includes an encoder, a bottleneck layer, and a decoder. The encoder is a deep convolutional neural network with fully connected layers removed, and the decoder is an inverse deep convolutional neural network. A sample image dataset is obtained, which includes sample images of defect-free objects of the same type as the object being tested. For each sample image in the sample image dataset, the sample image is divided into multiple sample image blocks according to a preset size. The multiple sample image blocks are used as input data to train the initial image reconstruction model until all sample images in the sample image dataset have been traversed to obtain the constructed image reconstruction model.
[0012] A second aspect of this application provides an apparatus for defect detection, comprising: a memory configured to store instructions; a processor configured to retrieve instructions from the memory and, when executing the instructions, to implement the aforementioned method for defect detection.
[0013] A third aspect of this application provides a machine-readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the above-described method for defect detection.
[0014] The aforementioned technical solution involves acquiring an original image containing the object under test, dividing the original image into multiple original image blocks, shuffling the order of these blocks, and then inputting the shuffled blocks into a pre-constructed image reconstruction model to obtain reconstructed image blocks. The training data for the image reconstruction model includes sample images of defect-free objects of the same type as the object under test. Each reconstructed image block is then input into a pre-constructed jigsaw puzzle generation model to restore the original order of the image blocks, resulting in a reconstructed image corresponding to the original image. The difference between the original image and the reconstructed image is further determined, and finally, the presence of defects in the object under test in the original image is determined based on the difference. This application, by shuffling the image blocks before inputting them into the image reconstruction model, can better capture the local features of the image. Using defect-free sample images to train the reconstruction model results in better reconstruction performance for defect-free images, enabling defect detection of high-quality industrial products with limited defect samples and improving the accuracy of defect detection.
[0015] Other features and advantages of the embodiments of this application will be described in detail in the following detailed description section. Attached Figure Description
[0016] The accompanying drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the following detailed description to explain the embodiments of this application, but do not constitute a limitation on the embodiments of this application. In the drawings: Figure 1 A flowchart illustrating a method for defect detection provided in an embodiment of this application; Figure 2 This is a schematic diagram illustrating a defect detection process based on an image reconstruction model, provided as a specific embodiment of this application. Figure 3 This is a structural block diagram of a device for defect detection provided in an embodiment of this application. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for illustration and explanation of the embodiments of this application and are not intended to limit the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0018] It should be noted that if the embodiments of this application involve directional indicators (such as up, down, left, right, front, back, etc.), the directional indicators are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indicators will also change accordingly.
[0019] Furthermore, if the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the technical solutions of various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0020] Figure 1 This is a flowchart illustrating a method for defect detection provided in an embodiment of this application. Figure 1 As shown in the figure, this application provides a method for defect detection. Taking the application of this method to a processor as an example, the method may include the following steps.
[0021] Step S101: Obtain the original image containing the object being measured.
[0022] It's understandable that the object being tested can encompass various objects across multiple fields such as industrial manufacturing, materials, food, and biomedicine, specifically referring to a particular object requiring defect detection. To detect whether the object under test has defects, it's first necessary to acquire original images of the object. This can be done by using image acquisition equipment to photograph the object, obtaining multiple original images of the object from different angles and locations. Each original image contains a partial view of the object. Then, defect detection can be performed on each image to determine whether defects exist and their locations.
[0023] Step S102: Divide the original image into multiple original image blocks and shuffle the order of each original image block.
[0024] Understandably, to improve the accuracy and efficiency of local defect detection, this embodiment of the application can first adjust the original image to a set size, then divide the original image of the set size into multiple small blocks according to a preset size, obtaining multiple original image blocks, and then randomly shuffle the arrangement of these image blocks. In this way, the original spatial structure information of the image can be broken, so that when the subsequent model processes the image blocks, it needs to learn the features of the image blocks themselves, such as texture, color, shape, and other local features, rather than relying on their position information in the original image. This improves the model's ability to learn the essential features of the image, laying the foundation for accurate defect detection. This method enhances the model's sensitivity to local defects and is more accurate in locating defect regions compared to traditional global defect detection methods.
[0025] Step S103: Input the shuffled original image blocks into the pre-constructed image reconstruction model to obtain reconstructed image blocks. The training data of the image reconstruction model includes sample images of defect-free objects of the same type as the object being tested.
[0026] It is understandable that traditional defect detection methods often require a large amount of defect-annotated data, leading to high training costs and difficulty in widespread adoption. To reduce detection costs while meeting the defect detection requirements of high-quality objects and ensuring the accuracy of detection results, this application employs a large number of sample images of defect-free objects of the same type as the object being detected during the training phase of the image reconstruction model. This results in the image reconstruction model performing well on defect-free images but poorly on defective images. Specifically, shuffled original image blocks are input into the image reconstruction model, allowing it to reconstruct each original image block in parallel, resulting in multiple reconstructed image blocks. Thus, the image reconstruction model is trained using only defect-free normal samples, learning the features of normal images in an unsupervised environment. Unlike traditional defect detection methods that require manually annotated defect samples, the image reconstruction model in this application avoids dependence on defect annotation, exhibiting greater flexibility and adaptability. This allows the model to be trained even in the absence of defect data and to detect defects by learning the distribution characteristics of normal samples.
[0027] Step S104: Input each reconstructed image block into the pre-built jigsaw puzzle generation model to restore the original arrangement order of the image blocks and obtain the reconstructed image corresponding to the original image.
[0028] It is understandable that the role of the jigsaw puzzle generation model is to analyze the relationship between the reconstructed image blocks. By learning the semantic associations and edge matching information between the image blocks, the scrambled reconstructed image blocks are restored to their original order, thereby obtaining a reconstructed image corresponding to the original image.
[0029] Step S105: Determine the difference values between the original image and the reconstructed image.
[0030] It's understandable that the difference value quantifies the degree of difference between the original image and the reconstructed image. Since image reconstruction models perform poorly on defective images but well on defect-free images, the more defects in an image, the greater the difference between the reconstructed and original images, and thus the larger the difference value; conversely, the fewer defects, the smaller the difference value. In one example, the difference value between the original and reconstructed images can be calculated using the mean squared error. In another example, the difference value can be calculated using the structural similarity index.
[0031] Step S106: Determine whether there are defects in the object being tested in the original image based on the difference value.
[0032] It is understandable that the difference value can reflect the defects of the object under test in the original image. Therefore, the presence of defects in the object under test can be determined based on the difference value. In one example, a difference threshold can be pre-defined based on experimental data. This difference threshold is a global threshold. The calculated difference value is compared with this difference threshold. If the difference value is greater than the difference threshold, it indicates that the difference between the original image and the reconstructed image is large and exceeds the normal fluctuation range, thus indicating that the object under test has defects. If the difference value is less than or equal to the difference threshold, it is considered that the difference between the original image and the reconstructed image is within an acceptable range, and the object under test has no defects.
[0033] Therefore, compared to traditional global defect detection methods, this application, by performing local block processing on the image, can more accurately locate and detect local defects. This results in greater precision in practical applications, especially in industrial inspection, where it can accurately identify minute defects or localized problems in the image, improving the accuracy and effectiveness of defect detection. Furthermore, the defect detection method provided in this application is applicable to defect detection of both ordinary and high-quality industrial products, offering higher detection accuracy and a wider range of applications than existing technologies.
[0034] The aforementioned technical solution involves acquiring an original image containing the object under test, dividing the original image into multiple original image blocks, shuffling the order of these blocks, and then inputting the shuffled blocks into a pre-constructed image reconstruction model to obtain reconstructed image blocks. The training data for the image reconstruction model includes sample images of defect-free objects of the same type as the object under test. Each reconstructed image block is then input into a pre-constructed jigsaw puzzle generation model to restore the original order of the image blocks, resulting in a reconstructed image corresponding to the original image. The difference between the original image and the reconstructed image is further determined, and finally, the presence of defects in the object under test in the original image is determined based on the difference. This application, by shuffling the image blocks before inputting them into the image reconstruction model, can better capture the local features of the image. Using defect-free sample images to train the reconstruction model results in better reconstruction performance for defect-free images, enabling defect detection of high-quality industrial products with limited defect samples and improving the accuracy of defect detection.
[0035] In this embodiment, the image reconstruction model includes an encoder, a bottleneck layer, and a decoder. The scrambled original image blocks are input into the pre-constructed image reconstruction model to obtain reconstructed image blocks. This can include: for each original image block, the encoder converts the original image block into a corresponding latent feature vector, the latent feature vector containing the abstract features of the original image block; the bottleneck layer processes the latent feature vector to obtain the corresponding feature distribution; and the decoder reconstructs the feature distribution to obtain the reconstructed image block.
[0036] It is understandable that the image reconstruction model adopts an autoencoder architecture that includes an encoder, a bottleneck layer, and a decoder. This architecture can compress the input data into a low-dimensional representation, namely the latent feature vector, and then reconstruct the original data from this low-dimensional representation.
[0037] Specifically, the encoder can extract abstract features, forcing the model to learn the essential features of image patches, such as normal texture patterns, rather than surface details, thus laying the foundation for subsequent defect detection.
[0038] The bottleneck layer transforms latent feature vectors into two parameters: mean and variance, thus defining a probability distribution, typically a Gaussian distribution, i.e., a feature distribution. For example, a 4×4×256 latent feature vector might be mapped to two 4×4×128 tensors, representing the mean and log-variance, respectively. During inference, feature vectors can be sampled from this feature distribution for decoding. By introducing randomness and regularization, the bottleneck layer prevents overfitting and enables the model to learn the distribution characteristics of the data, enhancing its generalization ability to different defect-free samples.
[0039] The decoder is used to reconstruct the feature distribution, generating a reconstructed image patch corresponding to the input image patch. The decoder and encoder have a symmetrical structure. The decoder can progressively restore the spatial dimensions of the original image patch from the feature vector sampled from the bottleneck layer. For example, through upsampling and convolution operations, a 4×4×128 feature vector is progressively expanded into a 32×32×3 reconstructed image patch. Based on the feature distribution learned from defect-free samples, the decoder can attempt to correct any features that do not conform to the distribution, including defective parts, thereby making the reconstructed image patch appear defect-free.
[0040] Thus, when the input original image patch contains defects, the features of these defective regions differ from the feature distribution of defect-free samples. The latent feature vector extracted by the encoder will contain these anomalous features, and when the bottleneck layer and decoder reconstruct it based on the defect-free distribution, they will attempt to correct these anomalous features to a normal pattern. This results in a significant difference between the reconstructed image patch and the original image patch in the defective region, and defect detection can be achieved by using this difference as a criterion.
[0041] In this embodiment of the application, the latent feature vector is processed by the bottleneck layer to obtain the corresponding feature distribution, which may include: mapping the latent feature vector to a latent feature space, the latent feature space being composed of multiple different Gaussian distributions, each representing the normal data features of different parts of the measured object; determining the target Gaussian distribution corresponding to the latent feature vector from the multiple Gaussian distributions in the latent feature space; and assigning the feature vector to the target Gaussian distribution to obtain the corresponding feature distribution.
[0042] It is understandable that the normal features of different parts of the object being tested have local specificity and need to be modeled with independent Gaussian distributions. By assigning the potential feature vectors to the corresponding Gaussian distributions, the normal feature range of each part can be described more accurately, thereby improving the sensitivity of defect detection.
[0043] Specifically, during the training phase of the image reconstruction model, the latent feature space can be divided into multiple Gaussian distributions based on the latent feature vectors of defect-free samples through Gaussian mixture model training. Each Gaussian distribution corresponds to a local normal feature pattern of the tested object; that is, different Gaussian distributions represent normal data features of different parts of the tested object. Further, during defect detection, the image reconstruction model internally maps the latent feature vectors output by the encoder to the latent feature space, determines the target Gaussian distribution corresponding to the latent feature vector from the multiple Gaussian distributions in the latent feature space, and assigns the feature vector to the target Gaussian distribution to obtain the corresponding feature distribution. In one example, the Euclidean distance between the latent feature vector and each Gaussian distribution can be determined, and the Gaussian distribution corresponding to the minimum Euclidean distance is determined as the target Gaussian distribution of the latent feature vector, which is then used as the feature distribution corresponding to the latent feature vector.
[0044] In this way, by dividing the potential feature space into multiple Gaussian distributions, a refined modeling of the normal features of the object under test is achieved, upgrading defect detection from traditional global anomaly judgment to location-specific anomaly identification, thereby improving the accuracy of detection results.
[0045] In this embodiment, the loss function of the jigsaw puzzle generation model may include an HSIC regularization term, which constrains the independence between each reconstructed image patch through HSIC information.
[0046] It is understood that HSIC is a non-parametric statistic based on the reproducing kernel Hilbert space, used to measure the independence of two random variables. If two variables are independent, their covariance in the feature space is zero. In the embodiments of this application, the loss function of the jigsaw puzzle generation model can be composed of permutation loss and HSIC regularization term. In the jigsaw puzzle generation model, the HSIC regularization term can constrain the independence between reconstructed image patches, forcing the jigsaw puzzle generation model to learn the true dependencies between image patches, such as spatial adjacency and semantic association, and avoid relying on spurious correlations. In this way, by stitching together semantic associations based on spatial independence constraints, the accuracy of detection results for complex image structures is improved.
[0047] In this embodiment of the application, determining the difference value between the original image and the reconstructed image may include: determining the difference value between each reconstructed image block in the reconstructed image and the corresponding original image block in the original image, so as to obtain multiple difference values.
[0048] It is understandable that traditional difference calculations, when only small local defects exist in an image, weaken the difference caused by these defects due to the overall difference, leading to the neglect of these small defects and the conclusion that the image is defect-free. To address this, and to reduce detection errors, this application determines the difference value between corresponding locations in the original and reconstructed image blocks, on a block-by-block basis, thus obtaining multiple difference values. Furthermore, these multiple difference values can be used to determine whether the object under test in the original image has a defect. In one example, a local preset difference threshold can be set for each image block, which can be calibrated based on experimental data. Then, each difference value is compared with the preset difference threshold. If any difference value is greater than the preset difference threshold, it is determined that the object under test in the image has a defect, and the defect location is the location of the image block where the difference value is greater than the preset difference threshold.
[0049] Thus, by calculating the difference between blocks, each corresponding image block of the original image and the reconstructed image is compared block by block to generate a difference value matrix, which can realize the spatial localization and severity quantification of defects and improve the accuracy of local defect detection.
[0050] In this embodiment of the application, determining whether the object under test in the original image has a defect based on the difference value may include: if there are at least a preset number of difference values that are greater than a preset difference threshold among multiple difference values, determining that the object under test in the original image has a defect; if multiple difference values are all less than or equal to the preset difference threshold, determining that the object under test in the original image does not have a defect.
[0051] It is understandable that, in order to reduce the impact of image reconstruction errors on defect detection results, when determining whether there are defects in the original image based on multiple local difference values, the test object in the original image can be determined to have defects only if at least a preset number of difference values are greater than a preset difference threshold; otherwise, the test object in the original image is determined to be defect-free, thereby improving the accuracy of the detection results.
[0052] In this embodiment of the application, the method may further include: when there is a defect in the object under test in the original image, performing differential processing on the original image and the reconstructed image to obtain a corresponding residual map; and determining the location of the detected defect in the original image based on the residual map.
[0053] Specifically, when determining that the object under test in the original image has a defect, the reconstructed image will differ from the original image because the model is reconstructed based on defect-free features. Therefore, this difference can be quantified by differential processing to generate a residual map, highlighting the defect area in the form of high pixel values, realizing the spatial localization of the defect, and determining the location of the defect detected in the original image.
[0054] In this embodiment, the steps for constructing the image reconstruction model may include: constructing an initial image reconstruction model based on a deep convolutional neural network model, wherein the framework of the initial image reconstruction model includes an encoder, a bottleneck layer, and a decoder, wherein the encoder is a deep convolutional neural network with fully connected layers removed, and the decoder is an inverse deep convolutional neural network; acquiring a sample image dataset, wherein the sample image dataset includes sample images of defect-free objects of the same type as the object being tested; for each sample image in the sample image dataset, dividing the sample image into multiple sample image blocks according to a preset size; using the multiple sample image blocks of the sample images as input data to train the initial image reconstruction model until all sample images in the sample image dataset have been traversed to obtain the constructed image reconstruction model.
[0055] It is understood that the training data for the image reconstruction model in this embodiment consists of normal object sample images, i.e., images of defect-free objects of the same type as the object to be detected. A sample image dataset is formed by collecting sample images of multiple defect-free objects, where multiple images of each defect-free object from different angles and different local areas are collected. To enhance the model's generalization ability—that is, to ensure the image reconstruction model can reconstruct high-resolution images of different defect-free objects—all sample images can be preprocessed uniformly, including normalization. Specifically, the pixel values of the images are mapped to the range [0, 1], which helps accelerate network convergence and improve training stability. Furthermore, according to the input requirements of the image reconstruction model, all sample images are adjusted to a fixed size. Finally, to increase the diversity of the training data, data augmentation can be performed on the images in the sample image dataset, such as random rotation, flipping, and cropping, to improve the model's robustness and prevent overfitting.
[0056] Further, the processed image is input into the initial image reconstruction model for training. During training, for each sample image, a grid size of n×n is first set according to the image dimensions to divide the image into several small blocks. For example, when n=3, the image will be divided into 9 small blocks. Each image block is fed into an autoencoder network in parallel for training to extract the latent features of the image block and complete the reconstruction of each image block. After traversing all sample images in the sample image dataset, the trained image reconstruction model is obtained.
[0057] In this way, training is done solely on normal samples, eliminating the need for manually labeled defective samples. This allows the image reconstruction model to automatically learn the features of normal samples in an unsupervised environment and detect defects through reconstruction errors, thus achieving a more flexible and efficient training method.
[0058] It is understandable that this technical solution not only performs excellently in industrial defect detection but also has broad application prospects. By adapting to different types of image data and changes in complex scenes, the proposed defect model can be extended to other fields, such as visual perception for autonomous driving, further promoting the application and development of unsupervised defect detection technology.
[0059] Figure 2 This is a schematic diagram illustrating a defect detection process based on an image reconstruction model, provided as a specific embodiment of this application. (As shown in the image...) Figure 2 As shown, the defect detection process for the image to be detected is as follows: First, the input image to be detected is divided into multiple image blocks for subsequent shuffling. Then, the segmented images are randomly shuffled to form a jigsaw puzzle image, thereby breaking the contextual information of the image and preventing the model from directly using the structural information of the original image, thus improving the resolution and clarity of the reconstructed image. Further, the shuffled image blocks are input into a context-free inference network for feature encoding to obtain the latent representation of the image; the context-free inference network is a network that does not rely on the global contextual order information of the image for feature extraction or inference. Further, the latent representation of each image block is mapped to a mixed distribution space, where multiple Gaussian distributions are used to represent possible normal data features. Further, based on the image features, the latent variables of different image blocks are assigned to their respective Gaussian distributions to capture diverse normal data features. Furthermore, a jigsaw puzzle generation network is used to reconstruct the order of image patches based on latent representations, recombine the patches, and generate a reconstructed image that conforms to the distribution of a normal image. In the jigsaw puzzle generation network, HSIC (Hilbert-Schmidt Independence Criterion) information is used to constrain the independence between image patches, enhancing sensitivity to defect features. Furthermore, the probability distribution of the generated image is used to represent the model's predictions for generating normal data. Finally, the generated image is compared with the real input image, and the difference between the two is calculated. Based on the similarity difference between the generated and input images, if the difference is large, the image is considered to potentially contain defects, thus achieving defect detection.
[0060] Thus, by dividing the image into multiple small patches and processing each patch in parallel, local anomaly features can be captured more effectively. This method can effectively locate defect regions in the image. This ability to detect local anomalies makes the model more accurate in practical applications, especially in industrial inspection, where it can promptly identify subtle defects. Furthermore, this approach relies solely on normal samples for training, eliminating the need for manually labeled defect samples. This allows the image reconstruction model to automatically learn the features of normal samples in an unsupervised environment and detect defects through reconstruction errors, thereby achieving a more flexible and efficient training method.
[0061] Figure 3 This is a structural block diagram of a device for defect detection provided in an embodiment of this application. Figure 3 As shown in the figure, this application provides an apparatus for defect detection, which may include: Memory 310 is configured to store instructions; The processor 320 is configured to retrieve instructions from the memory 310 and, when executing the instructions, to implement the method of the apparatus for defect detection described in the above embodiments.
[0062] This application also provides a machine-readable storage medium on which a program or instruction is stored. When the program or instruction is executed by a processor, it implements the defect detection method described in the above embodiments.
[0063] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0064] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0065] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0066] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0067] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0068] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0069] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0070] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0071] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for defect detection, characterized in that, include: Acquire the original image containing the object being measured; The original image is divided into multiple original image blocks, and the order of the original image blocks is shuffled. The shuffled original image blocks are input into a pre-constructed image reconstruction model to obtain reconstructed image blocks. The training data of the image reconstruction model includes sample images of defect-free objects of the same type as the object under test. Each of the reconstructed image blocks is input into a pre-built jigsaw puzzle generation model to restore the original arrangement order of the image blocks and obtain a reconstructed image corresponding to the original image; Determine the difference values between the original image and the reconstructed image; The presence of defects in the tested object in the original image is determined based on the difference value.
2. The method according to claim 1, characterized in that, The image reconstruction model includes an encoder, a bottleneck layer, and a decoder. The step of inputting the scrambled original image blocks into the pre-constructed image reconstruction model to obtain reconstructed image blocks includes: For each of the original image patches, the encoder converts the original image patch into a corresponding latent feature vector, the latent feature vector containing the abstract features of the original image patch; The bottleneck layer processes the potential feature vectors to obtain the corresponding feature distribution; The feature distribution is reconstructed using the decoder to obtain the reconstructed image patch.
3. The method according to claim 2, characterized in that, The step of processing the latent feature vector through the bottleneck layer to obtain the corresponding feature distribution includes: The latent feature vector is mapped to a latent feature space, which is composed of multiple different Gaussian distributions. The different Gaussian distributions represent the normal data features of different parts of the object being measured. Determine the target Gaussian distribution corresponding to the latent feature vector from multiple Gaussian distributions in the latent feature space; The feature vectors are assigned to the target Gaussian distribution to obtain the corresponding feature distribution.
4. The method according to claim 1, characterized in that, The loss function of the jigsaw puzzle generation model includes an HSIC regularization term, which constrains the independence between the reconstructed image patches through HSIC information.
5. The method according to claim 1, characterized in that, Determining the difference between the original image and the reconstructed image includes: The difference value between each reconstructed image block in the reconstructed image and the corresponding original image block in the original image is determined to obtain multiple difference values.
6. The method according to claim 5, characterized in that, The step of determining whether the tested object in the original image has defects based on the difference value includes: If at least a preset number of the multiple difference values are greater than a preset difference threshold, it is determined that the object under test in the original image has a defect. If all the difference values are less than or equal to the preset difference threshold, it is determined that the object being tested in the original image has no defects.
7. The method according to claim 1, characterized in that, The method further includes: If the object under test has defects in the original image, the original image and the reconstructed image are subjected to differential processing to obtain the corresponding residual map; The location of the detected defects in the original image is determined based on the residual map.
8. The method according to claim 1, characterized in that, The steps for constructing the image reconstruction model include: An initial image reconstruction model is constructed based on a deep convolutional neural network model. The framework of the initial image reconstruction model includes an encoder, a bottleneck layer, and a decoder. The encoder is a deep convolutional neural network with fully connected layers removed, and the decoder is an inverse deep convolutional neural network. Obtain a sample image dataset, which includes sample images of defect-free objects of the same type as the object under test; For each sample image in the sample image dataset, the sample image is divided into multiple sample image blocks according to a preset size; The initial image reconstruction model is trained by using multiple sample image patches as input data until all sample images in the sample image dataset have been traversed to obtain the constructed image reconstruction model.
9. A device for defect detection, characterized in that, include: The memory is configured to store instructions; A processor is configured to retrieve the instructions from the memory and, when executing the instructions, to implement the method for defect detection according to any one of claims 1 to 8.
10. A machine-readable storage medium on which a program or instructions are stored, characterized in that, When the program or the instructions are executed by the processor, they implement the method for defect detection according to any one of claims 1 to 8.
Citation Information
Patent Citations
Adversarial network texture surface defect detection method based on abnormal feature editing
CN112164033A
Defect detection method based on variational automatic encoder
CN114862811A
Defect detection method and device, defect training method and device, storage medium and equipment
CN115375617A
Surface defect detection method and device based on feature out-of-order rearrangement
CN118840650A
Unsupervised anomaly detection method based on pre-training feature reconstruction
CN120182679A