Industrial defect image generation method and system, computer device and storage medium
By lightweighting the denoising diffusion model and introducing a region-aware module and a detail enhancement module, the problems of high computational cost and loss of image details in existing technologies are solved, and efficient and accurate industrial defect image generation is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NANCHANG INST OF TECH
- Filing Date
- 2025-12-09
- Publication Date
- 2026-04-24
AI Technical Summary
Existing methods for generating industrial defect images are computationally expensive in high-resolution or multi-step sampling scenarios, making them difficult to deploy in resource-constrained environments. Furthermore, the global noise addition and removal process introduces uncontrollable interference into background areas that do not need to be changed, affecting image details and accuracy.
By lightweighting the denoising diffusion model and combining it with the region perception module and the detail enhancement module, the computational load and memory usage are reduced, noise is added and removed in a more refined manner, and the model's ability to capture local defect information is improved.
It improves image generation efficiency and detail accuracy, making it suitable for deployment in practical applications and enhancing the quality and speed of generating industrial defect images from the model.
Smart Images

Figure CN121304819B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image generation, and in particular to a method, system, computer device, and storage medium for generating industrial defect images. Background Technology
[0002] With the rapid development of industry, the quality requirements for the production process have become increasingly stringent. Among these requirements, the identification of industrial defects is of paramount importance. Currently, computer vision technology is widely used for industrial defect identification. By processing defect images, the defect area and type can be located. Therefore, acquiring a large number of industrial defect images is essential.
[0003] In existing technologies, industrial defect image samples obtained through real-world photography are often insufficient to support the training requirements of existing recognition models. Therefore, image generation has gradually become one of the important means to obtain a large number of industrial defect image samples. However, existing industrial defect image generation methods often have two shortcomings: First, traditional industrial defect image generation methods require repeated iterative noise removal calculations on the entire image, which leads to a sharp increase in computational costs in high-resolution or multi-step sampling scenarios. In addition to affecting computational efficiency, they are also difficult to deploy in resource-constrained scenarios. Second, in tasks involving the generation of local defects, the global noise addition and removal process can introduce uncontrollable interference to background areas that do not need to be changed, resulting in a decrease in overall image quality or loss of defect details, which limits its practical value in scenarios with stringent requirements for accuracy and efficiency.
[0004] Therefore, how to design an industrial defect image generation method to improve image generation efficiency and ensure the accuracy of image details has become an urgent problem to be solved. Summary of the Invention
[0005] Based on this, the present invention proposes an industrial defect image generation method, system, computer device, and storage medium. By lightweighting the denoising diffusion model, the computational load and memory usage of the model are reduced, thereby improving the model's operating efficiency and making it more suitable for deployment in practical applications. Through the region perception module, the quality of the industrial defect images generated by the model can be improved and the generation speed can be accelerated. The region perception module guides the model to refine the addition and removal of noise, which helps to improve the model's data processing efficiency. Furthermore, through the detail enhancement module, the process of the model processing the input image can be refined and the model's ability to capture local defect information can be improved, thereby improving the quality of the industrial defect images generated by the model. The present invention improves image generation efficiency and the accuracy of image details.
[0006] The present invention proposes a method for generating industrial defect images, comprising:
[0007] An industrial defect dataset is acquired and image preprocessing is performed, the image preprocessing being based on an adaptive linear interpolation algorithm;
[0008] The basic denoising diffusion model is lightweighted to obtain a lightweight denoising diffusion model, which includes a region perception module and a detail enhancement module, and is based on the U-Net architecture.
[0009] The lightweight denoising and diffusion model, guided by the region perception module, performs denoising and diffusion processing on the industrial defect dataset to obtain basic industrial defect images.
[0010] The lightweight denoising diffusion model is enhanced with detail enhancement modules to obtain a detail-enhanced industrial defect image. The detail enhancement is based on multi-scale deconvolution.
[0011] The detailed enhanced industrial defect image is evaluated to obtain the final industrial defect generated image.
[0012] In summary, the above-described method for generating industrial defect images reduces computational load and memory consumption by lightweighting the denoising diffusion model, thereby improving its operational efficiency and making it more suitable for deployment in practical applications. The region awareness module enhances the quality and speed of the generated industrial defect images. Furthermore, by guiding the model to refine noise addition and removal, the module improves data processing efficiency. The detail enhancement module further refines the model's processing of input images and enhances its ability to capture local defect information, thus improving the quality of the generated industrial defect images. This invention improves both image generation efficiency and the accuracy of image details. Specifically, the process involves acquiring an industrial defect dataset and performing image preprocessing. This image preprocessing is based on an adaptive linear interpolation algorithm, which lightweights the basic denoising and diffusion model to obtain a lightweight denoising and diffusion model. This lightweight model includes a region-aware module and a detail enhancement module. Based on the U-Net architecture, this reduces the model's computational load and memory usage, thereby improving its operational efficiency and making it more suitable for deployment in practical applications. The region-aware module guides the lightweight denoising and diffusion model to perform denoising and diffusion processing on the industrial defect dataset to obtain basic industrial defect images, which can improve the model's performance. To improve the quality and speed of industrial defect image generation, the region perception module guides the model to refine the addition and removal of noise, which helps improve the model's data processing efficiency. The detail enhancement module then enhances the lightweight denoising diffusion model to obtain a detail-enhanced industrial defect image. This detail enhancement, based on multi-scale deconvolution, refines the model's processing of the input image and improves its ability to capture local defect information, thereby improving the quality of the generated industrial defect image. The detail-enhanced industrial defect image is then evaluated to obtain the final industrial defect image. This invention improves image generation efficiency and the accuracy of image details.
[0013] Furthermore, the step of acquiring the industrial defect dataset and performing image preprocessing specifically includes:
[0014] An industrial defect dataset is acquired, and super-resolution reconstruction is performed on the dataset using an adaptive linear interpolation algorithm. This algorithm adaptively adjusts the interpolation direction based on local gradients. In flat regions, standard bilinear interpolation is used; in edge regions, interpolation is performed along the edge direction. If the defect edge is horizontal, interpolation is performed horizontally; if the defect edge is vertical, interpolation is performed vertically; and if the defect edge is oblique, interpolation is performed along the corresponding diagonal direction. The specific details of the adaptive linear interpolation algorithm are as follows:
[0015] ,
[0016] ,
[0017] Where A, B, C, D, E, F, and G represent the neighboring pixels of the current pixel, and the specific coordinates of the neighboring pixels are A=(i,j-1), B=(i,j+1), C=(i-1,j), D=(i+1,j), E=(i-1,j-1), F=I(i+1,j+1), G=(i-1,j+1), H=(i+1,j-1), where i and j represent the x and y coordinates of the current pixel. Represents the gradient value in the horizontal direction. Represents the gradient value in the vertical direction. Represents the gradient value along the main diagonal. This represents the gradient value in the anti-diagonal direction. This represents the minimum value in the gradient. P This represents the interpolated pixel value. This indicates that the minimum value is used for calculation.
[0018] Furthermore, the step of lightweighting the basic denoising diffusion model to obtain a lightweight denoising diffusion model specifically includes:
[0019] The basic denoising diffusion model is lightweighted to obtain a lightweight denoising diffusion model. The lightweight denoising diffusion model is based on the U-Net architecture and specifically includes 16 conv3×3 convolutional layers with 3 kernels, 1 conv1×1 convolutional layer with 1 kernel, 4 max pool downsampling layers, 4 multi-scale deconvolutional layers, and 3 concat connection layers.
[0020] Furthermore, the step of guiding the lightweight denoising and diffusion model to perform denoising and diffusion processing on the industrial defect dataset according to the region perception module to obtain basic industrial defect images specifically includes:
[0021] The defect region and time k value are obtained based on the region awareness module. The range of the defect region is obtained according to the defect region annotation in the industrial defect dataset. The specific algorithm for the time k value is as follows:
[0022] ,
[0023] in, k Indicates the value of time k. Indicates to k Rounding to the nearest whole number, S X S represents the total number of pixels in the input image of the industrial defect dataset. X’This represents the total number of pixels in the defective region, and T is the total number of time steps during the noise addition process.
[0024] Based on the defect region and the time k value, a lightweight denoising diffusion model is used to perform denoising diffusion processing on the industrial defect dataset to obtain basic industrial defect images.
[0025] Furthermore, the step of guiding the lightweight denoising and diffusion model to perform denoising and diffusion processing on the industrial defect dataset based on the defect region and the time k value specifically includes:
[0026] Forward noise addition is performed based on the defect region and the time value k. The specific algorithm for forward noise addition is as follows:
[0027] ,
[0028] in, X t Indicates time k Image of the whole picture before interference and image after adding noise. and Let represent the noise intensity at times t and T, respectively, and α t and α T Less than or equal to 1, where T is the total number of time steps in the noise addition process, and t represents the t-th time step in the noise addition process. Indicates the time of output from the area perception module. ε t-1 and ε T-1 Let these represent the noise that follows a standard Gaussian distribution at times t-1 and T-1, respectively. This represents an image with the defect area marked by a region mask and noise added at time step T. This represents the noise map after the forward noise addition process is completed at time k. An image showing the completion of the forward noise addition process;
[0029] Inverse denoising is performed based on the defect region and the time value k. The specific algorithm for inverse denoising is as follows:
[0030] ,
[0031] in, and These are images of the defect region at times T-1 and k, respectively, during the noise removal process. This represents the full-image view at time t-1 during the noise removal process. and These represent the prediction noise at T-1 and t-1, respectively.
[0032] The step of performing detail enhancement on the lightweight denoising diffusion model according to the detail enhancement module to obtain a detail-enhanced industrial defect image specifically includes:
[0033] The detail enhancement module is based on multi-scale deconvolution, which specifically includes:
[0034] ,
[0035] ,
[0036] ,
[0037] ,
[0038] ,
[0039] in, This represents a convolution with a kernel of 1. This indicates a convolution with a kernel of 3. This indicates a convolution with a kernel of 5. This represents a convolution with a kernel of 7. Indicates channel fusion, This indicates the output after channel fusion. express The output after convolution processing with a kernel of 1 Indicates channel weight, This represents the Sigmoid activation function. Indicates a fully connected network. Indicates the max pooling layer. Indicates normalization, Indicates learnable parameters, This indicates an input identity mapping. This represents a weight parameter with a value range of 0 to 1.
[0040] Furthermore, the step of evaluating the enhanced industrial defect image to obtain the final industrial defect generation image specifically includes:
[0041] The algorithm for evaluating detailed industrial defect images is as follows:
[0042] ,
[0043] ,
[0044] in, IS(G) Indicates the initial score of the image. FID Represents the FID score. Indicates the distribution from productionP g Medium-sampled images x Find the average, D KL Denotes KL divergence, Indicates in a given image x In this case, the classifier predicts the category y The probability distribution, Represents the category prediction for all generated images y The average distribution The mean of the feature vectors representing the real image. This represents the mean of the feature vectors of the generated image. Let represent the square of the Euclidean norm, and Tr represent the trace of the matrix. The covariance matrix representing the feature vectors of a real image. The covariance matrix of the feature vectors of the generated image.
[0045] The present invention proposes an industrial defect image generation system, characterized in that it comprises:
[0046] The preprocessing module is used to acquire industrial defect datasets and perform image preprocessing, which is based on an adaptive linear interpolation algorithm.
[0047] The lightweight module is used to perform lightweight processing on the basic denoising diffusion model to obtain a lightweight denoising diffusion model. The lightweight denoising diffusion model includes a region perception module and a detail enhancement module. The lightweight denoising diffusion model is based on the U-Net architecture.
[0048] The region perception module is used to guide the lightweight denoising diffusion model to perform denoising diffusion processing on the industrial defect dataset in order to obtain basic industrial defect images.
[0049] A detail enhancement module is used to enhance the details of the lightweight denoising diffusion model according to the detail enhancement module to obtain a detail-enhanced industrial defect image, wherein the detail enhancement is based on multi-scale deconvolution.
[0050] An evaluation module is used to evaluate the enhanced industrial defect image to obtain a final industrial defect generation image.
[0051] The present invention also provides a storage medium that stores one or more programs, which, when executed by a processor, implement the industrial defect image generation method described above.
[0052] The present invention also provides a computer device, the computer device including a memory and a processor, wherein:
[0053] The memory is used to store computer programs;
[0054] When the processor executes the computer program stored in the memory, it implements the industrial defect image generation method described above. Attached Figure Description
[0055] Figure 1 This is a flowchart of the industrial defect image generation method proposed in the first embodiment of the present invention;
[0056] Figure 2 This is a schematic diagram of the industrial defect image generation system proposed in the second embodiment of the present invention;
[0057] Figure 3 This is a diagram of the U-Net network structure of the lightweight denoising diffusion model of the present invention.
[0058] The following detailed description, in conjunction with the accompanying drawings, will further illustrate the present invention. Detailed Implementation
[0059] To facilitate understanding of the present invention, a more complete description will be given below with reference to the accompanying drawings. Several embodiments of the invention are illustrated in the drawings. However, the invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
[0060] It should be noted that when a component is said to be "fixed to" another component, it can be directly on the other component or there may be an intervening component. When a component is said to be "connected to" another component, it can be directly connected to the other component or there may be an intervening component. The terms "vertical," "horizontal," "left," "right," and similar expressions used in this document are for illustrative purposes only.
[0061] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0062] Please see Figure 1 The diagram shows a flowchart of an industrial defect image generation method proposed in the first embodiment of the present invention. This industrial defect image generation method includes steps S01 to S05, wherein:
[0063] Step S01: Obtain the industrial defect dataset and perform image preprocessing;
[0064] It should be noted that in this embodiment, the image preprocessing is based on an adaptive linear interpolation algorithm. An industrial defect dataset is acquired, and super-resolution reconstruction is performed on the dataset using the adaptive linear interpolation algorithm. The adaptive linear interpolation algorithm adaptively adjusts the interpolation direction based on the local gradient. When the defect is in a flat region, standard bilinear interpolation is used; when it is in an edge region, interpolation is performed along the edge direction. If the defect edge is horizontal, interpolation is performed along the horizontal direction; if the defect edge is vertical, interpolation is performed along the vertical direction; if the defect edge is oblique, interpolation is performed along the corresponding diagonal direction. The specific adaptive linear interpolation algorithm is as follows:
[0065] ,
[0066] ,
[0067] Where A, B, C, D, E, F, and G represent the neighboring pixels of the current pixel, and the specific coordinates of the neighboring pixels are A=(i,j-1), B=(i,j+1), C=(i-1,j), D=(i+1,j), E=(i-1,j-1), F=I(i+1,j+1), G=(i-1,j+1), H=(i+1,j-1), where i and j represent the x and y coordinates of the current pixel. Represents the gradient value in the horizontal direction. Represents the gradient value in the vertical direction. Represents the gradient value along the main diagonal. This represents the gradient value in the anti-diagonal direction. This represents the minimum value in the gradient. P This represents the interpolated pixel value. This indicates that the minimum value is used for calculation.
[0068] Step S02: Lightweight the basic denoising diffusion model to obtain a lightweight denoising diffusion model;
[0069] It should be noted that in this embodiment, lightweighting the basic denoising diffusion model DDPM is a key step. Its purpose is to reduce the model's computational complexity and memory footprint, thereby improving its operating efficiency in resource-constrained environments. Specifically, the lightweighting process involves removing the last max pool module and its corresponding up-conv module from the U-Net network in the DDPM model. The last max pool module and its corresponding up-conv module in the U-Net network are located at the deepest part of the network and are used to capture information about large objects in the input data. However, industrial defects are often localized. Therefore, removing these modules not only reduces redundant computation but also allows the model to focus more on the feature representation of small- and medium-scale defects. The lightweight DDPM model has similar functionality to the original DDPM model, but with significantly reduced computation, making it more suitable for deployment in real-world industrial inspection scenarios. This is achieved by removing the last max pool module and its corresponding up-conv module from the U-Net network in the DDPM model. The pool module and its corresponding up-conv module significantly reduce the computational cost of the DDPM model. This structural modification makes the network more efficient in processing input data compared to the normal U-Net network, thereby reducing the model's computational complexity and memory usage. The lightweight DDPM model is beneficial for deployment in resource-constrained scenarios such as embedded systems or mobile devices, improving the model's practicality and applicability. Although the lightweight model reduces the network depth and cuts some computational and storage overhead, the industrial defects are usually small in size, so this processing will not significantly affect the model's performance. Therefore, the lightweight DDPM model can still maintain high image generation quality. The lightweight denoising diffusion model includes a region-aware module and a detail enhancement module. The lightweight denoising diffusion model is based on the U-Net architecture and is obtained by lightweighting the basic denoising diffusion model. The lightweight denoising diffusion model is based on the U-Net architecture and specifically includes 16 conv3×3 convolutional layers with 3 kernels, 1 conv1×1 convolutional layer with 1 kernel, and 4 max... The system consists of a pooled downsampling layer, four multi-scale deconvolutional layers, and three concat connection layers.
[0070] Step S03: Guide the lightweight denoising and diffusion model based on the region perception module to perform denoising and diffusion processing on the industrial defect dataset to obtain basic industrial defect images;
[0071] It should be noted that in this embodiment, the region awareness module RP, through a lightweight segmentation model, can generate high-precision binary region masks in real time and mark defect regions, such as 1 representing a defect region and 0 representing the background. The generated binary region mask is fed into the DDPM model, which can accurately locate the positions of defects and background in the input data. This allows the model to add or remove noise to different regions of the data. The RP model can receive a time k set by the user, which guides the model to add or remove noise to different regions of the input data at what time. The value of the user-designed parameter k should be set according to the background of the input data. For example, if there are large objects in the background, the value of k should be larger to ensure the authenticity of the generated industrial defect image. The region awareness module RP needs to obtain the region mask of the defect region, which is achieved through the lightweight segmentation model, which can obtain the region mask in real time. By marking the defect region through the region mask, the defect can be accurately identified. The location of the defect is identified and passed to the model, enabling the model to perceive the defect location. The RP_DDPM denoising and diffusion model, guided by region perception, uses a region mask to mark the defect area and time k to guide the forward noise addition and backward noise removal process. This allows the model to add or remove noise to different areas at different times, refining the data processing and improving processing speed and image quality. By setting the value of k, the number of times noise is added to the image background is changed, improving the quality of the generated image background. Compared to DDPM, which adds and removes noise across the entire image, the RP_DDPM model, through the RP module's processing of input data and the guidance of time k, offers more targeted processing, reducing unnecessary computational waste and improving defect handling capabilities. The defect area and time k value are obtained from the region perception module. The extent of the defect area is obtained based on defect area annotations in the industrial defect dataset. The specific algorithm for determining the time k value is as follows:
[0072] ,
[0073] in, k Indicates the value of time k. Indicates to k Rounding to the nearest whole number, S X S represents the total number of pixels in the input image of the industrial defect dataset. X’ This represents the total number of pixels in the defective region, and T is the total number of time steps during the noise addition process.
[0074] Based on the defect region and the time k value, a lightweight denoising diffusion model is used to perform denoising diffusion processing on the industrial defect dataset to obtain basic industrial defect images.
[0075] Forward noise addition is performed based on the defect region and the time value k. The specific algorithm for forward noise addition is as follows:
[0076] ,
[0077] in, X t Indicates time k Image of the whole picture before interference and image after adding noise. and Let represent the noise intensity at times t and T, respectively, and α t and α T Less than or equal to 1, where T is the total number of time steps in the noise addition process, and t represents the t-th time step in the noise addition process. Indicates the time of output from the area perception module. ε t-1 and ε T-1 Let these represent the noise that follows a standard Gaussian distribution at times t-1 and T-1, respectively. This represents an image with the defect area marked by a region mask and noise added at time step T. This represents the noise map after the forward noise addition process is completed at time k. An image showing the completion of the forward noise addition process;
[0078] Inverse denoising is performed based on the defect region and the time value k. The specific algorithm for inverse denoising is as follows:
[0079] ,
[0080] in, and These are images of the defect region at times T-1 and k, respectively, during the noise removal process. This represents the full-image view at time t-1 during the noise removal process. and These represent the prediction noise at T-1 and t-1, respectively;
[0081] By marking defect regions using the region-aware RP module, the location of defects in the input data can be identified, guiding the RP_DDPM model to focus on local defect locations and improving the model's defect information acquisition capabilities. By receiving user-defined time k through the region-aware RP module, the model can be guided on when and in which regions of the input data to add noise, enabling more refined processing of the input data and improving its processing speed. Through proper design, the RP module can be effectively integrated into the RP_DDPM model to enhance its performance and efficiency. The region-aware RP module marks the location of defects in the input data and provides... The time step k helps the model to specifically remove noise, improving the quality and speed of generating industrial defect images. After time k, the reverse process model removes noise from the noise-laden regions, helping the model focus on defect generation and improving the realism of generated defects. Before time k, the reverse process model removes noise from the entire image after adding noise, helping the model acquire global information and improving the realism of generated industrial images containing defects. The number of noise removal steps for the entire image can be controlled by the size of time k, which can affect the model's generation speed and quality. By properly designing the RP module, it can be effectively integrated into the RP_DDPM model, improving the quality of the images generated by the model.
[0082] Step S04: Perform detail enhancement on the lightweight denoising diffusion model according to the detail enhancement module to obtain a detail-enhanced industrial defect image;
[0083] It should be noted that in this embodiment, the detail enhancement is based on multi-scale deconvolution, which specifically includes:
[0084] ,
[0085] ,
[0086] ,
[0087] ,
[0088] ,
[0089] in, This represents a convolution with a kernel of 1. This indicates a convolution with a kernel of 3. This indicates a convolution with a kernel of 5. This represents a convolution with a kernel of 7. Indicates channel fusion, This indicates the output after channel fusion. express The output after convolution processing with a kernel of 1 Indicates channel weight, This represents the Sigmoid activation function. Indicates a fully connected network. Indicates the max pooling layer. Indicates normalization, Indicates learnable parameters, This indicates an input identity mapping. This represents a weight parameter with a value range of 0 to 1.
[0090] The detail enhancement module MSR-RevConv overcomes the limitations of single convolutional kernels and fixed regularization by using multi-scale convolutional kernel fusion, channel adaptive regularization, and residual enhancement. This significantly enhances the detail fidelity in image restoration tasks, thereby improving the accuracy of the model in predicting noise. The up-conv module in the U-Net network was chosen to replace the MSR-RevConv module because it has the same function as the MSR-RevConv module and therefore does not affect the basic working mechanism of the model. By properly configuring the MSR-RevConv module into the U-Net network of the RP_DDPM model, the quality of industrial defect images generated by the model can be improved.
[0091] Step S05: Evaluate the enhanced detail industrial defect image to obtain the final industrial defect generation image;
[0092] It should be noted that in this embodiment, the detailed industrial defect image is evaluated, and the specific algorithm for the evaluation is as follows:
[0093] ,
[0094] ,
[0095] in, IS(G) Indicates the initial score of the image. FID Represents the FID score. Indicates the distribution from production P g Medium-sampled images x Find the average, D KL Denotes KL divergence, Indicates in a given image x In this case, the classifier predicts the category y The probability distribution, Represents the category prediction for all generated images y average distribution The mean of the feature vectors representing the real image. This represents the mean of the feature vectors of the generated image. Let represent the square of the Euclidean norm, and Tr represent the trace of the matrix. The covariance matrix representing the feature vectors of a real image. The covariance matrix of the feature vectors of the generated image.
[0096] The initial score is a comprehensive evaluation metric for the quality and diversity of the output samples of the generative model. It quantifies the difference in probability distribution between the generated images and the pre-trained classification model. This metric is based on the KL divergence between the conditional class distribution and the marginal class distribution, reflecting both the sharpness and class coverage of the generated images. The initial score is one of the core metrics for evaluating the performance of generative models such as DDPM. It integrates the realism and diversity of the generated samples through a single numerical value. By calculating the statistics of multiple sets of generated samples and taking the exponential operation, the initial score can effectively balance the differences in generation effects between different classes, providing clear directional guidance for model optimization. The FID score is a comprehensive evaluation metric for the quality and diversity of the output samples of a generative model. It is quantified by calculating the Freche distance between generated and real samples in the deep feature space. This metric is based on feature vectors extracted by a pre-trained convolutional neural network and compares the similarity of the mean and covariance matrices of the two feature distributions. The FID score is one of the core metrics for measuring the performance of the DDPM generative model. The lower the value, the closer the distribution of generated samples is to that of real samples. By transforming the complex distribution differences in the high-dimensional feature space into a single scalar value, the FID score can simultaneously and sensitively reflect the realism and diversity of generated images, providing a stable and reliable evaluation benchmark for model performance.
[0097] In summary, the above-described method for generating industrial defect images reduces computational load and memory consumption by lightweighting the denoising diffusion model, thereby improving its operational efficiency and making it more suitable for deployment in practical applications. The region awareness module enhances the quality and speed of the generated industrial defect images. Furthermore, by guiding the model to refine noise addition and removal, the module improves data processing efficiency. The detail enhancement module further refines the model's processing of input images and enhances its ability to capture local defect information, thus improving the quality of the generated industrial defect images. This invention improves both image generation efficiency and the accuracy of image details. Specifically, the process involves acquiring an industrial defect dataset and performing image preprocessing. This image preprocessing is based on an adaptive linear interpolation algorithm, which lightweights the basic denoising and diffusion model to obtain a lightweight denoising and diffusion model. This lightweight model includes a region-aware module and a detail enhancement module. Based on the U-Net architecture, this reduces the model's computational load and memory usage, thereby improving its operational efficiency and making it more suitable for deployment in practical applications. The region-aware module guides the lightweight denoising and diffusion model to perform denoising and diffusion processing on the industrial defect dataset to obtain basic industrial defect images, which can improve the model's performance. To improve the quality and speed of industrial defect image generation, the region perception module guides the model to refine the addition and removal of noise, which helps improve the model's data processing efficiency. The detail enhancement module then enhances the lightweight denoising diffusion model to obtain a detail-enhanced industrial defect image. This detail enhancement, based on multi-scale deconvolution, refines the model's processing of the input image and improves its ability to capture local defect information, thereby improving the quality of the generated industrial defect image. The detail-enhanced industrial defect image is then evaluated to obtain the final industrial defect image. This invention improves image generation efficiency and the accuracy of image details.
[0098] Please see Figure 2 The diagram shows a schematic representation of an industrial defect image generation system proposed in the second embodiment of the present invention. The system includes:
[0099] Preprocessing module 10 is used to acquire industrial defect datasets and perform image preprocessing, wherein the image preprocessing is based on an adaptive linear interpolation algorithm;
[0100] The lightweight module 20 is used to perform lightweight processing on the basic denoising diffusion model to obtain a lightweight denoising diffusion model. The lightweight denoising diffusion model includes a region perception module and a detail enhancement module. The lightweight denoising diffusion model is based on the U-Net architecture.
[0101] The region perception module 30 is used to guide the lightweight denoising diffusion model to perform denoising diffusion processing on the industrial defect dataset in order to obtain basic industrial defect images.
[0102] Detail enhancement module 40 is used to enhance the details of the lightweight denoising diffusion model according to the detail enhancement module to obtain a detail-enhanced industrial defect image, wherein the detail enhancement is based on multi-scale deconvolution;
[0103] Evaluation module 50 is used to evaluate the enhanced detail industrial defect image to obtain a final industrial defect generated image.
[0104] The present invention also proposes a computer storage medium storing one or more programs that, when executed by a processor, implement the above-described method for generating industrial defect images.
[0105] The present invention also proposes a computer device, including a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to implement the above-described industrial defect image generation method.
[0106] Those skilled in the art will understand that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can mean any means that can contain stored, communicated, propagated, or transmitted programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0107] More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which the program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0108] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0109] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0110] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention. Therefore, the scope of protection of this patent should be determined by the appended claims.
Claims
1. A method for generating industrial defect images, characterized in that, include: An industrial defect dataset is acquired and image preprocessing is performed, the image preprocessing being based on an adaptive linear interpolation algorithm; The basic denoising diffusion model is lightweighted to obtain a lightweight denoising diffusion model, which includes a region perception module and a detail enhancement module, and is based on the U-Net architecture. The lightweight denoising and diffusion model, guided by the region perception module, performs denoising and diffusion processing on the industrial defect dataset to obtain basic industrial defect images. The step of guiding the lightweight denoising and diffusion model to perform denoising and diffusion processing on the industrial defect dataset according to the region perception module to obtain basic industrial defect images specifically includes: The defect region and time k value are obtained based on the region awareness module. The range of the defect region is obtained according to the defect region annotation in the industrial defect dataset. The specific algorithm for the time k value is as follows: , in, k Indicates the value of time k. Indicates to k Rounding to the nearest whole number, S X S represents the total number of pixels in the input image of the industrial defect dataset. X’ This represents the total number of pixels in the defective region, and T is the total number of time steps during the noise addition process. Based on the defect region and the time k value, a lightweight denoising diffusion model is used to perform denoising diffusion processing on the industrial defect dataset to obtain a basic industrial defect image. The steps of guiding a lightweight denoising and diffusion model to perform denoising and diffusion processing on the industrial defect dataset based on the defect region and the time k value specifically include: Forward noise addition is performed based on the defect region and the time value k. The specific algorithm for forward noise addition is as follows: , in, X t Indicates time k Image of the whole picture before interference and image after adding noise. and Let represent the noise intensity at times t and T, respectively, and α t and α T Less than or equal to 1, where T is the total number of time steps in the noise addition process, and t represents the t-th time step in the noise addition process. Indicates the time of output from the area perception module. ε t-1 and ε T-1 Let these represent the noise that follows a standard Gaussian distribution at times t-1 and T-1, respectively. This represents an image with the defect area marked by a region mask and noise added at time step T. This represents the noise map after the forward noise addition process is completed at time k. An image showing the completion of the forward noise addition process; Inverse denoising is performed based on the defect region and the time value k. The specific algorithm for inverse denoising is as follows: , in, and These are images of the defect region at times T-1 and k, respectively, during the noise removal process. This represents the full-image view at time t-1 during the noise removal process. and These represent the prediction noise at T-1 and t-1, respectively; The lightweight denoising diffusion model is enhanced with detail enhancement modules to obtain a detail-enhanced industrial defect image. The detail enhancement is based on multi-scale deconvolution. The detailed enhanced industrial defect image is evaluated to obtain the final industrial defect generated image.
2. The industrial defect image generation method according to claim 1, characterized in that, The steps of acquiring industrial defect datasets and performing image preprocessing specifically include: An industrial defect dataset is acquired, and super-resolution reconstruction is performed on the dataset using an adaptive linear interpolation algorithm. This algorithm adaptively adjusts the interpolation direction based on local gradients. In flat regions, standard bilinear interpolation is used; in edge regions, interpolation is performed along the edge direction. If the defect edge is horizontal, interpolation is performed horizontally; if the defect edge is vertical, interpolation is performed vertically; and if the defect edge is oblique, interpolation is performed along the corresponding diagonal direction. The specific details of the adaptive linear interpolation algorithm are as follows: , , Where A, B, C, D, E, F, G, and H represent the neighboring pixels of the current pixel, and the specific coordinates of the neighboring pixels are A=(i,j-1), B=(i,j+1), C=(i-1,j), D=(i+1,j), E=(i-1,j-1), F=I(i+1,j+1), G=(i-1,j+1), H=(i+1,j-1), where i and j represent the x and y coordinates of the current pixel. Represents the gradient value in the horizontal direction. Represents the gradient value in the vertical direction. Represents the gradient value along the main diagonal. This represents the gradient value in the anti-diagonal direction. This represents the minimum value in the gradient. P This represents the interpolated pixel value. This indicates that the minimum value is used for calculation.
3. The industrial defect image generation method according to claim 1, characterized in that, The step of lightweighting the basic denoising diffusion model to obtain a lightweight denoising diffusion model specifically includes: The basic denoising diffusion model is lightweighted to obtain a lightweight denoising diffusion model. The lightweight denoising diffusion model is based on the U-Net architecture and specifically includes 16 conv3×3 convolutional layers with 3 kernels, 1 conv1×1 convolutional layer with 1 kernel, 4 max pool downsampling layers, 4 multi-scale deconvolutional layers, and 3 concat connection layers.
4. The industrial defect image generation method according to claim 1, characterized in that, The step of performing detail enhancement on the lightweight denoising diffusion model according to the detail enhancement module to obtain a detail-enhanced industrial defect image specifically includes: The detail enhancement module is based on multi-scale deconvolution, which specifically includes: , , , , , in, This represents a convolution with a kernel of 1. This indicates a convolution with a kernel of 3. This indicates a convolution with a kernel of 5. This represents a convolution with a kernel of 7. Indicates channel fusion, This indicates the output after channel fusion. express The output after convolution processing with a kernel of 1 Indicates channel weight, This represents the Sigmoid activation function. Indicates a fully connected network. Indicates the max pooling layer. Indicates normalization, Indicates learnable parameters, This indicates an input identity mapping. This represents a weight parameter with a value range of 0 to 1.
5. The industrial defect image generation method according to claim 1, characterized in that, The step of evaluating the enhanced industrial defect image to obtain a final industrial defect image specifically includes: The algorithm for evaluating detailed industrial defect images is as follows: , , in, IS(G) Indicates the initial score of the image. FID Represents the FID score. Indicates the distribution from production P g Medium-sampled images x Find the average, D KL Denotes KL divergence, Indicates in a given image x In this case, the classifier predicts the category y The probability distribution, Represents the category prediction for all generated images y The average distribution The mean of the feature vectors representing the real image. This represents the mean of the feature vectors of the generated image. Let represent the square of the Euclidean norm, and Tr represent the trace of the matrix. The covariance matrix representing the feature vectors of a real image. The covariance matrix of the feature vectors of the generated image.
6. An industrial defect image generation system, characterized in that, include: The preprocessing module is used to acquire industrial defect datasets and perform image preprocessing, which is based on an adaptive linear interpolation algorithm. The lightweight module is used to perform lightweight processing on the basic denoising diffusion model to obtain a lightweight denoising diffusion model. The lightweight denoising diffusion model includes a region perception module and a detail enhancement module. The lightweight denoising diffusion model is based on the U-Net architecture. The region perception module is used to guide the lightweight denoising diffusion model to perform denoising diffusion processing on the industrial defect dataset in order to obtain basic industrial defect images. The steps of using the lightweight denoising and diffusion model guided by the region-aware module to perform denoising and diffusion processing on the industrial defect dataset to obtain basic industrial defect images specifically include: The defect region and time k value are obtained based on the region awareness module. The range of the defect region is obtained according to the defect region annotation in the industrial defect dataset. The specific algorithm for the time k value is as follows: , in, k Indicates the value of time k. Indicates to k Rounding to the nearest whole number, S X S represents the total number of pixels in the input image of the industrial defect dataset. X’ This represents the total number of pixels in the defective region, and T is the total number of time steps during the noise addition process. Based on the defect region and the time k value, a lightweight denoising diffusion model is used to perform denoising diffusion processing on the industrial defect dataset to obtain a basic industrial defect image. The steps of guiding a lightweight denoising and diffusion model to perform denoising and diffusion processing on the industrial defect dataset based on the defect region and the time k value specifically include: Forward noise addition is performed based on the defect region and the time value k. The specific algorithm for forward noise addition is as follows: , in, X t Indicates time k Image of the whole picture before interference and image after adding noise. and Let represent the noise intensity at times t and T, respectively, and α t and α T Less than or equal to 1, where T is the total number of time steps in the noise addition process, and t represents the t-th time step in the noise addition process. Indicates the time of output from the area perception module. ε t-1 and ε T-1 Let these represent the noise that follows a standard Gaussian distribution at times t-1 and T-1, respectively. This represents an image with the defect area marked by a region mask and noise added at time step T. This represents the noise map after the forward noise addition process is completed at time k. An image showing the completion of the forward noise addition process; Inverse denoising is performed based on the defect region and the time value k. The specific algorithm for inverse denoising is as follows: , in, and These are images of the defect region at times T-1 and k, respectively, during the noise removal process. This represents the full-image view at time t-1 during the noise removal process. and These represent the prediction noise at T-1 and t-1, respectively; The detail enhancement module is used to enhance the details of the lightweight denoising diffusion model according to the detail enhancement module to obtain a detail-enhanced industrial defect image, wherein the detail enhancement is based on multi-scale deconvolution; An evaluation module is used to evaluate the enhanced industrial defect image to obtain a final industrial defect generation image.
7. A storage medium, characterized in that, The storage medium stores one or more programs that, when executed by a processor, implement the industrial defect image generation method as described in any one of claims 1-5.
8. A computer device, characterized in that, The computer device includes a memory and a processor, wherein: The memory is used to store computer programs; When the processor executes the computer program stored in the memory, it implements the industrial defect image generation method according to any one of claims 1-5.
Citation Information
Patent Citations
Industrial defect detection and data enhancement method based on lightweight diffusion model adapter
CN120388002A
Industrial defect detection method based on lightweight diffusion encoder and resolution decision
CN121074055A