A Multi-Class Defect Detection Method and Device Based on Variational Autoencoder and Denoising Network
By combining a variational autoencoder and a denoising network to create an image reconstruction model, the problems of insufficient detection accuracy and category confusion in multi-category defect detection are solved, enabling efficient and accurate detection and localization of surface defects in industrial parts.
Patent Information
- Application Number
- CN202411464089.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2044-10-21
AI Technical Summary
Existing automated defect detection methods suffer from insufficient detection accuracy, high computational costs, and category confusion when inspecting multiple product categories. They are difficult to effectively distinguish between normal and abnormal samples, and their reconstruction results are poor when dealing with small or complex texture defects.
By combining variational autoencoders and denoising networks, an image reconstruction model is constructed, including a variational encoder, a feature-guided network, and a denoising network. Through staged training and multi-scale feature extraction and comparison, accurate localization and detection of multiple types of defects can be achieved.
It reduces training and deployment complexity, improves model generalization ability and detection accuracy, reduces false positives and false negatives, significantly improves detection efficiency and adaptability, and can quickly and accurately locate defect areas on industrial parts.
Smart Images

Figure CN119516249B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer vision and industrial inspection, and in particular to a method and apparatus for detecting multiple types of defects based on variational autoencoders and denoising networks, used for the automated detection and location of surface defects on multiple types of objects such as industrial parts. Background Technology
[0002] In industrial production, defect detection on the surface of parts is a crucial step in ensuring product quality. Most existing automated defect detection methods are based on single-product inspection. For multi-product categories, separate detection models often need to be trained for each category, which not only increases model complexity and computational cost but also presents significant limitations when inspecting cross-category products. Furthermore, existing methods perform poorly in reconstructing defects with fine or complex textures, easily leading to false positives or false negatives.
[0003] In recent years, variational autoencoders (VAEs) and denoising diffusion models have gained widespread attention in anomaly detection tasks due to their powerful image reconstruction capabilities. VAEs can learn the feature distribution of input data and model normal samples using their latent space. However, existing VAE-based detection methods are prone to class confusion when handling multi-class anomaly detection, failing to effectively distinguish between normal and anomalous samples. Furthermore, while diffusion models can generate high-quality images, they typically require multiple diffusion steps, resulting in high computational costs.
[0004] To address the aforementioned issues, how to conduct unified testing on different types of components and accurately locate abnormal areas is one of the problems that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0005] The main objective of this invention is to overcome the shortcomings and deficiencies of the prior art and provide a multi-category defect detection method and device based on variational autoencoder and denoising network. By combining the advantages of VAE and denoising network, it can solve the problems of insufficient detection accuracy, high computational cost and category confusion in the existing technology for multi-category defect detection, and achieve more reliable detection, identification and location of product surface defects.
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] In a first aspect, the present invention provides a multi-category defect detection method based on a variational autoencoder and a denoising network, comprising the following steps:
[0008] Acquire and preprocess images of surface defects in industrial products to construct training and validation sets;
[0009] An image reconstruction model is constructed, comprising a variational encoder, a feature guidance network, a denoising network, and a variational decoder connected in sequence. The variational encoder extracts compact features from the image and learns the image feature distribution. The feature guidance network interacts with the denoising network by extracting features from the variational encoder, guiding the denoising network to perform correct reconstruction across multiple categories. The denoising network further performs secondary reconstruction of image features in the feature space to enhance the reconstruction capability of the image reconstruction model. The variational decoder performs preliminary image reconstruction based on features in the latent space.
[0010] The image reconstruction model is trained in stages using the training set, specifically including: the first stage of training the variational encoder and variational decoder to learn the feature distribution and reconstruction of normal images; and the second stage of training the denoising network to further optimize the reconstruction effect of image features.
[0011] The design of a multi-scale feature extraction ratio compares the multi-scale features extracted from the input image and the reconstructed image by the network, and outputs an anomaly score map, which is used to locate defects.
[0012] The validation set is input into the defect detection model, which consists of an image reconstruction model and a multi-scale feature extraction and comparison network, to conduct validation tests, evaluate the detection performance of the defect detection model, and realize multi-category defect detection in actual industrial scenarios based on the evaluated defect detection model.
[0013] As a preferred technical solution, the step of acquiring and preprocessing images of surface defects in industrial products to construct training and validation sets specifically involves:
[0014] Industrial cameras are used to acquire surface image data of industrial products. An area scan camera is fixed in a top-down position, and the sample is illuminated with uniform light to acquire bright and evenly lit images of the industrial product surface. The images are then classified; data preprocessing is performed on the surface defect images of industrial products according to different categories; after passing through the image acquisition module, normalization and brightness homogenization are performed, converting the images into a format that the model can recognize.
[0015] The acquired image data is cleaned, augmented, and normalized, and then converted into a format that the model can recognize.
[0016] In the preprocessed images, images without anomalies are selected as the training set, and images with anomalies and their corresponding anomaly mask images are selected as the validation set.
[0017] As a preferred technical solution, the construction of the image reconstruction model specifically includes:
[0018] The input image x is compressed into the latent space representation Z using a pre-trained variational encoder, and intermediate layer features f are extracted. iThe latent variable z of the disturbance is generated through a partially positive diffusion process with added noise. t ;f i Input features guide the network to direct the denoising network;
[0019] z t Inputting a denoising network, it outputs a reconstructed latent representation through a one-step inverse diffusion process. And utilize a pre-trained variational decoder to To restore the image to its original level, a reconstructed image is obtained.
[0020] As a preferred technical solution, the step of training the image reconstruction model using a training set in stages specifically involves:
[0021] In the first phase of training, a variational encoder and a variational decoder are trained to compress normal images into the latent space and recover pixel-level representations. Mean squared error loss and perceptual image similarity loss are used as reconstruction loss measures, and KL divergence and maximum mean difference are used to constrain the latent space features. The mean squared error loss is used to reconstruct pixel-level errors, and the perceptual image similarity loss is used to enhance the local realism of the reconstructed image.
[0022] In the second stage of training, a denoising network is trained to perform secondary reconstruction of latent spatial variables, reconstructing large-scale anomalies and texture anomalies, and a feature-guided network is introduced to guide the correct category reconstruction. The loss function in the second stage guides the image reconstruction model to gradually restore the normal data distribution by minimizing the difference between predicted noise and actual noise, thereby enhancing the reconstruction capability of complex defects and anomalies.
[0023] As a preferred technical solution, the feature-guided network extracts features from the intermediate layer of the variational encoder block. Furthermore, it interacts with the output features of the denoising network through a cross-attention mechanism, guiding the denoising network to reconstruct image details more accurately.
[0024] As a preferred technical solution, the multi-scale feature extraction and comparison network, during the inference phase, compares the input original image x with the reconstructed image. Through pre-trained feature extractors Features are extracted, and anomaly scoring maps are generated by calculating the cosine similarity of feature maps at different scales. Abnormal scores It is obtained by weighted summation of the scores of all feature layers.
[0025] As a preferred technical solution, the anomaly scoring graph The calculation formula is as follows:
[0026]
[0027] Where n represents the feature extraction layer, The nth layer features extracted for the pre-trained feature extractor. Anomaly scoring. The result is obtained by weighted summation of the scores from all feature layers:
[0028]
[0029] Where, σ n N is the upsampling factor used to maintain consistent pixel spatial dimensions, and N is the set of feature layers used during inference.
[0030] Secondly, the present invention provides a multi-class defect detection system based on variational autoencoder and denoising network, which is applied to the multi-class defect detection method based on variational autoencoder and denoising network, including an image acquisition module, an image reconstruction module, an information guidance module, a multi-scale feature comparison module and a model deployment module.
[0031] The image acquisition module is used to acquire images of surface defects in industrial products and perform preprocessing to construct training and validation sets.
[0032] The image reconstruction module is used to construct an image reconstruction model, which includes a variational encoder, a feature guidance network, a denoising network, and a variational decoder connected in sequence. The variational encoder is used to extract compact features of the image and learn the image feature distribution. The feature guidance network interacts with the denoising network by extracting features from the variational encoder, guiding the denoising network to perform correct reconstruction for multiple categories. The denoising network further performs secondary reconstruction of image features in the feature space to enhance the reconstruction capability of the image reconstruction model. The variational decoder is used to perform preliminary image reconstruction based on the features of the latent space.
[0033] The information guidance module is used to train the image reconstruction model in stages using the training set. Specifically, it includes: training the variational encoder and variational decoder in the first stage to learn the feature distribution and reconstruction of normal images; and training the denoising network in the second stage to further optimize the reconstruction effect of image features.
[0034] The multi-scale feature comparison module is used to design a multi-scale feature extraction ratio to compare the multi-scale features of the input image and the reconstructed image extracted by the network, and output an anomaly score map, based on which defect localization is achieved;
[0035] The model deployment module is used to input the validation set into the defect detection model composed of a multi-scale feature extraction and comparison network of the image reconstruction model for validation testing, evaluate the detection performance of the defect detection model, and realize multi-category defect detection in actual industrial scenarios based on the evaluated defect detection model.
[0036] Thirdly, the present invention provides an electronic device, the electronic device comprising:
[0037] At least one processor; and,
[0038] A memory communicatively connected to the at least one processor; wherein,
[0039] The memory stores computer program instructions that can be executed by the at least one processor, which enables the at least one processor to execute the multi-category defect detection method based on variational autoencoder and denoising network.
[0040] Fourthly, the present invention provides a computer-readable storage medium storing a program, which, when executed by a processor, implements the multi-category defect detection method based on variational autoencoder and denoising network.
[0041] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0042] 1. This invention proposes a multi-class defect detection method based on variational autoencoders and denoising networks, which can simultaneously process multiple classes of industrial parts in a single model without requiring separate model training for each class. Compared to existing methods that require training independent models for different classes, this invention significantly reduces the complexity of training and deployment, saves substantial computational resources, and improves the model's generalization ability.
[0043] 2. By combining a variational autoencoder (VAE) and a denoising network, this invention can more effectively handle large-scale anomalies and complex texture defects during image reconstruction. The VAE is responsible for initial feature learning and reconstruction, while the denoising network performs secondary reconstruction in the latent space, enabling the model to better capture potential defect information in the image. Compared to traditional reconstruction methods, this invention shows significant advantages in detail recovery and reconstruction accuracy, reducing the possibility of false positives and false negatives.
[0044] 3. This invention guides the denoising U-Net to correctly reconstruct categories through an Information Interaction Branch (IIB), avoiding category confusion in multi-category scenarios. This mechanism enhances the model's robustness in processing multi-category data, ensuring accurate reconstruction and detection of components from different categories. Compared to traditional methods, this mechanism significantly improves the model's adaptability and detection accuracy in multi-category scenarios.
[0045] 4. This invention uses a multi-scale feature comparison module to compare multi-layer features of the input and reconstructed images, and generates an anomaly scoring map using cosine similarity calculation. This enables rapid and accurate localization of defective areas on industrial parts. Compared to existing detection methods that rely on pixel-level errors, the feature comparison method of this invention is more in line with human visual perception, enabling the detection and localization of anomalies in a shorter time, and significantly improving detection efficiency. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0047] Figure 1 This is a flowchart of a multi-category defect detection method based on a variational autoencoder and a denoising network according to an embodiment of the present invention;
[0048] Figure 2 This is a flowchart of the image reconstruction module according to an embodiment of the present invention;
[0049] Figure 3 This is a flowchart of the multi-scale feature comparison module in an embodiment of the present invention;
[0050] Figure 4 This is a block diagram of a multi-category defect detection method based on a variational autoencoder and a denoising network according to an embodiment of the present invention.
[0051] Figure 5 This is a schematic diagram of the structure of the electronic device of the present invention. Detailed Implementation
[0052] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of the present application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative effort are within the scope of protection of the present application.
[0053] In this application, the reference to "embodiment" means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a mutually exclusive, independent, or alternative embodiment. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described in this application can be combined with other embodiments.
[0054] The autoencoder in the title of this application includes two parts: a variational encoder and a variational decoder.
[0055] Please see Figure 1 One embodiment of this application provides a multi-class defect detection method based on variational autoencoder and denoising network, comprising the following steps:
[0056] S1. Acquire surface image data of industrial products using an industrial camera, process the images through the image acquisition module to construct training and validation sets; clean, augment, and normalize the acquired image data, and convert it into a format that the model can recognize.
[0057] Furthermore, an industrial camera is used to acquire surface image data of industrial products. The area array camera is fixed in a top-down position, and the sample is illuminated with uniform light to acquire bright and evenly lit images of the industrial product surface. The images are then classified; the surface defect images of the industrial products are preprocessed according to different categories; after passing through the image acquisition module, they are normalized and brightness uniformized, converting them into a format recognizable by the model. From the processed images, images without anomalies are selected as the training set, and images with anomalies and their corresponding anomaly masks are selected as the validation set.
[0058] S2, please refer to Figure 2 An image reconstruction model is established, consisting of a variational encoder, a feature guidance network, a denoising network, and a variational decoder connected sequentially. Specifically: the variational encoder extracts compact features from the image and learns the image feature distribution; the feature guidance network interacts with the denoising network by extracting features from the variational encoder, guiding the denoising network to perform correct multi-class reconstruction; the denoising network further reconstructs image features in the feature space to enhance the model's reconstruction capability; and the variational decoder performs preliminary image reconstruction based on the features of the latent space. It is understood that in this embodiment, the variational autoencoder includes both a variational encoder and a variational decoder, with the denoising network added between the variational encoder and the variational decoder.
[0059] Furthermore, the multi-class defect detection method based on variational autoencoders and denoising networks is characterized in that the image reconstruction model establishment step includes:
[0060] S21. Use a pre-trained variational encoder on the input image. Encode the latent space representation Z as follows:
[0061]
[0062] Where μ and σ are the mean and variance of the encoder output, respectively, and ∈ represents the noise sampled from the standard normal distribution.
[0063] S22. Perform partial forward diffusion on the latent spatial variable z to generate a perturbed latent variable z. t The details are as follows:
[0064]
[0065] Where α t These are noise scheduling parameters. This indicates cumulative noise scheduling, where ∈ represents the added Gaussian noise.
[0066] S23, the potential variable z of the disturbance t The input is fed into a denoising network, and the reconstructed latent representation is output through a one-step inverse diffusion process. Then, a pre-trained variational decoder is used to... Decode and restore to the original image level to obtain the reconstructed image. The specific process is as follows:
[0067]
[0068] S3. The defect detection model is trained in stages using the training set, specifically including: the first stage of training the variational encoder and variational decoder to learn the feature distribution and reconstruction of normal images; and the second stage of training the denoising network to further optimize the reconstruction effect of image features.
[0069] Furthermore, in the first stage, a variational encoder and a variational decoder are trained to compress the normal image into the latent space and recover its pixel-level representation. The following loss function is used during training:
[0070] Mean squared error (MSE) loss is used to reconstruct pixel-level errors:
[0071]
[0072] Perceptual image similarity (LPIPS) loss is used to enhance the local realism of reconstructed images and avoid blurring.
[0073]
[0074] Where, φ l This refers to the feature layer extracted from the pre-trained network.
[0075] Kullback-Leibler divergence (KL divergence) is used to align the latent spatial distribution to a prior Gaussian distribution:
[0076]
[0077] Maximum mean difference (MMD) is used to maintain the diversity of latent variables and prevent latent space collapse.
[0078]
[0079] The second stage trains the denoising U-Net to perform secondary reconstruction of latent spatial variables, reconstructing large-scale anomalies and texture anomalies, and introduces a feature-guided network to guide the correct category reconstruction. Its loss function is:
[0080]
[0081] Where, ∈ θ r represents the noise predicted by the denoising network, and r represents the original data.
[0082] S4. The feature-guided network extracts features from the variational encoder and interacts with the denoising network to guide the denoising network to perform correct reconstruction of multiple categories.
[0083] Furthermore, the feature-guided network extracts features from the intermediate layers of the variational encoder block. Furthermore, it interacts with the output features of the denoising network through a cross-attention mechanism, guiding the denoising network to more accurately reconstruct image details. The formula for the cross-attention mechanism is:
[0084]
[0085] Where Q is the query vector in the denoising network, K and V are the key and value in the bootstrap network, respectively, and d k is the dimension of the key vector.
[0086] S5, please refer to Figure 3 The multi-scale feature extraction ratio is used to compare the multi-scale features of the input image and the reconstructed image extracted by the network, and an anomaly score map is output. Defect localization is achieved based on the score map.
[0087] Furthermore, the multi-scale feature extraction and comparison network is constructed, and during the inference phase, the input original image x is compared with the reconstructed image. Through pre-trained feature extractors Feature extraction is performed, and anomaly scoring maps are generated by calculating the cosine similarity of feature maps at different scales. The specific formula is as follows:
[0088]
[0089] Where n represents the feature extraction layer, The nth layer features extracted for the pre-trained feature extractor. Anomaly scoring. The result is obtained by weighted summation of the scores from all feature layers:
[0090]
[0091] Where, σ n N is the upsampling factor used to maintain consistent pixel spatial dimensions, and N is the set of feature layers used during inference.
[0092] S6. Use the validation set to validate and test the trained defect detection model, evaluate its detection performance, and deploy the model to the detection system to achieve multi-category defect detection in real industrial scenarios.
[0093] Furthermore, the defect detection model includes the aforementioned image reconstruction model and a multi-scale feature extraction and comparison network.
[0094] It should be noted that, for the sake of simplicity, the aforementioned method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously.
[0095] Based on the same idea as the multi-class defect detection method based on variational autoencoders and denoising networks in the above embodiments, this invention also provides a multi-class defect detection system based on variational autoencoders and denoising networks. This system can be used to execute the above-described multi-class defect detection method based on variational autoencoders and denoising networks. For ease of explanation, the structural diagram of the embodiment of the multi-class defect detection system based on variational autoencoders and denoising networks only shows the parts related to the embodiments of this invention. Those skilled in the art will understand that the illustrated structure does not constitute a limitation on the device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0096] Please see Figure 4 In another embodiment of this application, a multi-class defect detection system 100 based on variational autoencoder and denoising network is provided. The system includes an image acquisition module 101, an image reconstruction module 102, an information guidance module 103, a multi-scale feature comparison module 104, and a model deployment module 105.
[0097] The image acquisition module 101 is used to acquire images of surface defects of industrial products and perform preprocessing to construct training and validation sets.
[0098] The image reconstruction module 102 is used to construct an image reconstruction model, which includes a variational encoder, a feature guidance network, a denoising network, and a variational decoder connected in sequence. The variational encoder is used to extract compact features of the image and learn the image feature distribution. The feature guidance network interacts with the denoising network by extracting features from the variational encoder, guiding the denoising network to perform correct reconstruction for multiple categories. The denoising network further performs secondary reconstruction of image features in the feature space to enhance the reconstruction capability of the image reconstruction model. The variational decoder is used to perform preliminary image reconstruction based on the features of the latent space.
[0099] The information guidance module 103 is used to train the image reconstruction model in stages using the training set, specifically including: the first stage of training the variational encoder and variational decoder to learn the feature distribution and reconstruction of normal images; and the second stage of training the denoising network to further optimize the reconstruction effect of image features.
[0100] The multi-scale feature comparison module 104 is used to design a multi-scale feature extraction ratio to compare the multi-scale features of the input image and the reconstructed image extracted by the network, and output an anomaly score map, based on which defect localization is achieved;
[0101] The model deployment module 105 is used to input the validation set into the defect detection model composed of the multi-scale feature extraction and comparison network of the image reconstruction model for validation testing, evaluate the detection performance of the defect detection model, and realize multi-category defect detection in actual industrial scenarios based on the evaluated defect detection model.
[0102] It should be noted that the multi-class defect detection system based on variational autoencoder and denoising network of the present invention corresponds one-to-one with the multi-class defect detection method based on variational autoencoder and denoising network of the present invention. The technical features and beneficial effects described in the embodiments of the multi-class defect detection method based on variational autoencoder and denoising network are applicable to the embodiments of multi-class defect detection based on variational autoencoder and denoising network. For details, please refer to the description in the embodiments of the method of the present invention, which will not be repeated here.
[0103] Furthermore, in the above embodiments of the multi-category defect detection system based on variational autoencoders and denoising networks, the logical division of each program module is merely illustrative. In practical applications, the above functions can be assigned to different program modules as needed, for example, for the sake of corresponding hardware configuration requirements or the convenience of software implementation. That is, the internal structure of the multi-category defect detection system based on variational autoencoders and denoising networks can be divided into different program modules to complete all or part of the functions described above.
[0104] Please see Figure 5In one embodiment, an electronic device is provided for implementing a multi-category defect detection method based on variational autoencoder and denoising network. The electronic device 200 may include a first processor 201, a first memory 202 and a bus, and may also include a computer program stored in the first memory 202 and executable on the first processor 201, such as a multi-category defect detection program 203 based on variational autoencoder and denoising network.
[0105] The first memory 202 includes at least one type of readable storage medium, including flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the first memory 202 can be an internal storage unit of the electronic device 200, such as the portable hard drive of the electronic device 200. In other embodiments, the first memory 202 can also be an external storage device of the electronic device 200, such as a plug-in portable hard drive, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on the electronic device 200. Furthermore, the first memory 202 can include both internal and external storage units of the electronic device 200. The first memory 202 can be used not only to store application software and various types of data installed on the electronic device 200, such as the code of a multi-category defect detection program 203 based on a variational autoencoder and denoising network, but also to temporarily store data that has been output or will be output.
[0106] In some embodiments, the first processor 201 may be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The first processor 201 is the control unit of the electronic device, connecting various components of the entire electronic device through various interfaces and lines. It executes programs or modules stored in the first memory 202 and calls data stored in the first memory 202 to perform various functions of the electronic device 200 and process data.
[0107] Figure 5 Only electronic devices with components are shown; it will be understood by those skilled in the art that... Figure 5The structure shown does not constitute a limitation on the electronic device 200, and may include fewer or more components than shown, or combine certain components, or have different component arrangements.
[0108] The multi-category defect detection program 203 based on variational autoencoder and denoising network stored in the first memory 202 of the electronic device 200 is a combination of multiple instructions. When run in the first processor 201, it can achieve the following:
[0109] Acquire and preprocess images of surface defects in industrial products to construct training and validation sets;
[0110] An image reconstruction model is constructed, comprising a variational encoder, a feature guidance network, a denoising network, and a variational decoder connected in sequence. The variational encoder extracts compact features from the image and learns the image feature distribution. The feature guidance network interacts with the denoising network by extracting features from the variational encoder, guiding the denoising network to perform correct reconstruction across multiple categories. The denoising network further performs secondary reconstruction of image features in the feature space to enhance the reconstruction capability of the image reconstruction model. The variational decoder performs preliminary image reconstruction based on features in the latent space.
[0111] The image reconstruction model is trained in stages using the training set, specifically including: the first stage of training the variational encoder and variational decoder to learn the feature distribution and reconstruction of normal images; and the second stage of training the denoising network to further optimize the reconstruction effect of image features.
[0112] The design of a multi-scale feature extraction ratio compares the multi-scale features extracted from the input image and the reconstructed image by the network, and outputs an anomaly score map, which is used to locate defects.
[0113] The validation set is input into the defect detection model, which is composed of a multi-scale feature extraction and comparison network of the image reconstruction model, to evaluate the detection performance of the defect detection model. Based on the evaluated defect detection model, multi-category defect detection in real industrial scenarios is realized.
[0114] Furthermore, if the modules / units integrated in the electronic device 200 are implemented as software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium. The computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, or a read-only memory (ROM).
[0115] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0116] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0117] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and shall be included within the protection scope of the present invention.
Claims
1. A multi-category defect detection method based on variational autoencoder and denoising network, characterized in that, Includes the following steps: Acquire and preprocess images of surface defects in industrial products to construct training and validation sets; An image reconstruction model is constructed, comprising a variational encoder, a feature guidance network, a denoising network, and a variational decoder connected in sequence. The variational encoder extracts compact features from the image and learns the image feature distribution. The feature guidance network interacts with the denoising network by extracting features from the variational encoder, guiding the denoising network to perform correct multi-class reconstruction. The denoising network further performs secondary reconstruction of image features in the feature space to enhance the reconstruction capability of the image reconstruction model. The variational decoder performs preliminary image reconstruction based on features in the latent space. Specifically, the construction of the image reconstruction model involves: The input image x is compressed into a latent space representation z using a pre-trained variational encoder, and intermediate layer features f are extracted. i The latent variable z of the disturbance is generated through a partially positive diffusion process with added noise. t ;f i Input features guide the network to direct the denoising network; z t Inputting a denoising network, it outputs a reconstructed latent representation through a one-step inverse diffusion process. And utilize a pre-trained variational decoder to To restore the image to its original level, a reconstructed image is obtained. The image reconstruction model is trained in stages using the training set, specifically including: the first stage of training the variational encoder and variational decoder to learn the feature distribution and reconstruction of normal images; and the second stage of training the denoising network to further optimize the reconstruction effect of image features. A multi-scale feature extraction and comparison network is designed to extract multi-scale features from the input image and the reconstructed image, compare them, and output an anomaly score map. Defect localization is achieved based on this score map. During the inference phase, the multi-scale feature extraction and comparison network compares the input original image x with the reconstructed image x. Through pre-trained feature extractors Features are extracted, and anomaly scoring maps are generated by calculating the cosine similarity of feature maps at different scales. Abnormal scores It is obtained by weighted summation of the scores of all feature layers; The anomaly scoring chart The calculation formula is as follows: Where n represents the feature extraction layer, Anomaly scoring is the nth layer feature extracted by the pre-trained feature extractor. The result is obtained by weighted summation of the scores from all feature layers: Where, σ n The upsampling factor is used to maintain the consistency of pixel spatial dimensions, and N is the set of feature layers used in the inference process; The validation set is input into the defect detection model, which consists of an image reconstruction model and a multi-scale feature extraction and comparison network, to conduct validation tests, evaluate the detection performance of the defect detection model, and realize multi-category defect detection in actual industrial scenarios based on the evaluated defect detection model.
2. The multi-category defect detection method based on variational autoencoder and denoising network according to claim 1, characterized in that, The process of acquiring and preprocessing images of surface defects in industrial products to construct training and validation sets specifically involves: Industrial cameras are used to collect surface image data of industrial products. The area array camera is fixed in a top-down position, and the sample is illuminated with uniform light to collect bright and uniformly lit surface images of industrial products. The images are then classified, and the surface defect images of industrial products are preprocessed according to different categories. After passing through the image acquisition module, the image is normalized and its brightness is uniformized, and then converted into a format that the model can recognize. The acquired image data is cleaned, augmented, and normalized, and then converted into a format that the model can recognize. In the preprocessed images, images without anomalies are selected as the training set, and images with anomalies and their corresponding anomaly mask images are selected as the validation set.
3. The multi-category defect detection method based on variational autoencoder and denoising network according to claim 1, characterized in that, The step of training the image reconstruction model using the training set in stages is as follows: In the first phase of training, a variational encoder and a variational decoder are trained to compress normal images into the latent space and recover pixel-level representations. Mean squared error loss and perceptual image similarity loss are used as reconstruction loss measures, and KL divergence and maximum mean difference are used to constrain the latent space features. The mean squared error loss is used to reconstruct pixel-level errors, and the perceptual image similarity loss is used to enhance the local realism of the reconstructed image. In the second stage of training, a denoising network is trained to perform secondary reconstruction of latent spatial variables, reconstructing large-scale anomalies and texture anomalies, and a feature-guided network is introduced to guide the correct category reconstruction. The loss function in the second stage guides the image reconstruction model to gradually restore the normal data distribution by minimizing the difference between predicted noise and actual noise, thereby enhancing the reconstruction capability of complex defects and anomalies.
4. The multi-category defect detection method based on variational autoencoder and denoising network according to claim 1, characterized in that, The feature-guided network extracts features from the intermediate layers of the variational encoder block. Furthermore, it interacts with the output features of the denoising network through a cross-attention mechanism, guiding the denoising network to reconstruct image details more accurately.
5. A multi-category defect detection system based on variational autoencoder and denoising network, characterized in that, The multi-class defect detection method based on variational autoencoder and denoising network applied to any one of claims 1-4 includes an image acquisition module, an image reconstruction module, an information guidance module, a multi-scale feature comparison module, and a model deployment module; The image acquisition module is used to acquire images of surface defects in industrial products and perform preprocessing to construct training and validation sets. The image reconstruction module is used to construct an image reconstruction model, which includes a variational encoder, a feature guidance network, a denoising network, and a variational decoder connected in sequence. The variational encoder is used to extract compact features of the image and learn the image feature distribution. The feature guidance network interacts with the denoising network by extracting features from the variational encoder, guiding the denoising network to perform correct reconstruction for multiple categories. The denoising network further performs secondary reconstruction of image features in the feature space to enhance the reconstruction capability of the image reconstruction model. The variational decoder is used to perform preliminary image reconstruction based on the features of the latent space. The information guidance module is used to train the image reconstruction model in stages using the training set, specifically including: the first stage of training the variational encoder and variational decoder to learn the feature distribution and reconstruction of normal images; The second stage involves training a denoising network to further optimize the reconstruction of image features. The multi-scale feature comparison module is used to design a multi-scale feature extraction ratio to compare the multi-scale features of the input image and the reconstructed image extracted by the network, and output an anomaly score map, based on which defect localization is achieved; The model deployment module is used to input the validation set into the defect detection model composed of a multi-scale feature extraction and comparison network of the image reconstruction model for validation testing, evaluate the detection performance of the defect detection model, and realize multi-category defect detection in actual industrial scenarios based on the evaluated defect detection model.
6. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores computer program instructions that can be executed by the at least one processor, which enables the at least one processor to perform the multi-class defect detection method based on variational autoencoder and denoising network as described in any one of claims 1-4.
7. A computer-readable storage medium storing a program, characterized in that, When the program is executed by the processor, it implements the multi-category defect detection method based on variational autoencoder and denoising network as described in any one of claims 1-4.
Citation Information
Patent Citations
Defect detection method and device based on de-noising convolution auto-encoder
CN113129272A
Image defect detection method and device and related equipment
CN117788408A