Defect image generation method and device, model training method and device, medium and product

By using the noise processing module and the feature extraction module to generate defect images, the problem of difficulty in obtaining defect samples in industrial defect detection is solved, and the accuracy and training efficiency of the model are improved.

CN118761983APending Publication Date: 2024-10-11BOE TECHNOLOGY GROUP CO LTD +1
View PDF 0 Cites 6 Cited by

Patent Information

Application Number
CN202410888542.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-03
Publication Date
2024-10-11

AI Technical Summary

Technical Problem

In industrial defect detection, defect samples are difficult to obtain on a large scale, which makes it difficult to train defect detection models. Existing defect generation methods suffer from training instability problems.

Method used

A defect image generation method is proposed. By obtaining the target image, target mask image and target defect type, the noise processing module and feature extraction module in the pre-trained defect image generation model are used to generate the target defect image, which provides a large number of defects. data to improve the accuracy of the detection model.

Benefits of technology

By generating high-quality defect images, the problem of difficulty in obtaining defect samples is solved, the accuracy of the defect detection model is improved, and the training cost is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118761983A_ABST
    Figure CN118761983A_ABST
Patent Text Reader

Abstract

The invention provides a defect image generation method and device, a model training method and device, a medium and a product, and the method comprises the steps: obtaining a target image, a target mask image and a target defect type, and enabling the target image to be a defect-free image; inputting the target image, the target mask image and the target defect type into a pre-trained defect image generation model; wherein the defect image generation model comprises a noise processing module and a feature extraction module, and the training data set is utilized to train the noise processing module and the feature extraction module to obtain the defect image generation model for outputting defect images; the target defect image is obtained through processing of the defect image generation model for subsequent training of the defect detection model, a large amount of defect data is provided for scenes such as the defect detection model, the problem that current defect sample data is less is solved, and then the accuracy of the defect detection model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a defect image generation method, a model training method, a device, a medium and a product. Background Art

[0002] In industrial defect detection, the training of detection models often requires a large number of samples containing defects. However, due to the improvement of production technology, the number of defect samples in production has gradually decreased, which makes it difficult to obtain defect samples on a large scale, resulting in many problems in the collection of defect samples.

[0003] In view of this, how to generate defect samples efficiently and accurately has become an important problem to be solved. Summary of the invention

[0004] In view of this, the purpose of the present disclosure is to propose a defect image generation method, model training method, device, medium and product to solve or partially solve the above-mentioned problems.

[0005] Based on the above purpose, the first aspect of the present disclosure provides a defect image generation method, the method comprising:

[0006] Acquire a target image, a target mask image, and a target defect type, wherein the target image is a defect-free image;

[0007] The target image, the target mask image and the target defect type are input into a pre-trained defect image generation model; wherein the defect image generation model comprises a noise processing module and a feature extraction module, and the noise processing module and the feature extraction module are trained respectively using a training data set to obtain a defect image generation model that outputs a defect image;

[0008] The target defect image is obtained by processing the defect image generation model.

[0009] A second aspect of the present disclosure provides a model training method for training a defect image generation model in the above-mentioned defect image generation method, wherein the initial defect image generation model includes a noise processing module and a feature extraction module, and the method includes:

[0010] Obtain training defect images, training mask images and training defect types, and construct a training data set;

[0011] Acquire preset noise, and use the preset noise to perform noise addition processing on the data in the training data set to obtain a noisy image;

[0012] Inputting the noisy image into a noise processing module to obtain predicted noise;

[0013] Training the noise processing module based on the predicted noise and the preset noise until the training of the noise processing module is completed;

[0014] De-noising the noisy image using the predicted noise to obtain a de-noised image;

[0015] The feature extraction module is trained based on the denoised image until the feature extraction module training is completed, thereby obtaining a defect image generation model.

[0016] Based on the same inventive concept, the third aspect of the present disclosure proposes a defect image generating device, comprising:

[0017] A data acquisition module is configured to acquire a target image, a target mask image, and a target defect type, wherein the target image is a defect-free image;

[0018] An input module is configured to input the target image, the target mask image and the target defect type into a pre-trained defect image generation model; wherein the defect image generation model includes a noise processing module and a feature extraction module, and the noise processing module and the feature extraction module are trained respectively using a training data set to obtain a defect image generation model that outputs a defect image;

[0019] The processing module is configured to obtain a target defect image through processing by the defect image generation model.

[0020] Based on the same inventive concept, the fourth aspect of the present disclosure proposes a model training device, comprising:

[0021] An acquisition module is configured to acquire a training defect image, a training mask image, and a training defect type to construct a training data set;

[0022] A noise adding module is configured to obtain a preset noise, and use the preset noise to perform noise adding processing on the data in the training data set to obtain a noisy image;

[0023] An input module, configured to input the noisy image into a noise processing module to obtain predicted noise;

[0024] A first training module is configured to train the noise processing module based on the predicted noise and the preset noise until the training of the noise processing module is completed;

[0025] a denoising module, configured to perform denoising processing on the noisy image using the predicted noise to obtain a denoised image;

[0026] The second training module is configured to train the feature extraction module based on the denoised image until the feature extraction module is trained to obtain a defect image generation model.

[0027] Based on the same inventive concept, the fifth aspect of the present disclosure proposes an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein the processor implements the method as described above when executing the computer program.

[0028] Based on the same inventive concept, the sixth aspect of the present disclosure proposes a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a computer to execute the method as described above.

[0029] Based on the same inventive concept, a seventh aspect of the present disclosure provides a computer program product, including computer program instructions, which, when executed on a computer, enable the computer to execute the method described above.

[0030] From the above, it can be seen that the present disclosure proposes a defect image generation method, a model training method, a device, a medium and a product, wherein a target image, a target mask image and a target defect type are input into a trained defect image generation model, wherein the defect image generation model is a pre-trained model of an output defect image, and the target defect image is generated by the defect image generation model for subsequent training of a defect detection model, thereby providing a large amount of defect data for scenarios such as defect detection models, solving the problem of less defect sample data in the current situation, and thereby improving the accuracy of the defect detection model. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] In order to more clearly illustrate the technical solutions in the present disclosure or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0032] Figure 1 is a flow chart of a defect image generating method according to an embodiment of the present disclosure;

[0033] Figure 2 A flowchart of a model training method according to an embodiment of the present disclosure;

[0034] Figure 3 It is a structural schematic diagram of an initial defect image generation model according to an embodiment of the present disclosure;

[0035] Figure 4It is a structural schematic diagram of another initial defect image generation model according to an embodiment of the present disclosure;

[0036] Figure 5 is a structural block diagram of a defect image generating device according to an embodiment of the present disclosure;

[0037] Figure 6 is a structural block diagram of a model training device according to an embodiment of the present disclosure;

[0038] Figure 7 It is a schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0039] In order to make the objectives, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.

[0040] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the embodiments of the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. "Including" or "comprising" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0041] The terms used in this disclosure are explained as follows:

[0042] GAN: Generative Adversarial Networks (GAN) consists of a generative model and a discriminative model. The generative model is responsible for capturing the distribution of sample data, while the discriminative model is generally a binary classifier that determines whether the input is real data or a generated sample.

[0043] VGG: The VGG network is a very classic convolutional neural network (CNN) architecture in the field of deep learning.

[0044] DDPM: DDPM (Denoising Diffusion Probabilistic Models) diffusion model is a probabilistic model based on Gaussian noise, which can be used to denoise and generate images with arbitrary distribution.

[0045] LoRA: Low-Rank Adaptation of Large Language Models, is a low-rank adaptation technique for fine-tuning large language models.

[0046] Since scenes such as industrial defect detection and segmentation require the training of corresponding models, model training often requires a large number of samples containing defects. However, due to the improvement of production technology, the number of defect samples in production is gradually decreasing, and the types of defects are uncertain. If defect sample images are produced, it is difficult to cover all unknown defects, and expensive manpower and financial resources are required. Defect samples are obtained by artificially destroying samples, and then defect sample images are obtained for algorithm research. The defect diversity obtained is insufficient and the cost is high. In summary, defect samples are generally difficult to obtain on a large scale, which makes the collection of defect samples have many problems.

[0047] At present, most defect generation methods are based on GAN technology, but the GAN model has the problem of unstable training. With the advancement of large model technology, large model technology has begun to be used to solve the problem of defect data generation. However, defect data is generally difficult to obtain on a large scale, and large model parameters are huge and rely on a large amount of data training, which limits the application of large model technology.

[0048] Based on the above description, this embodiment proposes a defect image generation method, such as Figure 1 As shown, the method includes:

[0049] Step 101 : acquiring a target image, a target mask image and a target defect type, wherein the target image is a defect-free image.

[0050] Step 102, input the target image, the target mask image and the target defect type into a pre-trained defect image generation model; wherein the defect image generation model includes a noise processing module and a feature extraction module, and the noise processing module and the feature extraction module are trained respectively using a training data set to obtain a defect image generation model that outputs a defect image.

[0051] Step 103: obtaining a target defect image through processing by the defect image generation model.

[0052] In specific implementation, when generating a defect image, first obtain a target image, a target mask image (mask image) and a target defect type, wherein the target image is a defect-free image, i.e., a good product image. Defect types include screen defects, building material defects, etc., such as scratches, black spots, etc.

[0053] The mask image is a selected image, graphic or object that blocks the processed image (whole or part) to control the image processing area or processing process. The mask can be used to shield certain areas on the image so that they do not participate in the processing or the calculation of processing parameters, or only the shielded area is processed or counted.

[0054] The initial defect image generation model is pre-trained using the training data set until a pre-set training end condition is met to obtain the defect image generation model.

[0055] Specifically, the initial defect image generation model includes a noise processing module and a feature extraction module. The noise processing module is used to perform noise addition and denoising on the data in the training data set. The predicted noise obtained by the noise processing module and the noise added during actual noise addition are used for supervised learning to achieve training of the noise processing module.

[0056] The feature extraction module is used to separate different types of defects from a group of sample images, and combines the sample contrast loss to supervise the defect image generation model so that the defect type of the generated defect image is consistent with the target defect type.

[0057] The target image, the target mask image and the target defect type are input into the defect image generation model, and the defect image generation model is used to process them to output a target defect image, wherein the target defect image is an image containing defects of the target defect type.

[0058] Through the above scheme, the target image, target mask image and target defect type are input into the trained defect image generation model. The defect image generation model is a model of output defect image obtained by pre-training. The target defect image is generated by the defect image generation model for subsequent training of the defect detection model, which provides a large amount of defect data for scenarios such as the defect detection model, solves the problem of less defect sample data in the current situation, and thereby improves the accuracy of the defect detection model.

[0059] In some embodiments, step 103 specifically includes:

[0060] Step 1031 , performing a noise adding process for a first preset number of steps on the target image based on the target defect type to obtain a first noise image.

[0061] Step 1032: denoising the first noise image based on the target mask image until the number of denoising steps meets a first preset number of steps to obtain a target defect image.

[0062] In specific implementation, a preset number of noise steps (i.e., a first preset number of steps) is obtained, and forward noise processing is performed on the target image based on the target defect type, that is, Gaussian noise is added to the target image (good product image), wherein the Gaussian noise is a preset added noise value. The number of noise adding steps is the first preset number of steps, and the first noise image is obtained after the noise adding is completed, and the first noise image is essentially a random noise matrix.

[0063] In order to ensure that the image area of ​​the target defect image except the mask corresponding to the target mask image does not change, during denoising, step-by-step denoising is performed based on the target mask image, that is, the part that does not need to be reconstructed is replaced by the part corresponding to the good image, and features are reconstructed only in the part corresponding to the mask.

[0064] In the denoising process, the noise used in the denoising process is the noise predicted by the defect image generation model. The denoising is performed until the number of denoising steps reaches the first preset number, which means that the denoising is completed and the target defect image can be obtained.

[0065] In some embodiments, step 1032 specifically includes:

[0066] For each denoising process:

[0067] Step 10321, performing a denoising process on the first noise image to obtain a second noise image.

[0068] Step 10322: Based on the target defect type, the target image is subjected to noise adding processing for a second preset number of steps to obtain a third noisy image, wherein the second preset number of steps is smaller than the first preset number of steps.

[0069] Step 10323, combining the target mask image, the second noise image and the third noise image to obtain a defect image.

[0070] In specific implementation, in each denoising process, predicted noise is obtained, and firstly, a denoising process is performed on the first noise image based on the predicted noise to obtain a second noise image, and the second noise image differs from the first noise image by one predicted noise.

[0071] The target image is directly subjected to noise processing based on the target defect type to obtain a third noise image. The number of noise adding steps is a second preset number of steps, and the second preset number of steps is less than the first preset number of steps. In this embodiment, the difference between the second preset number of steps and the first preset number of steps is preferably one step.

[0072] The second noise image and the third noise image are combined based on the target mask image. In the target mask image, the area with a mask value of 1 indicates retention, and the area with a mask value of 0 indicates an area that needs to be replaced, that is, a part that needs to be reconstructed.

[0073] For example, the target image is Z a , the first preset step number is 20, the target mask image is mask, and the area where the mask value is 1 is retained.

[0074] Add noise to the target image for 20 steps to obtain the first noise image Z 20 The first noise image is subjected to a one-step denoising process to obtain a second noise image Z 19 Directly add noise to the target image for 19 steps to obtain the third noise image z′ 19 .

[0075] Combined with the target mask image mask, Z 19 and z′ 19 The specific combination method is expressed by the formula mask*z′ 19 +(1-mask)*Z 19 , and the obtained defect image is used as the noise image corresponding to step 19.

[0076] De-noise the noisy image corresponding to step 19 again to obtain Z 18 Directly add noise to the target image for 18 steps to obtain the third noise image z′ 18 .

[0077] Combined with the target mask image mask, Z 18 and z′ 18 The specific combination method is expressed by the formula mask*z′ 18 +(1-mask)*Z 18 , and the obtained defect image is used as the noise image corresponding to step 18.

[0078] Repeat the above steps until the final target defect image Z is obtained. 0 , output the target defect image.

[0079] Through the above scheme, by combining the second noise image and the third noise image based on the target mask image, the area outside the mask part is not denoised by the predicted noise of the defect image generation model, but is directly denoised by using the preset added noise value. In other words, the area outside the mask part is directly replaced by the good image with noise, without using the predicted noise of the defect image generation model, and the area corresponding to the mask part uses the predicted noise of the defect image generation model, so that in the generated target defect image, the area outside the mask part is a good image, and the area corresponding to the mask part is a reconstructed image, so that the target defect image obtained is more accurate.

[0080] Another embodiment of the present disclosure provides a model training method, the method flow is as follows: Figure 2 As shown, it is used to train the defect image generation model in the above embodiment, such as Figure 3 As shown, Figure 3 A structural schematic diagram of an initial defect image generation model is shown, wherein the initial defect image generation model includes a noise processing module and a feature extraction module, and the method includes:

[0081] Step 201 : Acquire training defect images, training mask images and training defect types to construct a training data set.

[0082] In a specific implementation, before training the initial defect image generation model, a training data set is first determined. A training defect image, a training mask image corresponding to the training defect image, and a training defect type corresponding to the training defect image are obtained, wherein the training defect image is an image containing defects, the training mask image is a mask image with the same defect position as that in the training defect image, and the training defect type is the same as the defect type of the defect in the training defect image.

[0083] A training data set is constructed based on the acquired training defect images, training mask images, and training defect types. The training data set may also include good product images, so that the good product images can be processed during training to obtain defect images output by the model, and then the defect images output by the model are compared with the training defect images to determine the degree of model training.

[0084] Step 202: Obtain preset noise, and use the preset noise to perform noise addition processing on the data in the training data set to obtain a noisy image.

[0085] In a specific implementation, a preset noise is obtained, and a forward noise addition process is performed based on the preset noise. In the forward noise addition process, the model continues to add the preset noise to the good product image until it becomes a random noise matrix, and the random noise matrix is ​​the noisy image.

[0086] Step 203: input the noisy image into a noise processing module to obtain predicted noise.

[0087] In a specific implementation, the noisy image is back-diffused, the noisy image is input into a noise processing module, and the noise processing module performs noise prediction on the noisy image to obtain predicted noise corresponding to the noisy image.

[0088] Step 204: training the noise processing module based on the predicted noise and the preset noise until the noise processing module training is completed.

[0089] In a specific implementation, a first training data set is constructed based on the predicted noise output by the noise processing module and the preset noise actually added, and the noise processing module is trained using the first training data set until a preset first training end condition is met, and it is determined that the training of the noise processing module is completed. At this time, the noise processing module can accurately predict the real noise actually added each time.

[0090] The first training end condition includes at least one of the following: determining that all data in the first training data set is input into the noise processing module for training, determining that the loss value of the noise processing module is less than or equal to a preset loss threshold, or determining that the noise processing module is iteratively trained to a first preset number of iterations.

[0091] Exemplarily, the first training end condition is to determine that the loss value of the noise processing module is less than or equal to a preset loss threshold:

[0092] A first loss value is determined according to the predicted noise and the preset noise. The type of the first loss value includes at least one of the following: a mean square error loss value, a cross entropy loss value, a logarithmic loss value, an exponential loss value, a square loss value, or an absolute value loss value, etc. When the first loss value is less than or equal to a preset loss threshold, it is determined that the first training end condition is met.

[0093] In another example, the first training end condition is to determine that all the data in the first training data set are input into the noise processing module for training:

[0094] There are ten groups of data in the first training data set, each group of data includes preset noise and predicted noise. The first training end condition is to determine that all data in the first training data set are input into the noise processing module for training, that is, when the ten groups of data are input into the noise processing module, there is no data in the first training data set that has not been input into the noise processing module, and it is determined that the noise processing module training ends.

[0095] In another example, the first preset training end condition is to determine that the noise processing module is iteratively trained to a first preset number of iterations.

[0096] The data in the first training data set is input into the noise processing module for iterative training, the number of iterations is recorded, and when it is determined that the number of iterations is equal to the first preset number of iterations, the first training end condition is met.

[0097] Step 205: De-noising the noisy image using the predicted noise to obtain a de-noised image.

[0098] In a specific implementation, the predicted noise output by the noise processing module is used to perform denoising on the noisy image to obtain a denoised image.

[0099] When the noisy image is a noisy image obtained by adding a preset number of steps of noise, and the preset number of steps is multiple steps, when denoising, the noisy image with the preset number of steps of noise is first input into the noise processing module, and the predicted noise corresponding to the noisy image with the preset number of steps is output. The noisy image with the preset number of steps of noise is denoised by one step using the predicted noise corresponding to the noisy image with the preset number of steps, to obtain a first initial denoised image, wherein the first initial denoised image is a noise image with the preset number of steps minus one step.

[0100] The first initial denoised image is input into a noise processing module, and the predicted noise corresponding to the first initial denoised image is output. The first initial denoised image is denoised by one step using the predicted noise corresponding to the first initial denoised image to obtain a second initial denoised image, wherein the second initial denoised image is a noise image with two steps added to it.

[0101] Repeat the above steps until a clear image with complete denoising is obtained, which is the denoised image.

[0102] For example, the preset number of steps is 1000, and the noisy image x with 1000 steps of noise added is 1000 Input to the noise processing module, output x 1000 The corresponding prediction noise. 1000 Subtracting the predicted noise, we get a slightly sharper image x 999 . Then x 999 Input to the noise processing module, output x 999 The corresponding prediction noise. 999 Subtracting the predicted noise, we get a slightly sharper image x 998 Repeat the above process until a clear image with complete denoising is obtained.

[0103] Step 206: training the feature extraction module based on the denoised image until the feature extraction module is trained to obtain a defect image generation model.

[0104] In a specific implementation, a second training set is constructed based on the training defect image and the denoised image, and the feature extraction module is trained using the second training set until the preset second training end condition is met, and the feature extraction module training is determined to be completed, and a defect image generation model is obtained. At this time, the defect image generation model can generate a corresponding defect image according to the target defect type and the target mask image.

[0105] The second training end condition includes at least one of the following: determining that all data in the second training data set is input into the feature extraction module for training, determining that the loss value of the feature extraction module is less than or equal to a preset loss threshold, or determining that the feature extraction module is iteratively trained to a second preset number of iterations.

[0106] Exemplarily, the second training end condition is to determine that all the data in the second training data set are input into the feature extraction module for training:

[0107] There are ten groups of data in the second training data set, each group of data includes a training defect image and a denoised image. The second training end condition is to determine that all data in the second training data set are input into the feature extraction module for training, that is, when all ten groups of data are input into the feature extraction module, there is no data in the second training data set that has not been input into the feature extraction module, and it is determined that the feature extraction module training is ended.

[0108] In another example, the second training end condition is to determine that the loss value of the feature extraction module is less than or equal to a preset loss threshold:

[0109] A second loss value is determined according to the predicted noise and the preset noise. The type of the second loss value includes at least one of the following: a mean square error loss value, a cross entropy loss value, a logarithmic loss value, an exponential loss value, a square loss value, or an absolute value loss value, etc. When the second loss value is less than or equal to a preset loss threshold, it is determined that the second training end condition is met.

[0110] In another example, the second preset training end condition is to determine that the feature extraction module is iteratively trained to a second preset number of iterations.

[0111] The data in the second training data set is input into the feature extraction module for iterative training, the number of iterations is recorded, and when it is determined that the number of iterations is equal to the second preset number of iterations, the second training end condition is met.

[0112] Through the above scheme, by training the noise processing module in the initial defect image generation model, the noise processing module can accurately predict the real noise actually added each time, thereby enabling the initial defect image generation model to have the ability to generate defect images. At the same time, adding a feature extraction module to the initial defect image generation model can enhance the generation effect of the model when the amount of data is small and improve the accuracy of the defect image generated by the model.

[0113] In some embodiments, step 204 specifically includes:

[0114] Step 2041: train the noise processing module using the predicted noise and the preset noise to determine a first loss.

[0115] Step 2042: In response to the first loss being less than or equal to a first loss threshold, determining that the noise processing module training is completed.

[0116] In specific implementation, in this embodiment, the first preset training end condition is preferably to determine that the loss value of the noise processing module is less than or equal to the preset loss threshold, that is, the noise processing module is trained using the predicted noise and the preset noise to determine the first loss corresponding to the noise processing module.

[0117] The noise processing module is continuously trained until the first loss is less than or equal to the first loss threshold, which indicates that the noise processing module training is completed.

[0118] In some embodiments, step 2041 specifically includes:

[0119] Step 20411: determine a first sub-loss according to the preset noise and the predicted noise.

[0120] In a specific implementation, the preset noise actually input and the predicted noise output by the noise processing module are input into a preset first loss function, wherein the first loss function includes at least one of the following: a mean square error loss function, a cross entropy loss function, a logarithmic loss function, an exponential loss value function, a square loss function or an absolute value loss function.

[0121] In this embodiment, the first loss function is preferably a mean square error loss function. The mean square error loss function is a quadratic loss function or an L2 loss function, which measures the quality of the model by calculating the square of the distance (i.e., error) between the predicted value and the actual value. That is, the closer the predicted value is to the actual value, the smaller the mean square error between the two.

[0122] A preset mean square error loss function is obtained, and the square value of the error between the preset noise and the predicted noise is calculated, and the calculation result is the first sub-loss.

[0123] Step 20412: denoise the noisy image using the predicted noise to obtain a denoised image.

[0124] In a specific implementation, the predicted noise output by the noise processing module is used to perform denoising on the noisy image to obtain a denoised image, wherein the denoised image is a clear image that is completely denoised.

[0125] Step 20413: determine a second sub-loss based on the training defect image and the denoised image.

[0126] During specific implementation, a preset second loss function is obtained, wherein the second loss function includes at least one of the following: a mean square error loss function, a cross entropy loss function, a logarithmic loss function, an exponential loss value function, a square loss function, or a mean absolute error loss function.

[0127] The second sub-loss between the training defect image and the denoised image is calculated using the second loss function, wherein the training defect image is the correct target defect image, and the denoised image is an image containing defects output after passing through the noise processing module.

[0128] In this embodiment, the second loss function is preferably a mean absolute error loss function, which is an L1 loss function and calculates the absolute difference between the predicted value and the true value.

[0129] A preset mean absolute value error loss function is obtained, and the absolute difference between the training defect image and the denoised image is calculated, and the calculation result is the second sub-loss.

[0130] Step 20414: determine a first loss based on the first sub-loss and the second sub-loss.

[0131] In a specific implementation, the first loss of the noise processing module is calculated according to the first sub-loss and the second sub-loss, and the first loss is expressed by the formula:

[0132] L 1 =L mse +0.01*L pec

[0133] Among them, L 1 is the first loss, L mse is the first sub-loss, L pec Loss for the second child.

[0134] In some embodiments, step 206 specifically includes:

[0135] Step 2061, using the denoised image to train the feature extraction module to determine the second loss.

[0136] Step 2062, in response to the second loss being less than or equal to a second loss threshold, determining that the feature extraction module training is completed, and obtaining a defect image generation model.

[0137] In specific implementation, in this embodiment, the second preset training end condition is preferably to determine that the loss value of the feature extraction module is less than or equal to the preset loss threshold, that is, the feature extraction module is trained using the denoised image and the training defect image to determine the second loss corresponding to the feature extraction module.

[0138] The feature extraction module is continuously trained until the second loss is less than or equal to the second loss threshold, which indicates that the feature extraction module training is completed.

[0139] In some embodiments, step 2061 specifically includes:

[0140] Step 20611: Use the feature extraction module to extract features from the denoised image, and determine the third sub-loss according to the extracted feature values.

[0141] Step 20612, determining a second loss based on the first sub-loss, the second sub-loss and the third sub-loss.

[0142] In the specific implementation, the feature extraction module is used to extract features of the denoised image to obtain feature values, which include feature values ​​corresponding to positive samples related to the training defect image, feature values ​​corresponding to negative samples related to the training defect image, and feature values ​​corresponding to the denoised image.

[0143] The third sub-loss is calculated according to the extracted eigenvalues, and the third sub-loss is combined with the first sub-loss and the second sub-loss in the vector space to obtain the second loss, wherein the second loss is expressed by the formula:

[0144] L 2 =L mse +0.01*L pec +0.01*L con

[0145] Among them, L 2 is the second loss, L con Loss for the third child.

[0146] In some embodiments, step 20611 specifically includes:

[0147] Step 206111, input the denoised image into the feature extraction module to obtain a first eigenvalue.

[0148] Step 206112: perform enhancement processing on the training defect image to obtain an enhanced defect image.

[0149] Step 206113, input the enhanced defect image into the feature extraction module to obtain a second eigenvalue.

[0150] Step 206114: select a sample defect image, input the sample defect image into the feature extraction module, and obtain a third feature value, wherein the training defect type of the sample defect image is different from that of the training defect image.

[0151] Step 206115, calculating a third sub-loss based on the first eigenvalue, the second eigenvalue and the third eigenvalue.

[0152] In a specific implementation, the denoised image is first input into a feature extraction module, and processed by the feature extraction module to output a first feature value corresponding to the denoised image. Data enhancement is performed on the training defect image to obtain a positive sample related to the training defect image and an enhanced defect image, wherein the data enhancement method includes at least one of the following: random rotation, scaling, and rotation plus scaling.

[0153] The enhanced defect image is input to a feature extraction module, and is processed by the feature extraction module to output a second feature value, wherein the second feature value is a feature value corresponding to a positive sample related to the training defect image.

[0154] According to the training defect type of the training defect image, a defect image corresponding to a defect type different from the training defect type is selected as a sample defect image, wherein the number of the sample defect images may be one or more. Meanwhile, when the number of the sample defect images is multiple, the defect types of different sample defect images may be the same or different.

[0155] The sample defect image is input into the feature extraction module, and a third feature value is output, wherein the third feature value is a feature value corresponding to a negative sample related to the training defect image.

[0156] A third sub-loss is calculated based on the first eigenvalue, the second eigenvalue, and the third eigenvalue, wherein the third sub-loss is expressed by the formula:

[0157]

[0158] Among them, L con is the third sub-loss, N is the N-layer output feature of the feature extraction module, l is the l-th layer, and v o is the first eigenvalue, v p is the second eigenvalue, v n is the third eigenvalue, τ is a hyperparameter, which is set to an empirical value of 0.07, and i is the i-th sample defect image.

[0159] In some embodiments, the feature extraction module includes a perception network, an average pooling layer, and a maximum pooling layer, and step 206111 specifically includes:

[0160] Step 2061111, input the denoised image into the perception network, process it through the perception network and output the initial eigenvalue.

[0161] Step 2061112, input the initial eigenvalue to the average pooling layer for processing to obtain the first sub-eigenvalue.

[0162] Step 2061113, input the initial eigenvalue into the maximum pooling layer for processing to obtain the second sub-eigenvalue.

[0163] Step 2061114: determine a first eigenvalue based on the first sub-eigenvalue and the second sub-eigenvalue.

[0164] In specific implementation, in this embodiment, the feature extraction module includes a perception network, an average pooling layer and a maximum pooling layer. The perception network is preferably a VGG network, through which global information and local information are captured.

[0165] Pooling is used to reduce the size of the feature extraction module, thereby reducing the amount of calculation, reducing the complexity of the feature extraction module and improving the robustness of the feature extraction module. The maximum pooling layer retains the most significant features by selecting the maximum value in the local area as the output value. The average pooling layer takes the average value of the values ​​in the local area as the output value to obtain the average representation of the overall features.

[0166] The perceptual network is used to output the initial eigenvalue, which is input into the average pooling layer and the maximum pooling layer respectively, and the first sub-eigenvalue is output through the average pooling layer, and the second sub-eigenvalue is output through the maximum pooling layer. The first sub-eigenvalue and the second sub-eigenvalue are connected in the channel dimension to obtain the initial first eigenvalue.

[0167] The feature extraction module also includes at least one fully connected layer, and the initial first eigenvalue is passed through at least one fully connected layer to obtain the first eigenvalue.

[0168] Through the above scheme, the initial feature value output by the perception network is passed through the average pooling layer, so that the image in the pooling area is averaged, so that the obtained feature information is more sensitive to background information, such as helping classification. The initial feature value output by the perception network is passed through the maximum pooling layer, and the pixel points in the pooling area are maximized, and the obtained feature map is more sensitive to texture feature information.

[0169] In some embodiments, step 206113 specifically includes:

[0170] The enhanced defect image is input into the feature extraction module, and the perception network is used to output the first initial eigenvalue. The first initial eigenvalue is input into the average pooling layer and the maximum pooling layer respectively. The third sub-eigenvalue is output through the average pooling layer, and the fourth sub-eigenvalue is output through the maximum pooling layer.

[0171] The third sub-eigenvalue and the fourth sub-eigenvalue are connected in the channel dimension to obtain an initial second eigenvalue. The feature extraction module also includes at least one fully connected layer, and the initial second eigenvalue is passed through at least one fully connected layer to obtain a second eigenvalue.

[0172] In some embodiments, step 206114 specifically includes:

[0173] The sample defect image is input into the feature extraction module, and the perception network is used to output the second initial eigenvalue. The second initial eigenvalue is input into the average pooling layer and the maximum pooling layer respectively. The fifth sub-eigenvalue is output through the average pooling layer, and the sixth sub-eigenvalue is output through the maximum pooling layer.

[0174] The fifth sub-eigenvalue and the sixth sub-eigenvalue are connected in the channel dimension to obtain an initial third eigenvalue. The feature extraction module also includes at least one fully connected layer, and the initial third eigenvalue is passed through at least one fully connected layer to obtain a third eigenvalue.

[0175] In some embodiments, the number of the sample defect images is multiple, and step 206115 specifically includes:

[0176] Step 2061151: for each sample defect image, based on the first eigenvalue, the second eigenvalue and the third eigenvalue corresponding to the sample defect image, calculate the loss value corresponding to the sample defect image.

[0177] Step 2061152, summing up the loss values ​​corresponding to all sample defect images to obtain the third sub-loss.

[0178] In specific implementation, when the number of sample defect images is multiple, for each sample defect image, the loss value corresponding to the sample defect image is calculated based on the first eigenvalue, the second eigenvalue and the third eigenvalue corresponding to the sample defect image, and the calculation method is the same as the calculation method of the third sub-loss in the above step.

[0179] After calculating the loss values ​​corresponding to all sample defect images, the loss values ​​corresponding to all sample defect images are added together to obtain the third sub-loss.

[0180] Exemplarily, there are two sample defect images, namely image A and image B. Image A is input into the feature extraction module to obtain the third eigenvalue corresponding to image A, and the loss value corresponding to image A is calculated based on the first eigenvalue, the second eigenvalue and the third eigenvalue corresponding to image A.

[0181] Image B is input into the feature extraction module to obtain a third eigenvalue corresponding to image B, and a loss value corresponding to image B is calculated based on the first eigenvalue, the second eigenvalue and the third eigenvalue corresponding to image B.

[0182] The loss value corresponding to the image A and the loss value corresponding to the image B are added together, and the sum obtained is the third sub-loss.

[0183] Due to the huge number of parameters in current large models and the high training cost, it is not cost-effective to train all parameters of large models when encountering downstream tasks, especially for scenarios such as defect generation. For some types of defects, the probability of their occurrence is very small and it is very difficult to obtain them, which makes it unrealistic to obtain a large number of training images.

[0184] Therefore, if Figure 4 As shown, Figure 4 A structural schematic diagram of another initial defect image generation model in this embodiment is shown, and the initial defect image generation model also includes a low-rank processing module. The low-rank processing module can act on the self-attention layer network of the noise processing module in the defect image generation model, and can also act on the cross-attention layer network of the noise processing module.

[0185] When the low-rank processing module acts on the self-attention layer network, the target image and the target mask image can be combined and input into the noise processing module. When the low-rank processing module acts on the cross-attention layer, the target mask image is input into the noise processing module from the cross-attention layer.

[0186] Furthermore, in some embodiments, the method further comprises:

[0187] Step 20A, in response to receiving a new training data set, determining whether a new training defect type corresponding to the new training data set exists in the training defect types corresponding to the defect image generation model that have been trained.

[0188] Step 20B: in response to the absence of the new training defect type, updating the model parameters of the defect image generation model to obtain a new initial defect image generation model.

[0189] Step 20C: input the new training data set into a low-rank processing module, and use the low-rank processing module to split the parameter matrix corresponding to the new training data set into multiple sub-data matrices for multiplication.

[0190] Step 20D, training the new initial defect image generation model by multiplying multiple sub-data matrices until the low-rank processing module is trained to obtain a new defect image generation model.

[0191] In specific implementation, when a new training data set is received, a new training defect type corresponding to the new training data set is determined, the trained training defect type corresponding to the defect image generation model is obtained, and it is determined whether the trained training defect type includes the new defect type.

[0192] If the training defect types that have been trained include the new defect type, it means that the training defect types that have been trained are continued to be trained using the new training data set. The noise processing module and the feature extraction module in the defect image generation model are trained using the new training data set. The specific training process is as described in the above embodiment and will not be repeated here.

[0193] If the training defect types that have been trained do not include the new defect type, in order to avoid fine-tuning all parameters of the overall model, the original weights of the defect image generation model are frozen, and the model parameters of the defect image generation model are updated using the parameters of the low-rank processing module. The specific process is expressed by the formula:

[0194] W′=W O +ΔW

[0195] Where W′ is the model parameter of the updated defect image generation model, W O are the model parameters of the defect image generation model, and ΔW are the parameters of the low-rank processing module.

[0196] The low-rank processing module includes two low-rank matrices. The new training data set is input into the low-rank processing module for processing. The parameter matrix corresponding to the new training data set is split by the low-rank processing module into a form of multiplication of multiple sub-data matrices. In this embodiment, the number of sub-data matrices is preferably two.

[0197] For example, the parameter matrix of the new training data set is 100*1024, and the corresponding parameter amount is 102400. It is split by the low-rank processing module into two matrix multiplications. Set the matrix rank Rank = 8, then split the original parameter matrix into a 100*8 B matrix and an 8*1024 A matrix for matrix multiplication, and the corresponding parameter amount becomes 800+8192=8992, which is about 11.39 times lower than the parameter amount before splitting.

[0198] Correspondingly, if the low-rank processing module includes two low-rank matrices A and B, the parameters of the corresponding low-rank processing module are expressed by the formula:

[0199] ΔW=AB T

[0200] in, d<<n, d is the rank of ΔW, and m and n are the parameters of the split parameter matrix.

[0201] The new initial defect image generation model is trained using the parameters in the form of multiplication of the multiple sub-data matrices obtained after the splitting, until the preset third training end condition is met, and it is determined that the training of the low-rank processing module is completed to obtain a new defect image generation model.

[0202] The third training end condition includes at least one of the following: determining that all data in the third training data set are input into the defect image generation model for training, determining that the loss value of the defect image generation model is less than or equal to a preset loss threshold, or determining that the defect image generation model is iteratively trained to a third preset number of iterations.

[0203] Exemplarily, the third training end condition is to determine that the loss value of the defect image generation model is less than or equal to a preset loss threshold:

[0204] A third loss value is determined according to the predicted noise and the preset noise. The type of the third loss value includes at least one of the following: a mean square error loss value, a cross entropy loss value, a logarithmic loss value, an exponential loss value, a square loss value, or an absolute value loss value, etc. When the third loss value is less than or equal to a preset loss threshold, it is determined that the third training end condition is met, and a new defect image generation model is obtained.

[0205] In another example, the third training end condition is to determine that all the data in the third training data set are input into the defect image generation model for training:

[0206] There are ten groups of data in the third training data set, and each group of data includes parameters in the form of multiplication of multiple sub-data matrices obtained after splitting. The third training end condition is to determine that all data in the third training data set are input into the defect image generation model for training, that is, when all ten groups of data are input into the defect image generation model, there is no data in the third training data set that has not been input into the defect image generation model, and it is determined that the training of the defect image generation model is completed, and a new defect image generation model is obtained.

[0207] In another example, the third preset training end condition is to determine that the defect image generation model is iteratively trained to a third preset number of iterations.

[0208] The data in the third training data set is input into the defect image generation model for iterative training, the number of iterations is recorded, and when it is determined that the number of iterations is equal to the third preset number of iterations, the third training end condition is met, and a new defect image generation model is obtained.

[0209] Through the above solution, after the defect image generation model is trained, if there is a training data set input for a defect type that the model has not been trained on, the LoRA module can be directly trained to avoid fine-tuning the defect image generation model that causes excessive training costs. At the same time, it can also enhance the generalization of the overall defect image generation model to new scenarios.

[0210] It should be noted that the method of the embodiment of the present disclosure can be performed by a single device, such as a computer or a server. The method of the present embodiment can also be applied in a distributed scenario and completed by multiple devices cooperating with each other. In the case of such a distributed scenario, one of the multiple devices can only perform one or more steps in the method of the embodiment of the present disclosure, and the multiple devices will interact with each other to complete the described method.

[0211] It should be noted that the above describes some embodiments of the present disclosure. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the above embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0212] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a defect image generating device.

[0213] refer to Figure 5 , Figure 5 The defect image generating device of the embodiment comprises:

[0214] The data acquisition module 501 is configured to acquire a target image, a target mask image and a target defect type, wherein the target image is a defect-free image;

[0215] The input module 502 is configured to input the target image, the target mask image and the target defect type into a pre-trained defect image generation model; wherein the defect image generation model includes a noise processing module and a feature extraction module, and the noise processing module and the feature extraction module are trained respectively using the training data set to obtain a defect image generation model that outputs a defect image;

[0216] The processing module 503 is configured to obtain a target defect image through processing by the defect image generation model.

[0217] In some embodiments, the processing module 503 specifically includes:

[0218] A noise processing module is configured to perform a noise processing of a first preset number of steps on the target image based on the target defect type to obtain a first noise image;

[0219] The denoising processing module is configured to perform denoising on the first noise image based on the target mask image until the number of denoising steps meets a first preset number of steps to obtain a target defect image.

[0220] In some embodiments, the denoising processing module is specifically configured to:

[0221] For each denoising process:

[0222] Performing a one-step denoising process on the first noisy image to obtain a second noisy image;

[0223] Performing noise adding processing on the target image for a second preset number of steps based on the target defect type to obtain a third noise image, wherein the second preset number of steps is less than the first preset number of steps;

[0224] The target mask image, the second noise image and the third noise image are combined to obtain a defect image.

[0225] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a model training device.

[0226] refer to Figure 6 , Figure 6 The model training device of the embodiment includes:

[0227] An acquisition module 601 is configured to acquire a training defect image, a training mask image and a training defect type, and construct a training data set;

[0228] The noise adding module 602 is configured to obtain a preset noise, and use the preset noise to perform noise adding processing on the data in the training data set to obtain a noisy image;

[0229] An input module 603 is configured to input the noisy image into a noise processing module to obtain predicted noise;

[0230] A first training module 604 is configured to train the noise processing module based on the predicted noise and the preset noise until the noise processing module training is completed;

[0231] A denoising module 605 is configured to perform denoising processing on the noisy image using the predicted noise to obtain a denoised image;

[0232] The second training module 606 is configured to train the feature extraction module based on the denoised image until the feature extraction module is trained and a defect image generation model is obtained.

[0233] In some embodiments, the first training module 604 specifically includes:

[0234] A first loss determining unit is configured to train the noise processing module using the predicted noise and the preset noise to determine a first loss;

[0235] The judgment unit is configured to determine that the training of the noise processing module is completed in response to the first loss being less than or equal to a first loss threshold.

[0236] In some embodiments, the first loss determination unit specifically includes:

[0237] A first sub-loss determination subunit, configured to determine a first sub-loss according to the preset noise and the predicted noise;

[0238] a denoising subunit, configured to perform denoising processing on the noisy image using the predicted noise to obtain a denoised image;

[0239] A second sub-loss determination subunit is configured to determine a second sub-loss according to the training defect image and the denoised image;

[0240] The first loss determining subunit is configured to determine a first loss based on the first sub-loss and the second sub-loss.

[0241] In some embodiments, the first sub-loss determination sub-unit is specifically configured to:

[0242] Get the preset mean square error loss function;

[0243] According to the preset noise and the predicted noise, a first sub-loss is determined based on the mean square error loss function.

[0244] In some embodiments, the second sub-loss determination sub-unit is specifically configured as follows:

[0245] Get the preset mean absolute error loss function;

[0246] According to the training defect image and the denoised image, a second sub-loss is determined based on the mean absolute value error loss function.

[0247] In some embodiments, the second training module 606 specifically includes:

[0248] A second loss determination unit is configured to train the feature extraction module using the denoised image to determine a second loss;

[0249] The judgment unit is configured to determine that the feature extraction module training is completed in response to the second loss being less than or equal to a second loss threshold, and obtain a defect image generation model.

[0250] In some embodiments, the second loss determination unit specifically includes:

[0251] A third sub-loss determination subunit is configured to perform feature extraction on the denoised image using the feature extraction module, and determine a third sub-loss according to the extracted feature values;

[0252] The second loss determining subunit is configured to determine a second loss based on the first sub-loss, the second sub-loss and the third sub-loss.

[0253] In some embodiments, the third sub-loss determination sub-unit is specifically configured as follows:

[0254] Inputting the denoised image into the feature extraction module to obtain a first feature value;

[0255] Performing enhancement processing on the training defect image to obtain an enhanced defect image;

[0256] Inputting the enhanced defect image into the feature extraction module to obtain a second feature value;

[0257] Selecting a sample defect image, and inputting the sample defect image into the feature extraction module to obtain a third feature value, wherein the sample defect image and the training defect image have different training defect types;

[0258] A third sub-loss is calculated based on the first eigenvalue, the second eigenvalue, and the third eigenvalue.

[0259] In some embodiments, the feature extraction module includes a perceptual network, an average pooling layer, and a maximum pooling layer, and the third sub-loss determination subunit is further configured as follows:

[0260] Inputting the denoised image into the perception network, processing the image through the perception network and outputting an initial eigenvalue;

[0261] Inputting the initial eigenvalue into the average pooling layer for processing to obtain a first sub-eigenvalue;

[0262] Inputting the initial eigenvalue into the maximum pooling layer for processing to obtain a second sub-eigenvalue;

[0263] A first eigenvalue is determined based on the first sub-eigenvalue and the second sub-eigenvalue.

[0264] In some embodiments, the third sub-loss determination sub-unit is further configured to:

[0265] For each sample defect image, based on the first eigenvalue, the second eigenvalue and the third eigenvalue corresponding to the sample defect image, calculate a loss value corresponding to the sample defect image;

[0266] The loss values ​​corresponding to all sample defect images are added together to obtain the third sub-loss.

[0267] In some embodiments, the initial defect image generation model further includes a low-rank processing module, and the device further includes a low-rank processing module, and the low-rank processing module is specifically configured as follows:

[0268] In response to receiving a new training data set, determining whether there is a new training defect type corresponding to the new training data set among the training defect types corresponding to the defect image generation model that have been trained;

[0269] In response to the absence of the new training defect type, updating the model parameters of the defect image generation model to obtain a new initial defect image generation model;

[0270] Inputting the new training data set into a low-rank processing module, and using the low-rank processing module to split the parameter matrix corresponding to the new training data set into multiple sub-data matrices for multiplication;

[0271] The new initial defect image generation model is trained by multiplying a plurality of sub-data matrices until the low-rank processing module is trained to obtain a new defect image generation model.

[0272] For the convenience of description, the above device is described by dividing it into various modules according to its functions. Of course, when implementing the present disclosure, the functions of each module can be implemented in the same or multiple software and / or hardware.

[0273] The device of the above embodiment is used to implement the corresponding defect image generation method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.

[0274] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments and methods, the present disclosure also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the defect image generation method described in any of the above embodiments is implemented.

[0275] Figure 7 A more specific schematic diagram of the hardware structure of an electronic device provided in this embodiment is shown, and the device may include: a processor 1010, a memory 1020, an input / output interface 1030, a communication interface 1040, and a bus 1050. The processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040 are connected to each other through the bus 1050 in the device.

[0276] The processor 1010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0277] The memory 1020 may be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 1020 may store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 1020 and are called and executed by the processor 1010.

[0278] The input / output interface 1030 is used to connect the input / output module to realize information input and output. The input / output module can be configured in the device as a component (not shown in the figure), or it can be externally connected to the device to provide corresponding functions. The input device may include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device may include a display, a speaker, a vibrator, an indicator light, etc.

[0279] The communication interface 1040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).

[0280] The bus 1050 includes a path that transmits information between the various components of the device (eg, the processor 1010, the memory 1020, the input / output interface 1030, and the communication interface 1040).

[0281] It should be noted that, although the above device only shows the processor 1010, the memory 1020, the input / output interface 1030, the communication interface 1040 and the bus 1050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0282] The electronic device of the above embodiment is used to implement the corresponding defect image generating method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.

[0283] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the defect image generation method described in any of the above embodiments.

[0284] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.

[0285] The computer instructions stored in the storage medium of the above embodiments are used to enable the computer to execute the defect image generation method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0286] Based on the same concept, corresponding to any of the above-mentioned embodiment methods, the present application also provides a computer program product, including computer program instructions. When the computer program instructions are run on a computer, the computer executes the method described in any of the above embodiments, which has the beneficial effects of the corresponding method embodiments and will not be repeated here.

[0287] It is understandable that before using the technical solutions of each embodiment of the present disclosure, the type, scope of use, usage scenarios, etc. of the personal information involved will be informed to the user in an appropriate manner, and the user's authorization will be obtained.

[0288] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly remind the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can independently choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.

[0289] As an optional but non-limiting implementation, in response to receiving the user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0290] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0291] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present disclosure (including the claims) is limited to these examples. Based on the concept of the present disclosure, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present disclosure as described above, which are not provided in detail for the sake of simplicity.

[0292] In addition, to simplify the description and discussion, and in order not to make the embodiments of the present disclosure difficult to understand, the known power / ground connections to the integrated circuit (IC) chips and other components may or may not be shown in the provided figures. In addition, the device can be shown in the form of a block diagram to avoid making the embodiments of the present disclosure difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform on which the embodiments of the present disclosure will be implemented (that is, these details should be fully within the scope of understanding of those skilled in the art). Where specific details (e.g., circuits) are set forth to describe exemplary embodiments of the present disclosure, it is apparent to those skilled in the art that the embodiments of the present disclosure can be implemented without these specific details or with changes in these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.

[0293] Although the present disclosure has been described in conjunction with specific embodiments of the present disclosure, many replacements, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.

[0294] The embodiments of the present disclosure are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present disclosure should be included in the scope of protection of the present disclosure.

Claims

1. A defect image generation method, characterized in that: include: Acquire a target image, a target mask image, and a target defect type, wherein the target image is a defect-free image; The target image, the target mask image and the target defect type are input into a pre-trained defect image generation model; wherein the defect image generation model comprises a noise processing module and a feature extraction module, and the noise processing module and the feature extraction module are trained respectively using a training data set to obtain a defect image generation model that outputs a defect image; The target defect image is obtained by processing the defect image generation model.

2. The method according to claim 1, characterized in that: The step of obtaining a target defect image through processing by the defect image generation model includes: Performing a noise adding process on the target image for a first preset number of steps based on the target defect type to obtain a first noise image; The first noise image is denoised based on the target mask image until the number of denoising steps meets a first preset number of steps to obtain a target defect image.

3. The method according to claim 2, characterized in that The denoising process is performed on the first noise image based on the target mask image until the number of denoising steps meets a first preset number of steps to obtain a target defect image, including: For each denoising process: Performing a one-step denoising process on the first noisy image to obtain a second noisy image; Performing noise adding processing on the target image for a second preset number of steps based on the target defect type to obtain a third noise image, wherein the second preset number of steps is less than the first preset number of steps; The target mask image, the second noise image and the third noise image are combined to obtain a defect image.

4. A model training method for training a defect image generation model of the defect image generation method according to any one of claims 1 to 3, characterized in that: The initial defect image generation model includes a noise processing module and a feature extraction module, including: Obtain training defect images, training mask images and training defect types, and construct a training data set; Acquire preset noise, and use the preset noise to perform noise addition processing on the data in the training data set to obtain a noisy image; Inputting the noisy image into a noise processing module to obtain predicted noise; Training the noise processing module based on the predicted noise and the preset noise until the training of the noise processing module is completed; De-noising the noisy image using the predicted noise to obtain a de-noised image; The feature extraction module is trained based on the denoised image until the feature extraction module training is completed, thereby obtaining a defect image generation model.

5. The method according to claim 4, characterized in that The training of the noise processing module based on the predicted noise and the preset noise includes: Using the predicted noise and the preset noise to train the noise processing module to determine a first loss; In response to the first loss being less than or equal to a first loss threshold, it is determined that the noise processing module training is complete.

6. The method according to claim 5, characterized in that The step of training the noise processing module by using the predicted noise and the preset noise to determine the first loss includes: Determine a first sub-loss according to the preset noise and the predicted noise; De-noising the noisy image using the predicted noise to obtain a de-noised image; Determine a second sub-loss according to the training defect image and the denoised image; A first loss is determined based on the first sub-loss and the second sub-loss.

7. The method according to claim 6, characterized in that The determining a first sub-loss according to the preset noise and the first noise includes: Get the preset mean square error loss function; According to the preset noise and the predicted noise, a first sub-loss is determined based on the mean square error loss function.

8. The method according to claim 6, characterized in that The determining the second sub-loss according to the training defect image and the denoised image comprises: Get the preset mean absolute error loss function; According to the training defect image and the denoised image, a second sub-loss is determined based on the mean absolute value error loss function.

9. The method according to claim 4, characterized in that The step of training the feature extraction module based on the denoised image until the feature extraction module training is completed to obtain a defect image generation model comprises: Training the feature extraction module using the denoised image to determine a second loss; In response to the second loss being less than or equal to a second loss threshold, it is determined that the feature extraction module training is completed, and a defect image generation model is obtained.

10. The method according to claim 9, characterized in that The step of training the feature extraction module using the denoised image to determine the second loss includes: Using the feature extraction module to extract features from the denoised image, and determining a third sub-loss according to the extracted feature values; A second loss is determined based on the first sub-loss, the second sub-loss, and the third sub-loss.

11. The method according to claim 10, characterized in that The feature extraction module is used to extract features from the denoised image, and a third sub-loss is determined according to the extracted feature values, including: Inputting the denoised image into the feature extraction module to obtain a first feature value; Performing enhancement processing on the training defect image to obtain an enhanced defect image; Inputting the enhanced defect image into the feature extraction module to obtain a second feature value; Selecting a sample defect image, and inputting the sample defect image into the feature extraction module to obtain a third feature value, wherein the sample defect image and the training defect image have different training defect types; A third sub-loss is calculated based on the first eigenvalue, the second eigenvalue, and the third eigenvalue.

12. The method according to claim 4, characterized in that The initial defect image generation model also includes a low-rank processing module. After obtaining the defect image generation model, it also includes: In response to receiving a new training data set, determining whether there is a new training defect type corresponding to the new training data set among the training defect types corresponding to the defect image generation model that have been trained; In response to the absence of the new training defect type, updating the model parameters of the defect image generation model to obtain a new initial defect image generation model; Inputting the new training data set into a low-rank processing module, and using the low-rank processing module to split the parameter matrix corresponding to the new training data set into multiple sub-data matrices for multiplication; The new initial defect image generation model is trained by multiplying a plurality of sub-data matrices until the low-rank processing module is trained to obtain a new defect image generation model.

13. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method according to any one of claims 1 to 3 or claims 4 to 12 is implemented.

14. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method of any one of claims 1 to 3 or claims 4 to 12.

15. A computer program product comprising computer program instructions, characterized in that When the computer program instructions are executed on a computer, the computer is caused to perform the method according to any one of claims 1 to 3 or claims 4 to 12.

Citation Information

Cited By

  • Chip defect detection method and device based on diffusion model, equipment and medium

    CN119941725A

  • Chip defect detection method, device, equipment and medium based on diffusion model

    CN119941725B

  • Steel structure welding quality detection method and storage medium

    CN120219374A

  • Cloth defect image generation method and device, equipment and storage medium

    CN120746923A

  • Training method and device of image generation model and image generation method and device

    CN120932042A