Training method of image generation model and image defect detection method

By updating the parameters of the image generation model using the difference between the reference sample image and the reconstructed sample image, the problems of low training efficiency and limited generalization ability in the prior art are solved, and efficient training and widely applicable image defect detection methods are realized.

CN118887497BActive Publication Date: 2025-02-07BEIJING SMARTMORE INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411376194.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2025-02-07
Estimated Expiration
2044-09-29

AI Technical Summary

Technical Problem

The existing image defect detection methods require a large number of defect samples for model training, and the model generalization ability is limited, making it difficult to apply to various artifact types and defect types.

Method used

By obtaining the reference sample image of the reference artifact, noise processing is performed to generate the reconstructed sample image, and the parameters of the image generation model are updated based on the image difference, so as to achieve efficient training and generalization of the model.

Benefits of technology

It improves the training efficiency and data applicability of the image generation model, can realize model training without the need for a large number of defect samples, and is suitable for various artifact types and defect types.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118887497B_ABST
    Figure CN118887497B_ABST
Patent Text Reader

Abstract

The present application relates to a method for training an image generation model and a method for detecting defects in an image. The method comprises: obtaining a reference sample image corresponding to a reference workpiece; inputting the reference sample image into an image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image; updating the model parameters of the image generation model to be trained based on the image difference between the reference sample image and the reconstructed sample image to obtain an updated image generation model; re-inputting the reference sample image into the updated image generation model for processing until a trained image generation model is obtained; the trained image generation model is used to determine the defect detection result corresponding to the image to be detected based on the reference image generated by the image to be detected. The present application not only improves the training efficiency of the image generation model, but also improves the data applicability of the model in the training process and the application process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of defect detection technology, and in particular to a training method for an image generation model, an image defect detection method, apparatus, computer equipment, and computer-readable storage medium. Background Art

[0002] In industrial production scenarios, in order to ensure the quality and integrity of workpieces, defect detection is required on the images corresponding to the workpieces to identify the defects of the workpieces.

[0003] In the current image defect detection methods, image defect detection is usually achieved through models. On the one hand, the model needs to be trained with a large number of defect samples. However, it is difficult to obtain a large number of defect samples, which reduces the efficiency of model training. On the other hand, image defect detection can only be achieved based on the workpiece types and defect types that have been trained in the model, resulting in limited model generalization ability and reducing the data applicability of the model in the training process and application process. Summary of the invention

[0004] Based on this, it is necessary to provide a training method for an image generation model, an image defect detection method, device, computer equipment, computer-readable storage medium and computer program product to address the above-mentioned technical problems. On the one hand, the training efficiency of the image generation model is improved, and on the other hand, the data applicability of the model in the training process and the application process is improved.

[0005] In a first aspect, the present application provides a method for training an image generation model, comprising:

[0006] Acquire a reference sample image corresponding to the reference workpiece;

[0007] Inputting the reference sample image into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image;

[0008] Based on the image difference between the reference sample image and the reconstructed sample image, the model parameters of the image generation model to be trained are updated to obtain an updated image generation model;

[0009] The reference sample image is re-input into the updated image generation model for processing until a trained image generation model is obtained; the trained image generation model is used to determine the defect detection result corresponding to the image to be detected based on the reference image generated by the image to be detected.

[0010] In a second aspect, the present application provides a method for detecting defects in an image, comprising:

[0011] Acquire the image to be detected;

[0012] Obtaining a trained image generation model, inputting the image to be detected into the trained image generation model for noise processing, and obtaining a reference image corresponding to the image to be detected; the trained image generation model is obtained by training the image generation model to be trained based on the reference sample image corresponding to the reference workpiece;

[0013] According to the image difference between the image to be detected and the reference image, the defect detection result corresponding to the image to be detected is obtained.

[0014] In a third aspect, the present application provides a training device for an image generation model, comprising:

[0015] A first acquisition module is used to acquire a reference sample image corresponding to a reference workpiece;

[0016] The first processing module is used to input the reference sample image into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image;

[0017] An updating module, used for updating the model parameters of the image generation model to be trained based on the image difference between the reference sample image and the reconstructed sample image, to obtain an updated image generation model;

[0018] The first generation module is used to re-input the reference sample image into the updated image generation model for processing until a trained image generation model is obtained; the trained image generation model is used to determine the defect detection result corresponding to the image to be detected based on the reference image generated by the image to be detected.

[0019] In a fourth aspect, the present application provides an image defect detection device, comprising:

[0020] A second acquisition module is used to acquire the image to be detected;

[0021] The second processing module is used to obtain a trained image generation model, input the image to be detected into the trained image generation model for noise processing, and obtain a reference image corresponding to the image to be detected; the trained image generation model is obtained by training the image generation model to be trained based on the reference sample image corresponding to the reference workpiece;

[0022] The second generating module is used to obtain the defect detection result corresponding to the image to be detected according to the image difference between the image to be detected and the reference image.

[0023] In a fifth aspect, the present application provides a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method when executing the computer program.

[0024] In a sixth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which implements the steps in the above method when executed by a processor.

[0025] In a seventh aspect, the present application provides a computer program product, which includes a computer program, and the computer program implements the steps in the above method when executed by a processor.

[0026] The above-mentioned image generation model training method, image defect detection method, device, computer equipment, computer-readable storage medium and computer program product, on the one hand, input the reference sample image corresponding to the defect-free workpiece into the image generation model to be trained for training, and the model training can be realized without collecting a large number of defective sample images, thereby reducing the difficulty of obtaining sample data, improving the training efficiency of the image generation model, and fully ensuring that the model has a generalized normal material distribution; on the other hand, only the reconstructed sample image is obtained by noise processing the input reference sample image, and based on the image difference between the reference sample image and the reconstructed sample image, the iterative update of the image generation model is realized, without the need for training for various workpiece types and defect types, it is suitable for processing various input data, and improves the data applicability of the model in the training process and application process. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] FIG1 is a diagram showing an application environment of a method for training an image generation model and a method for detecting defects in an image provided by an embodiment of the present application;

[0028] FIG2 is a flow chart of a method for training an image generation model provided in an embodiment of the present application;

[0029] Figure 3 A schematic diagram of a process flow of an image defect detection method provided in an embodiment of the present application;

[0030] Figure 4 A schematic diagram of a flow chart of another image defect detection method provided in an embodiment of the present application;

[0031] Figure 5 A structural block diagram of a training device for an image generation model provided in an embodiment of the present application;

[0032] Figure 6 A structural block diagram of an image defect detection device provided in an embodiment of the present application;

[0033] Figure 7 An internal structure diagram of a computer device provided in an embodiment of the present application;

[0034] Figure 8An internal structure diagram of another computer device provided in an embodiment of the present application;

[0035] Fig. 9 An internal structure diagram of a computer-readable storage medium provided in an embodiment of the present application. DETAILED DESCRIPTION

[0036] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0037] The training method of the image generation model and the image defect detection method provided in the embodiment of the present application can be applied to the application environment shown in Figure 1. Among them, the terminal 102 communicates with the server 104 through a communication network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. Among them, the terminal 102 can be but is not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.

[0038] As shown in FIG2 , the present application embodiment provides a method for training an image generation model, and the method is described by taking the method applied to the terminal 102 or the server 104 in FIG1 as an example. It is understandable that the computer device may include at least one of a terminal and a server. The method includes the following steps:

[0039] S202: Acquire a reference sample image corresponding to the reference workpiece.

[0040] Among them, the workpiece refers to an object with a certain shape and size made in an industrial production scenario; the reference workpiece refers to a workpiece whose surface quality meets the quality inspection requirements, such as a workpiece with no surface defects, or a workpiece with slight defects on the surface but still meets the technical requirements.

[0041] The sample image refers to an image obtained by photographing the surface features of the workpiece, including surface features such as the roughness, smoothness, and presence or absence of defects on the workpiece surface; the reference sample image refers to an image obtained by photographing the surface features of the reference workpiece.

[0042] S204 , inputting the reference sample image into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image.

[0043] Among them, the image generation model refers to an artificial intelligence model that can generate images based on input data; the image generation model can be expressed as a diffusion model (Denoising Diffusion Probabilistic Models, DDPMs), which processes the noise of the input image and converts it into an image that is close to the real data distribution.

[0044] Among them, the reconstructed sample image represents an image generated based on the image generation model to be trained and matching the reference sample image, that is, it is equivalent to the workpiece entity recorded in the reconstructed sample image matching the workpiece entity recorded in the reference sample image, and the surface features of the workpiece entity in the reconstructed sample image matching the surface features of the workpiece entity in the reference sample image.

[0045] The noise processing of an image refers to a combination of noise addition processing and noise removal processing of the image.

[0046] In some embodiments, the noise processing of the image may mean adding random noise or specified noise to the image, adding noise independently to different color channels of the image, adding noise to the image at different scales or resolutions, iteratively adding noise to the image for a specified number of times, and dynamically adjusting the noise intensity according to the local characteristics of the image to adaptively add noise to the image.

[0047] In some embodiments, the denoising process of an image may include filtering out random noise or specified noise from an image, independently filtering out noise from different color channels of an image, filtering out noise from an image at different scales or resolutions, iteratively filtering out noise from an image for a specified number of times, and dynamically adjusting filtering parameters according to local characteristics of the image and predicted noise distribution to adaptively filter out noise from the image.

[0048] In some embodiments, noise may be added to the image iteratively for a specified number of times, and then the noise may be filtered out iteratively for a specified number of times; or noise may be added to the image first, and then the noise may be filtered out, and then the process may be repeated for a specified number of times.

[0049] S206 . Based on the image difference between the reference sample image and the reconstructed sample image, the model parameters of the image generation model to be trained are updated to obtain an updated image generation model.

[0050] In some embodiments, image differences may represent differences in image features, where image features may represent visual features such as pixel value, color, texture, etc., and may also represent statistical features such as brightness, contrast, and histogram distribution, and may also represent structural features such as edges, contours, and shapes, and frequency domain features such as frequency distribution and spectral density.

[0051] In some embodiments, the pixel values ​​of the images can be directly compared at the pixel level through calculation methods such as Mean Absolute Error (MAE), Mean Squared Error (MSE), and Structural Similarity Index Measure (SSIM) to quantify the image difference between the sample image and the reconstructed sample image.

[0052] In some embodiments, the local or global features of the image can be compared at the feature level to quantify the image difference between the sample image and the reconstructed sample image through comparison methods such as histogram comparison, SIFT or SURF feature matching, deep learning feature extraction and comparison, etc.

[0053] In some embodiments, the semantic information of the images may be compared at the semantic level by means of semantic segmentation, attribute recognition, etc., so as to quantify the image difference between the sample image and the reconstructed sample image.

[0054] In some embodiments, based on the image difference between the reference sample image and the reconstructed sample image, the corresponding model parameters to be updated in the image generation model to be trained may represent model parameters involved in noise processing of the reference sample image in the image generation model to be trained, such as noise scheduling parameters for controlling noise addition and removal, and noise level parameters for defining the intensity of adding and removing noise.

[0055] In some embodiments, the model parameters to be updated may also represent neural network architecture parameters, which are used to define the weights and biases of each layer of the neural network, such as the parameters corresponding to the convolution layer, pooling layer, and sampling layer; the model parameters to be updated may also represent learning rate parameters, which are used to control the extent of model update in each iteration, such as attenuation steps, attenuation rate, cycle period and other parameters.

[0056] S208, re-input the reference sample image into the updated image generation model for processing until a trained image generation model is obtained; the trained image generation model is used to determine the defect detection result corresponding to the image to be detected based on the reference image generated by the image to be detected.

[0057] In some embodiments, during the iterative training of the image generation model, a reconstructed sample image output by the image generation model obtained by the iterative training is obtained. If the image difference between the reference sample image and the reconstructed sample image meets a preset threshold condition, the training of the image generation model is completed.

[0058] Among them, the preset threshold condition is used to determine whether the matching degree between the reference sample image and the reconstructed sample image reaches the expected value; if the image difference between the reference sample image and the reconstructed sample image meets the preset threshold condition, it means that the matching degree between the surface features of the workpiece entity in the reconstructed sample image and the surface features of the workpiece entity in the reference sample image reaches the expected value.

[0059] In some embodiments, the image to be inspected may represent an image to be inspected to see whether the workpiece recorded therein is abnormal, that is, to detect whether there is a defect on the surface of the workpiece recorded in the image. If so, further detect the defect type.

[0060] In some embodiments, the reference image may represent an image generated based on a trained image generation model and matching the image to be inspected, that is, the workpiece entity recorded in the reference image matches the workpiece entity recorded in the image to be inspected, and the surface features of the workpiece entity in the reference image are simulated as a defect-free state.

[0061] In some embodiments, the reference image and the image to be detected are compared at the image feature level, that is, when the reference image and the image to be detected record the same workpiece entity, based on the image comparison between the workpiece entity in a defect-free state in the reference image and the workpiece entity in an unknown defect state in the image to be detected, it is determined whether the workpiece entity in the image to be detected has defects and the corresponding defect type.

[0062] In some embodiments, the defect detection result corresponding to the image to be detected may represent information on the workpiece entity dimensions of the workpiece entity in the image to be detected, such as the workpiece type, whether there are defects, and the defect type. The workpiece type may represent information such as the shape, material, size, and function of the workpiece, and the defect type may represent information such as scratches, fractures, and deformations. The defect detection result corresponding to the image to be detected may also represent information on the image dimensions such as the shape, area, size, position coordinates, and involved areas of the defects of the workpiece entity in the image to be detected, and may also represent information on the production and quality inspection dimensions such as the detection time, the number and batch of the detected workpiece, and the configuration information of the detection equipment.

[0063] It can be seen that in the embodiments of the present application, on the one hand, the reference sample image corresponding to the defect-free workpiece is input into the image generation model to be trained for training, and the model training can be realized without collecting a large number of defective sample images, thereby reducing the difficulty of obtaining sample data, improving the training efficiency of the image generation model, and fully ensuring that the model has a generalized normal material distribution; on the other hand, the reconstructed sample image is obtained only by performing noise processing on the input reference sample image, and based on the image difference between the reference sample image and the reconstructed sample image, the iterative update of the image generation model is realized without training for various workpiece types and defect types, which is suitable for processing various input data and improves the data applicability of the model in the training process and the application process.

[0064] In some embodiments, the reference sample image is input into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image, including:

[0065] S302, obtaining the real noise distribution parameters corresponding to each round of noise addition processing, and performing noise addition processing on the reference sample image step by step according to the real noise distribution parameters corresponding to each round of noise addition processing, to obtain the noisy sample image corresponding to the target noise addition processing round of the reference sample image.

[0066] The noise adding process round refers to the round of performing noise adding process on the image during the image processing process; the target noise adding process round may include each noise adding process round, or may include at least one noise adding process round among all the noise adding process rounds.

[0067] The real noise distribution parameter represents parameter information describing the noise distribution state corresponding to the real noise added when the image is subjected to noise processing; the noise distribution state may represent information such as the noise type, noise intensity, and noise distribution range.

[0068] In some embodiments, according to the real noise distribution parameters corresponding to the first noise addition processing round, the reference sample image is subjected to noise addition processing to obtain a noisy image under the noise distribution state described by the real noise distribution parameters; then, according to the real noise distribution parameters corresponding to the next noise addition processing round, the noisy image is subjected to noise addition processing until all noise addition processing rounds are traversed to obtain a noisy sample image.

[0069] It can be understood that the noise distribution state corresponding to the noisy sample image is obtained by cumulatively merging the noise distribution states described by the real noise distribution parameters corresponding to each round of noisy processing, so that the noisy sample image is closer to pure noise, thereby enabling the image generation model to learn the complex conversion process from a clear image to pure noise, and providing a basis for the image generation model to perform the reverse operation, that is, to perform the reverse conversion operation from pure noise to a clear image.

[0070] In some embodiments, the number of noise addition processing rounds may be a fixed value, or may be adaptively adjusted according to the actual noise addition process. For example, if the noise distribution state corresponding to the noisy image obtained by the current noise addition process does not meet expectations, the number of noise addition processing rounds may be adaptively increased or decreased, and the actual noise distribution parameters corresponding to future noise addition processing rounds may also be adaptively adjusted.

[0071] S304, obtaining the predicted noise distribution parameters corresponding to each denoising process round, and performing denoising on the noisy sample image step by step according to the predicted noise distribution parameters corresponding to each denoising process round, to obtain a reconstructed sample image corresponding to the reference sample image after the target denoising process round.

[0072] The denoising processing round refers to the round of denoising processing performed on the image during the image processing process; the target denoising processing round may include each denoising processing round, and may also include at least one denoising processing round among all the denoising processing rounds.

[0073] Among them, the predicted noise distribution parameters represent parameter information for predicting the noise distribution state corresponding to the noise retained after filtering out the noise when denoising the image; wherein the noise distribution state can represent information such as noise type, noise intensity, and noise distribution range.

[0074] In some embodiments, the noisy sample image is denoised according to the predicted noise distribution parameters corresponding to the first denoising round to obtain a denoised image under the noise distribution state predicted by the predicted noise distribution parameters; then the denoised image is denoised according to the predicted noise distribution parameters corresponding to the next denoising round until all denoising rounds are traversed to obtain a reconstructed sample image.

[0075] It can be understood that the noise distribution state corresponding to the denoised sample image is obtained by cumulatively merging the noise distribution states predicted by the predicted noise distribution parameters corresponding to each denoising process round, so that the reconstructed sample image is closer to a clear image, thereby enabling the image generation model to learn the complex transformation process from pure noise to a clear image, so as to most effectively remove noise in each denoising process round, while most effectively retaining the important features of the image.

[0076] In some embodiments, the number of denoising processing rounds may be a fixed value, or may be adaptively adjusted according to the actual denoising process. For example, if the noise distribution state corresponding to the denoised image obtained by the current denoising process does not meet expectations, the number of denoising processing rounds may be adaptively increased or decreased, and the predicted noise distribution parameters corresponding to future denoising processing rounds may also be adaptively adjusted.

[0077] It can be seen that in this embodiment, the reference sample image is subjected to denoising step by step through various denoising rounds to obtain a noisy sample image, and then the noisy sample image is subjected to denoising step by step through various denoising rounds to obtain a reconstructed sample image. Based on this, the reference sample image is subjected to hierarchical and operational denoising and denoising processing, so that the image generation model can accurately and efficiently learn the conversion process between a clear image and pure noise.

[0078] In some embodiments, obtaining the real noise distribution parameters corresponding to each noise addition processing round includes:

[0079] S402: Acquire a reference noise distribution state, and sample from the reference noise distribution state according to the order of each noise adding process round to obtain real noise distribution parameters corresponding to each noise adding process round.

[0080] The reference noise distribution state represents a standardized noise distribution state.

[0081] In some embodiments, the reference noise distribution state may represent a Gaussian noise distribution state, for example, a Gaussian noise distribution state represented by N(0,I), where 0 is the mean and I is the unit covariance matrix; the reference noise distribution state may also represent a Laplace distribution state, for example, a Laplace distribution state represented by L(μ,b), where μ is the location parameter and b is the scale parameter; the reference noise distribution state may also represent a uniform noise distribution state, for example, a uniform noise distribution state represented by an interval U(m,n), where m and n are the lower and upper limits of the noise value, respectively, and all noise values ​​within the interval have the same probability.

[0082] In some embodiments, according to the order of each noise processing round, the sampling configuration information corresponding to each noise processing round is determined, such as sampling configuration information such as collecting noise of a specified noise intensity, collecting noise of a specified noise frequency, and sampling interval, and each noise processing round samples the corresponding noise distribution state from the reference noise distribution state according to the corresponding sampling configuration information; according to the noise distribution state obtained by sampling corresponding to each noise processing round, the real noise distribution parameters corresponding to each noise processing round are calculated. Based on this, the corresponding configuration information for sampling is adaptively allocated to each noise processing round, such as configuration information such as filtering out noise of a specified noise intensity, filtering out noise of a specified noise frequency, etc., so as to achieve hierarchical noise processing of the image based on the corresponding configuration information in each noise processing round.

[0083] In some embodiments, according to the order of each noise addition round, random sampling is performed from the reference noise distribution state to obtain the noise distribution state corresponding to each noise addition round; based on the noise distribution state obtained by sampling corresponding to each noise addition round, the real noise distribution parameters corresponding to each noise addition round are calculated.

[0084] In some embodiments, when the image generation model is a diffusion model, T noise processing rounds are defined, and each noise processing round is sampled in the Gaussian distribution state of N (0, I), and the T noise processing rounds respectively correspond to , ,……, Equal to the real noise distribution parameters, then the reference sample image After t rounds of noise addition processing, the output noised image is The corresponding noise distribution state for:

[0085] (1)

[0086] In formula (1), It means that after t rounds of noise addition, the reference sample image The amount of information retained in It means that after t rounds of noise addition, the reference sample image The noise variance of the accumulated noise in ; where, ,Right now Represents the number of steps from 1 to t The cumulative product of .

[0087] It can be seen that as t increases, Reduced, reference sample image The amount of information in the image gradually decreases, and the noise gradually increases; at t=T, the noisy image The corresponding noise distribution state is , that is, the reference sample image It becomes pure Gaussian noise.

[0088] In some embodiments, obtaining predicted noise distribution parameters corresponding to each denoising process round includes:

[0089] S404: Obtain noise prediction parameters of the image generation model to be trained, and determine predicted noise distribution parameters corresponding to each denoising process round from the noise prediction parameters according to the order of each denoising process round.

[0090] The noise prediction parameters are used to calculate the predicted noise distribution parameters corresponding to each denoising process round.

[0091] In some embodiments, based on the noise prediction parameters, the predicted noise distribution parameters of each denoising processing round in the corresponding order are calculated, so that according to the corresponding order of each denoising processing round, corresponding configuration information for denoising is adaptively allocated to each denoising processing round, such as filtering out noise of a specified noise intensity, filtering out noise of a specified noise frequency, and other configuration information, thereby achieving hierarchical denoising of the image in each denoising processing round based on the corresponding configuration information.

[0092] In some embodiments, when the image generation model to be trained is a diffusion model, T denoising rounds are defined, and the denoised sample image After T denoising rounds, the output reconstructed sample image The corresponding conditional probability distribution for:

[0093] (2)

[0094] In formula (2), Represents the noisy sample image at the given current t step In the case of The image at step t-1 obtained after denoising Corresponding probability conditional distribution; Accumulate and fuse the probability conditional distributions corresponding to steps 1 to T to achieve the noise sample image The final reconstructed sample image is obtained by step-by-step denoising and reconstruction. The corresponding conditional probability distribution.

[0095] In formula (2), Can represent the noisy sample image After t rounds of denoising, the output denoised image The corresponding noise distribution state ,Right now:

[0096] (3)

[0097] In formula (3), and Represents the noise prediction parameters that need to be learned by the U-Net network architecture in the diffusion model; , They are used to predict the denoised image obtained after t denoising rounds. The corresponding noise mean and noise variance are expressed as the predicted noise distribution parameters.

[0098] In some embodiments, T denoising rounds are a fixed number of denoising rounds, and T denoising rounds are a fixed number of denoising rounds, so as to speed up the reasoning efficiency and convergence efficiency of the model.

[0099] It can be seen that in this embodiment, on the one hand, the standardized reference noise distribution state is sampled according to the order of each denoising round, so as to efficiently and hierarchically obtain the real noise distribution parameters corresponding to each denoising round; on the other hand, according to the order of each denoising round, the predicted noise distribution parameters corresponding to each denoising round are efficiently and hierarchically calculated from the noise prediction parameters of the image generation model to be trained.

[0100] In some embodiments, based on the image difference between the reference sample image and the reconstructed sample image, the model parameters of the image generation model to be trained are updated to obtain the updated image generation model, including:

[0101] S502: Obtain pixel values ​​of the reference sample image and the reconstructed sample image at each pixel position respectively.

[0102] S504: Determine the loss between the reference sample image and the reconstructed sample image according to the difference in pixel values ​​at the same pixel position between the reference sample image and the reconstructed sample image.

[0103] In some embodiments, in the reference sample image, each pixel position is traversed to obtain the pixel value corresponding to each pixel position of the reference sample image; in the reconstructed sample image, each pixel position is traversed to obtain the pixel value corresponding to each pixel position of the reconstructed sample image; the reference sample image and the reconstructed sample image of the same size have matching numbers of pixels and pixel positions, and at each pixel position, the pixel value difference between the reference sample image and the reconstructed sample image is calculated, and further, based on the pixel value difference corresponding to each pixel position, the loss between the reference sample image and the reconstructed sample image is calculated.

[0104] In some embodiments, the loss between the reference sample image and the reconstructed sample image can be calculated by calculating the mean absolute error, that is, the pixel difference between the reference sample image and the reconstructed sample image at each pixel point is calculated, the pixel difference corresponding to each pixel point is fused to obtain a comprehensive pixel difference, and the comprehensive pixel difference is averaged according to the number of pixels to calculate the loss of the reference sample image and the reconstructed sample image.

[0105] In some embodiments, the loss between the reference sample image and the reconstructed sample image can be calculated by calculating the mean square error, that is, the pixel difference between the reference sample image and the reconstructed sample image at each pixel point is calculated, the pixel difference corresponding to each pixel point is squared respectively, and the comprehensive pixel difference after the square processing is averaged according to the number of pixels, so as to calculate the loss of the reference sample image and the reconstructed sample image.

[0106] S506. Determine an update direction of the model parameters of the image generation model to be trained according to the expected result corresponding to the loss, and update the model parameters according to the update direction to obtain an updated image generation model.

[0107] In some embodiments, in the image generation model to be trained, the model training direction is to make the matching degree of the workpiece surface features corresponding to the generated reconstructed sample image and the input reference sample image as high as possible, while ensuring that the loss between the reconstructed sample image and the reference sample image is as small as possible, so as to determine the updating direction of the model parameters of the image generation model to be trained.

[0108] In some embodiments, the expected result corresponding to the loss between the reconstructed sample image and the reference sample image may represent the minimum value of the loss between the reconstructed sample image and the reference sample image that is expected to be achieved. For example, the expected minimum value of the loss obtained by calculating the mean absolute error or the mean square error may be 0.

[0109] In some embodiments, the image difference between the reference sample image and the reconstructed sample image can be calculated by calculating the L1 loss, that is, the absolute difference in pixel values ​​at the same pixel between the reference sample image and the reconstructed sample image is calculated, and the absolute difference corresponding to each pixel is summed to obtain the L1 loss corresponding to the reference sample image and the reconstructed sample image.

[0110] It can be seen that in this embodiment, based on the difference in pixel values ​​corresponding to the reference sample image and the reconstructed sample image at each pixel position, the loss between the reference sample image and the reconstructed sample image is obtained comprehensively and accurately at the image pixel level, so as to efficiently update the model parameters of the image generation model to be trained.

[0111] In some embodiments, determining the update direction of the model parameters of the image generation model to be trained according to the expected result corresponding to the loss includes:

[0112] S602: In the current configuration environment, according to minimizing the loss, obtain the expected result corresponding to the loss.

[0113] S604: Determine the update direction of the model parameters of the image generation model to be trained according to the expected result.

[0114] The current configuration environment may represent the hardware configuration environment of a computer device, the data feature configuration environment of a data set, or the user's customized configuration environment.

[0115] The expected result may represent the minimum value that can be expected to be achieved when calculating the loss based on current computer resources, for example, calculating the image loss based on computer resources such as CPU occupancy, memory occupancy, and memory read and write speed.

[0116] The expected result may represent the minimum value that is expected to be achieved when the loss is calculated based on the image quality parameters of the current input image, for example, when the loss is calculated based on image quality parameters such as the image resolution and data volume of the current input image.

[0117] Among them, the expected result can represent the minimum value that can be expected to be achieved when calculating the loss according to the model architecture parameters set by the user, for example, when calculating the loss according to the model architecture parameters such as network layer and network depth set by the user.

[0118] In some embodiments, the expected result may represent the minimum value that can be achieved by considering one or all of the dimensions, such as computer resource consumption, image processing efficiency, and user experience, of the loss between the reconstructed sample image and the reference sample image.

[0119] In this embodiment, according to the current configuration environment, the expected result corresponding to the loss between the reference sample image and the reconstructed sample image is adaptively determined, so as to accurately obtain the update direction of the model parameters of the image generation model to be trained.

[0120] like Figure 3 As shown, the embodiment of the present application provides a method for detecting defects in an image, and the method is described by taking the method applied to the terminal 102 or the server 104 in FIG. 1 as an example. It can be understood that the computer device can include at least one of a terminal and a server. The method includes the following steps:

[0121] S702: Acquire an image to be detected.

[0122] The image to be detected refers to an image to be detected to see whether the workpiece recorded therein is abnormal, that is, to detect whether there are defects on the surface of the workpiece recorded in the image, and the type of the defects.

[0123] S704, obtaining a trained image generation model, inputting the image to be detected into the trained image generation model for noise processing, and obtaining a reference image corresponding to the image to be detected; the trained image generation model is obtained by training the image generation model to be trained based on the reference sample image corresponding to the reference workpiece.

[0124] The trained image generation model corresponds to the trained image generation model in any of the above embodiments.

[0125] Among them, the reference image represents an image generated based on the trained image generation model and matching the image to be detected, that is, the workpiece entity recorded in the reference image matches the workpiece entity recorded in the image to be detected, and the surface features of the workpiece entity in the reference image are simulated as a defect-free state.

[0126] Among them, the noise processing of the image to be detected by the trained image generation model corresponds to the noise processing of the reference sample image by the image generation model to be trained in any of the above embodiments, and the model parameters involved in the noise processing of the image to be detected are the updated model parameters.

[0127] S706: Obtain a defect detection result corresponding to the image to be detected according to the image difference between the image to be detected and the reference image.

[0128] Among them, the defect detection result corresponding to the image to be detected corresponds to the defect detection result in the above embodiment.

[0129] In some embodiments, when the reference image and the image to be inspected record the same workpiece entity, image comparison is performed between the workpiece entity in a defect-free state in the reference image and the workpiece entity in an unknown defect state in the image to be inspected to achieve image difference comparison between the reference image and the image to be inspected at the image level, thereby determining whether there are defects in the workpiece entity in the image to be inspected and the corresponding defect type.

[0130] In some embodiments, a difference map corresponding to the image to be detected and the reference image can be obtained based on the image difference between the image to be detected and the reference image. For example, the image to be detected and the reference image are subtracted at the pixel level to obtain the difference map, and the defect detection result corresponding to the image to be detected is directly obtained based on the numerical value of each pixel position in the difference map.

[0131] In some embodiments, the image to be inspected and the reference image may be subjected to a pixel-level subtraction operation to obtain a difference map, and then the difference map may be subjected to threshold processing to achieve image binarization. The defect detection result corresponding to the image to be inspected may be obtained based on the numerical value of each pixel position in the difference map after the binarization processing.

[0132] It can be seen that in this embodiment, on the one hand, based on the trained image generation model with data applicability, the image to be inspected is input into the trained image generation model for noise processing, and a reference image of a defect-free state corresponding to the image to be inspected is adaptively obtained; on the other hand, based on the image difference between the image to be inspected and the reference image, defect detection of the image to be inspected is efficiently and adaptively achieved at the level of image difference, so as to improve the applicability of the inspection object and the reliability of the results.

[0133] In some embodiments, obtaining a defect detection result corresponding to the image to be detected according to the image difference between the image to be detected and the reference image includes:

[0134] S802: Obtain a first grayscale image corresponding to the image to be detected and a second grayscale image corresponding to the reference image.

[0135] Among them, the grayscale image represents an image containing only grayscale, that is, an image that loses color information but retains brightness and structure information; the first grayscale image represents the grayscale image corresponding to the image to be detected, and the second grayscale image represents the grayscale image corresponding to the reference image.

[0136] In some embodiments, the R, G, and B values ​​of each pixel in the image may be averaged to obtain an average pixel value corresponding to each pixel, so as to convert the color image into a grayscale image.

[0137] In some embodiments, the R, G, and B values ​​of each pixel in the image may be weighted averaged according to specified weights to obtain weighted average pixel values ​​corresponding to each pixel. For example, considering the sensitivity of the human eye to different colors, the R, G, and B values ​​are assigned weights of 0.299, 0.587, and 0.114, respectively, to achieve the conversion of a color image into a grayscale image.

[0138] In some embodiments, in an image, only the values ​​corresponding to each pixel in the same single channel may be taken, for example, only the values ​​corresponding to each pixel in the R channel may be taken, so as to realize conversion of a color image into a grayscale image.

[0139] S804 , respectively obtain pixel values ​​of the first grayscale image and the second grayscale image at each pixel position, and obtain a binary image corresponding to the image to be detected according to the difference in pixel values ​​of the first grayscale image and the second grayscale image at the same pixel position.

[0140] The binary image refers to an image in which the pixel value of each pixel is 1 or 0, that is, it represents a mask image used to highlight or isolate a specific region of interest.

[0141] In some embodiments, a pixel-level subtraction operation is performed on the first grayscale image and the second grayscale image, that is, the pixel difference between the first grayscale image and the second grayscale image at the same pixel position is calculated, and a difference map is obtained according to the pixel difference corresponding to each pixel position; pixels in the difference map with pixel values ​​higher than a preset threshold are set to white, that is, the pixel values ​​are set to 1, and pixels in the difference map with pixel values ​​lower than or equal to the preset threshold are set to black, that is, the pixel values ​​are set to 0, thereby obtaining a binary image.

[0142] In some embodiments, the mean or median corresponding to the pixel values ​​of each pixel in the difference map can be used as a preset threshold; the difference map can be evenly divided into multiple local areas, and the preset threshold corresponding to each local area in the difference map can be adaptively set according to the local features corresponding to each local area in the difference map, such as the pixel mean, pixel median and other local features corresponding to each local area.

[0143] In some embodiments, a rectangular influence area of ​​specified length and width or a circular influence area of ​​specified radius can be obtained with any pixel as the center among the pixels of the difference map, and the pixel mean corresponding to each pixel in the influence area is used as the preset threshold corresponding to the pixel at the center.

[0144] S806, obtaining the pixel value of each pixel position of the binary image; obtaining the defect area in the image to be detected according to the area corresponding to the pixel position whose pixel value in the binary image meets the preset threshold condition; and determining the defect detection result corresponding to the image to be detected according to the defect area.

[0145] The preset threshold condition is used to screen out pixels with the same pixel value in the binary image.

[0146] In some embodiments, in each pixel of the binary image, if the pixel value of the pixel is 1, the pixel value of the pixel satisfies the preset threshold condition; if the pixel value of the pixel is 0, the pixel value of the pixel does not satisfy the preset threshold condition, thereby screening out the areas corresponding to pixels with the same pixel value of 1 and the areas corresponding to pixels with the same pixel value of 0.

[0147] In some embodiments, the area corresponding to the pixels whose pixel values ​​are all 1 obtained by screening represents the area corresponding to the pixels whose pixel values ​​in the difference map corresponding to the first grayscale image and the second grayscale image are higher than the preset threshold, that is, the area where there are differences between the surface features of the workpiece in the image to be inspected and the surface features of the workpiece in the reference image, that is, the defective area in the image to be inspected.

[0148] In some embodiments, after obtaining the defect area corresponding to the image to be detected, the physical information such as the defect type, defect position, defect size, etc. corresponding to the workpiece entity in the image to be detected in the physical space can be reflected based on the image information such as the position, contour, area, etc. of the defect area in the image to be detected.

[0149] In some embodiments, if the pixel value of each pixel in the binary image does not meet the preset threshold condition, it means that the workpiece entity in the image to be inspected is in a defect-free state.

[0150] In some embodiments, Figure 4 As shown, an image to be detected is obtained, and the image to be detected includes a workpiece area corresponding to the recorded workpiece entity, and the workpiece area is an area of ​​defect state to be detected. The image to be detected is input into a diffusion model for noise addition and denoising, and a reference image corresponding to the image to be detected is obtained.

[0151] The image to be inspected is grayed to obtain a first grayed image, and the reference image is grayed to obtain a second grayed image; the first grayed image and the second grayed image are subtracted at the pixel level to obtain a binary image, which is a segmented image of the defect area; a median filter can be used to filter the binary image to improve the smoothness of the image detail features.

[0152] If there is no difference area in the binary image, that is, all the values ​​in the binary image are 0, it means that the workpiece area corresponding to the image to be detected is in a defect-free state; if there is a difference area in the binary image, that is, some values ​​in the binary image are 1, the area corresponding to the value 1 is taken as the defect area in the workpiece area, and the defect is located and identified based on the defect area, so as to obtain the defect detection result.

[0153] It can be seen that in this embodiment, first, the image to be detected and the reference image are grayed to obtain corresponding grayed images, thereby reducing the amount of data and reducing the computational complexity; secondly, a binary image is obtained based on the pixel value difference between the grayed images, thereby further reducing the amount of data and highlighting the important structures in the image; thirdly, based on the pixel value size of each pixel in the binary image, the defective area is efficiently and accurately located and identified in the image to be detected.

[0154] It should be understood that, although the steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indications of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0155] Based on the same inventive concept, the embodiment of the present application also provides a training device for an image generation model. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the training device for one or more image generation models provided below can refer to the limitations of the training method for the image generation model above, and will not be repeated here.

[0156] like Figure 5 As shown, the embodiment of the present application provides a training device 500 for an image generation model, comprising:

[0157] A first acquisition module 502 is used to acquire a reference sample image corresponding to a reference workpiece;

[0158] The first processing module 504 is used to input the reference sample image into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image;

[0159] An updating module 506, configured to update the model parameters of the image generation model to be trained based on the image difference between the reference sample image and the reconstructed sample image, to obtain an updated image generation model;

[0160] The first generation module 508 is used to re-input the reference sample image into the updated image generation model for processing until a trained image generation model is obtained; the trained image generation model is used to determine the defect detection result corresponding to the image to be detected based on the reference image generated by the image to be detected.

[0161] In some embodiments, in the aspect of inputting the reference sample image into the image generation model to be trained for noise processing to obtain the reconstructed sample image corresponding to the reference sample image, the first processing module 504 is specifically used to:

[0162] Acquire the real noise distribution parameters corresponding to each round of noise addition processing, perform noise addition processing on the reference sample image step by step according to the real noise distribution parameters corresponding to each round of noise addition processing, and obtain the noisy sample image corresponding to the target noise addition processing round of the reference sample image;

[0163] The predicted noise distribution parameters corresponding to each denoising process round are obtained, and the noisy sample image is denoised step by step according to the predicted noise distribution parameters corresponding to each denoising process round, so as to obtain a reconstructed sample image corresponding to the target denoising process round of the reference sample image.

[0164] In some embodiments, in terms of obtaining the real noise distribution parameters corresponding to each noise addition processing round, the first processing module 504 is specifically used to:

[0165] Acquire a reference noise distribution state, and sample from the reference noise distribution state according to the order of each noise addition process round to obtain the real noise distribution parameters corresponding to each noise addition process round;

[0166] In terms of obtaining the predicted noise distribution parameters corresponding to each denoising process round, the first processing module 504 is specifically used to:

[0167] The noise prediction parameters of the image generation model to be trained are obtained, and according to the order of each denoising process round, the predicted noise distribution parameters corresponding to each denoising process round are determined from the noise prediction parameters.

[0168] In some embodiments, in terms of updating the model parameters of the image generation model to be trained based on the image difference between the reference sample image and the reconstructed sample image to obtain an updated image generation model, the updating module 506 is specifically used to:

[0169] Respectively obtain the pixel values ​​of the reference sample image and the reconstructed sample image at each pixel position;

[0170] Determine the loss between the reference sample image and the reconstructed sample image according to the difference in pixel values ​​at the same pixel position between the reference sample image and the reconstructed sample image;

[0171] According to the expected result corresponding to the loss, the update direction of the model parameters of the image generation model to be trained is determined, and the model parameters are updated according to the update direction to obtain the updated image generation model.

[0172] In terms of determining the update direction of the model parameters of the image generation model to be trained according to the expected result corresponding to the loss, the update module 506 is specifically used to:

[0173] In the current configuration environment, according to minimizing the loss, the expected result corresponding to the loss is obtained;

[0174] According to the expected results, the update direction of the model parameters of the image generation model to be trained is determined.

[0175] Based on the same inventive concept, the embodiment of the present application also provides an image defect detection device. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of one or more image defect detection devices provided below can refer to the limitations of the image defect detection method above, and will not be repeated here.

[0176] like Figure 6 As shown, the embodiment of the present application provides an image defect detection device 600, comprising:

[0177] The second acquisition module 602 is used to acquire the image to be detected;

[0178] The second processing module 604 is used to obtain a trained image generation model, input the image to be detected into the trained image generation model for noise processing, and obtain a reference image corresponding to the image to be detected; the trained image generation model is obtained by training the image generation model to be trained based on the reference sample image corresponding to the reference workpiece;

[0179] The second generating module 606 is used to obtain a defect detection result corresponding to the image to be detected according to the image difference between the image to be detected and the reference image.

[0180] In some embodiments, in terms of obtaining a defect detection result corresponding to the image to be detected according to the image difference between the image to be detected and the reference image, the second generating module 606 is specifically used to:

[0181] Acquire a first grayscale image corresponding to the image to be detected and a second grayscale image corresponding to the reference image;

[0182] Respectively obtaining pixel values ​​of the first grayscale image and the second grayscale image at each pixel position, and obtaining a binary image corresponding to the image to be detected according to the difference in pixel values ​​between the first grayscale image and the second grayscale image at the same pixel position;

[0183] Obtain the pixel value of each pixel position of the binary image; obtain the defect area in the image to be detected according to the area corresponding to the pixel position whose pixel value in the binary image meets the preset threshold condition; determine the defect detection result corresponding to the image to be detected according to the defect area.

[0184] Each module in the training device of the image generation model and the image defect detection device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module.

[0185] In some embodiments, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 7 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data involved in the training and application process of the image generation model. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the above-mentioned image generation model training method and image defect detection method are implemented.

[0186] In some embodiments, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 8As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the steps in the training method of the image generation model and the image defect detection method are implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen; the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0187] Those skilled in the art will understand that Figure 7 or Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0188] In some embodiments, a computer device is provided. The computer device includes a memory and a processor. The memory stores a computer program. When the processor executes the computer program, the steps in the above method embodiments are implemented.

[0189] In some embodiments, Fig. 9 The figure shows an internal structure diagram of a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0190] In some embodiments, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0191] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0192] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0193] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0194] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A training method for an image generation model, characterized in that: include: Acquire a reference sample image corresponding to the reference workpiece; Inputting the reference sample image into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image; Respectively obtaining pixel values ​​of the reference sample image and the reconstructed sample image at each pixel position; Determine the loss between the reference sample image and the reconstructed sample image according to the difference in pixel values ​​at the same pixel position between the reference sample image and the reconstructed sample image; Determining an update direction of model parameters of the image generation model to be trained according to an expected result corresponding to the loss, and updating the model parameters according to the update direction to obtain an updated image generation model; Re-inputting the reference sample image into the updated image generation model for processing until a trained image generation model is obtained; the trained image generation model is used to determine a defect detection result corresponding to the image to be detected based on a reference image generated by the image to be detected; The step of inputting the reference sample image into the image generation model to be trained for noise processing includes: A standardized noise distribution state is obtained, and according to the order of each noise addition processing round, real noise distribution parameters corresponding to each noise addition processing round are sampled from the standardized noise distribution state; and according to the real noise distribution parameters corresponding to each noise addition processing round, noise addition processing is performed on the reference sample image step by step to obtain a noisy sample image corresponding to the reference sample image after the target noise addition processing round.

2. The method according to claim 1, characterized in that The step of inputting the reference sample image into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image further includes: The predicted noise distribution parameters corresponding to each denoising process round are obtained, and the noisy sample image is denoised step by step according to the predicted noise distribution parameters corresponding to each denoising process round, so as to obtain a reconstructed sample image corresponding to the reference sample image after the target denoising process round.

3. The method according to claim 2, characterized in that The obtaining of predicted noise distribution parameters corresponding to each denoising process round includes: The noise prediction parameters of the image generation model to be trained are obtained, and according to the order of each denoising process round, the predicted noise distribution parameters corresponding to each denoising process round are determined from the noise prediction parameters.

4. The method according to claim 1, characterized in that: The obtaining of the standardized noise distribution state, sampling from the standardized noise distribution state according to the order of each noise adding process round to obtain the real noise distribution parameters corresponding to each noise adding process round, includes: Determine sampling configuration information corresponding to each of the noise adding processing rounds according to the order of each of the noise adding processing rounds, and each of the noise adding processing rounds samples the standardized noise distribution state according to the corresponding sampling configuration information to obtain a corresponding noise distribution state; According to the noise distribution states obtained by sampling corresponding to each of the noise adding processing rounds, the real noise distribution parameters corresponding to each of the noise adding processing rounds are calculated.

5. The method according to claim 1, characterized in that: Determining the update direction of the model parameters of the image generation model to be trained according to the expected result corresponding to the loss includes: In the current configuration environment, according to minimizing the loss, an expected result corresponding to the loss is obtained; According to the expected result, the updating direction of the model parameters of the image generation model to be trained is determined.

6. A method for detecting defects in an image, characterized in that: include: Acquire the image to be detected; Acquire a trained image generation model, input the image to be detected into the trained image generation model for noise processing, and obtain a reference image corresponding to the image to be detected; Obtaining a defect detection result corresponding to the image to be detected according to an image difference between the image to be detected and the reference image; The training process of the trained image generation model includes: Inputting the reference sample image into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image; Respectively obtaining pixel values ​​of the reference sample image and the reconstructed sample image at each pixel position; Determine the loss between the reference sample image and the reconstructed sample image according to the difference in pixel values ​​at the same pixel position between the reference sample image and the reconstructed sample image; Determining an update direction of model parameters of the image generation model to be trained according to an expected result corresponding to the loss, and updating the model parameters according to the update direction to obtain an updated image generation model; Re-inputting the reference sample image into the updated image generation model for processing until a trained image generation model is obtained; The step of inputting the reference sample image into the image generation model to be trained for noise processing includes: A standardized noise distribution state is obtained, and according to the order of each noise addition processing round, real noise distribution parameters corresponding to each noise addition processing round are sampled from the standardized noise distribution state; and according to the real noise distribution parameters corresponding to each noise addition processing round, noise addition processing is performed on the reference sample image step by step to obtain a noisy sample image corresponding to the reference sample image after the target noise addition processing round.

7. The method according to claim 6, characterized in that The obtaining, according to the image difference between the image to be detected and the reference image, a defect detection result corresponding to the image to be detected, comprises: Acquire a first grayscale image corresponding to the image to be detected and a second grayscale image corresponding to the reference image; Respectively obtaining pixel values ​​of the first grayscale image and the second grayscale image at each pixel position, and obtaining a binary image corresponding to the image to be detected according to the difference in pixel values ​​of the first grayscale image and the second grayscale image at the same pixel position; Obtain the pixel value of each pixel position of the binary image; obtain the defect area in the image to be detected according to the area corresponding to the pixel position whose pixel value in the binary image meets the preset threshold condition; determine the defect detection result corresponding to the image to be detected according to the defect area.

8. A training device for an image generation model, characterized in that: include: A first acquisition module, used to acquire a reference sample image corresponding to a reference workpiece; The first processing module is used to input the reference sample image into the image generation model to be trained for noise processing to obtain a reconstructed sample image corresponding to the reference sample image; and is also used to obtain a standardized noise distribution state, and sample from the standardized noise distribution state according to the order of each noise processing round to obtain the real noise distribution parameters corresponding to each noise processing round; and perform noise processing on the reference sample image step by step according to the real noise distribution parameters corresponding to each noise processing round to obtain a noisy sample image corresponding to the reference sample image after the target noise processing round; An updating module, used for respectively obtaining pixel values ​​of the reference sample image and the reconstructed sample image at each pixel position; Determine the loss between the reference sample image and the reconstructed sample image according to the difference in pixel values ​​at the same pixel position between the reference sample image and the reconstructed sample image; determine the update direction of the model parameters of the image generation model to be trained according to the expected result corresponding to the loss, and update the model parameters according to the update direction to obtain an updated image generation model; The first generation module is used to re-input the reference sample image into the updated image generation model for processing until a trained image generation model is obtained; the trained image generation model is used to determine the defect detection result corresponding to the image to be detected based on the reference image generated by the image to be detected.

9. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • DDPM-based semi-supervised power transformation equipment characterization defect detection method and system

    CN116309483A

  • Image data enhancement method, diffusion model training method and equipment

    CN117853388A