A condition-controllable image sample expansion method and system for surface defect detection

By using a conditionally controllable image sample augmentation method, and leveraging compressed sensing and diffusion models to generate defect images that meet quality standards, the problem of scarce negative samples and insufficient feature diversity in surface defect detection is solved, thereby improving the training stability and weak feature recognition capability of the model.

CN120525000BActive Publication Date: 2025-10-21HUNAN UNIV
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202511021599.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-24
Publication Date
2025-10-21
Estimated Expiration
2045-07-24

AI Technical Summary

Technical Problem

In surface defect detection, the scarcity of negative samples and the lack of feature diversity make data issues a major challenge for deep learning models.

Method used

A conditionally controllable image sample augmentation method is adopted. An image generation module is constructed by using a compressed sensing model and a diffusion model. Combined with a conditional coding module, a controllable defect image that meets quality standards is generated, including the defect shape, location and size.

Benefits of technology

It achieves high quality, diversity, and complete distribution of image generation, improves model training stability and the ability to discriminate downstream tasks, especially the ability to identify weak features.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120525000B_ABST
    Figure CN120525000B_ABST
Patent Text Reader

Abstract

A condition controllable image sample expansion method and system for surface defect detection, wherein the method comprises: collecting multiple negative sample and positive sample images, and constructing an image sample expansion model; inputting a template and an abnormal type into a condition coding module to obtain an output condition; an encoder compresses the negative sample image to a latent feature space, inputs the obtained latent space vector into a diffusion model and a decoder, combines the output condition, and obtains a reconstructed negative sample image; a total loss function and a diffusion loss function are constructed, and the two loss functions are minimized until a preset stopping condition is reached, and the model weight is adjusted during the training process; the model is deployed to a device end, a positive sample image is input, a controllable condition is designed, and corresponding samples are generated to realize image sample expansion. The present application realizes controllable region shape, size, position and type, can generate new samples according to the controllable condition, and provides a data basis for subsequent modeling.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of sample data expansion, and in particular to a conditionally controllable image sample expansion method and system for surface defect detection. Background Art

[0002] Intelligent inspection technology plays a key role in driving the intelligent transformation of manufacturing production lines. Automatic optical inspection equipment, leveraging high-precision cameras and advanced machine vision technology, can identify and remove defective products. It also optimizes production processes based on inspection feedback, significantly improving production efficiency. This has become a core strategy for companies to achieve high-end quality management and is widely used in precision manufacturing industries such as semiconductors, key automotive components, and aircraft engines. It is crucial for accelerating the intelligent and automated progress of enterprises.

[0003] In recent years, deep learning technology has achieved significant breakthroughs in numerous fields, including intelligent conversational systems (Chat GPT), protein structure prediction (AlphaFold), image generation (DALL E), and weather forecasting (Pangu Large Model). In the manufacturing industry, deep learning technology is also widely used in surface defect detection. Compared to traditional manual feature extraction algorithms that rely on human experience, deep learning uses models such as convolutional neural networks to automatically learn and extract deep and adaptable features from large amounts of data. This offers higher detection accuracy and generalization capabilities, making it a mainstream technology and future development direction for surface defect detection algorithms.

[0004] However, as a data-driven technology, the performance of deep learning models relies on sufficient and well-distributed datasets. In industrial production environments, negative samples (i.e., defective products) that do not meet quality standards are often scarce and lack feature diversity. Specifically, there are two main issues: 1) The number of negative samples is small. The pass rate of a production line is typically over 99.7%, resulting in the number of positive samples (i.e., qualified products) significantly exceeding the number of negative samples; and 2) The sample feature diversity is poor. Negative samples contain a variety of defect types, but the number of samples for each defect is limited, and it is even difficult to collect samples for certain defect categories. Data issues have become the biggest challenge in the implementation of deep learning in surface defect detection scenarios. Summary of the Invention

[0005] The present invention provides a conditionally controllable image sample expansion method and system for surface defect detection to solve the technical problems mentioned in the background technology.

[0006] To achieve the above object, the technical solution of the present invention is achieved as follows:

[0007] The present invention provides a conditionally controllable image sample expansion method for surface defect detection, comprising the following steps:

[0008] S1. Collect multiple negative sample images and positive sample images, and construct an image sample expansion model. The image sample expansion model includes an image generation module and a conditional coding module connected in sequence; the image generation module includes a compressed sensing model and a diffusion model connected in sequence; the compressed sensing model has a built-in encoder and decoder ;Diffusion model built-in denoising encoder;

[0009] S2. Input the template and the anomaly type into the conditional encoding module to obtain the output condition e; where the template contains the defect shape, location, and size, and the template and the anomaly type constitute the controllable condition;

[0010] S3, encoder in the image generation module Compress the negative sample image into the latent feature space to obtain the latent space vector , then the latent space vector Input into the diffusion model in the image generation module and combined with the output condition e of the conditional encoding module to obtain the reconstructed negative sample image;

[0011] S4, based on the latent space vector Encoder inside The output of is used to construct the total loss function of the encoder, and then the diffusion loss function is constructed based on the reconstructed negative sample image and the output condition e. The two loss functions are minimized in a loop from S2 to S4 until the preset stop condition is reached. The weights of the image sample expansion model are adjusted during the training process to obtain the trained image sample expansion model.

[0012] S5. Deploy the trained image sample expansion model to the device side, input the positive sample image, design controllable conditions, generate corresponding samples, and realize image sample expansion.

[0013] Another aspect of the present invention provides a conditionally controllable image sample expansion system for surface defect detection, including a computer device programmed to or executing the above-mentioned conditionally controllable image sample expansion method.

[0014] Beneficial effects of the present invention:

[0015] Compared with the existing technology, the present invention realizes the controllable shape, size, location and type of the region, can generate boundary samples according to quality standards, improves the sample distribution, and provides a data foundation for subsequent modeling. The advantages of the present invention are mainly reflected in the image generation quality, diversity, and distribution completeness:

[0016] 1) Image quality: Existing sample generation methods for surface defect detection are mostly based on autoencoders (AE) and generative adversarial networks (GAN). This paper constructs a conditionally controllable surface defect generation method based on a diffusion model, which improves the stability of model training and avoids the problem of mode collapse.

[0017] 2) Image Diversity: Existing sample generation algorithms only learn the distribution from collected images to construct a generative model. This generates samples closer to a sampling operation, introduces limited information, and makes it difficult to improve the sample distribution. This invention enables control over the shape, location, size, and type of abnormal regions. Furthermore, by introducing prior information and generating boundary samples based on industrial inspection standards, it improves the sample distribution. Given a limited dataset, this prior information increases the diversity of generated defect images, facilitating model training for downstream tasks.

[0018] 3) Distribution Completeness: In positive sample modeling methods for workpiece surface defect detection, boundary samples and samples that contain anomalies but do not affect image quality are scarce, which affects the completeness of the positive sample distribution. The proposed method improves the sample distribution by conditionally controlling the generation of boundary samples, enhancing the downstream task's ability to discriminate boundary samples with weak features (weak features typically refer to easily overlooked features such as small defect areas and light colors). BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 This is a structural diagram of the image sample expansion model in the present invention;

[0020] Figure 2 It is a structural block diagram of the denoising encoder in the present invention;

[0021] Figure 3 1 is a logic block diagram of the denoising encoder in the present invention;

[0022] Figure 4 Schematic diagram of new samples in an embodiment of the present invention; wherein the first row of figures are example figures of different templates; the second row of figures are images generated by the present invention respectively based on the different templates in the first row;

[0023] Figure 5 Figures for comparing experiments using various methods in the embodiments of the present invention are shown in rows (1) to (3), respectively, showing three different positive samples (g) and templates (h) obtained using different methods. From left to right, they are negative samples (a), AE-L1 (b), AE-SSIM (c), GAN (d), CycleGAN (e), negative samples (f) generated by the present invention, and positive samples (g) and templates (h). DETAILED DESCRIPTION

[0024] To facilitate understanding of the present invention, the present invention will be described more fully below with reference to the accompanying drawings. The accompanying drawings illustrate preferred embodiments of the present invention. However, the present invention may be implemented in many other forms and is not limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and comprehensive understanding of the disclosure of the present invention.

[0025] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of the technical features being referred to. Thus, a feature identified as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, "plurality" means two or more, unless otherwise specifically defined.

[0026] Reference Figure 1 The embodiment of the present application provides a conditionally controllable image sample expansion method for surface defect detection, comprising the following steps:

[0027] S1. Collect multiple negative sample images and positive sample images, and construct an image sample expansion model. The image sample expansion model includes an image generation module and a conditional coding module connected in sequence; the image generation module includes a compressed sensing model and a diffusion model connected in sequence; the compressed sensing model has a built-in encoder and decoder The diffusion model has a built-in denoising encoder. The conditional encoding module includes a sequentially connected residual network ResNet-50, a feature pyramid layer, and multiple fully connected layers.

[0028] S2. Input the template and the anomaly type into the conditional encoding module to obtain the output condition e; where the template contains the defect shape, location, and size, and the template and the anomaly type constitute the controllable condition;

[0029] S3, encoder in the image generation module Compress the negative sample image into the latent feature space to obtain the latent space vector , then the latent space vector Input into the diffusion model in the image generation module and combined with the output condition e of the conditional encoding module to obtain the reconstructed negative sample image; see the schematic diagram Figure 4 shown; Figure 4 The upper part is the template provided. Figure 4 The lower part is the new sample image formed by the corresponding template pair above;

[0030] S4, based on the latent space vector Encoder inside The output of is used to construct the total loss function of the encoder, and then the diffusion loss function is constructed based on the reconstructed negative sample image and the output condition e. The two loss functions are minimized in a loop from S2 to S4 until the preset stop condition is reached. The weights of the image sample expansion model are adjusted during the training process to obtain the trained image sample expansion model.

[0031] S5. Deploy the trained image sample expansion model to the device side, input the positive sample image, design controllable conditions, generate corresponding samples, and realize image sample expansion.

[0032] In some embodiments, the encoder Decoder is used to map images to latent space vectors Used to map the latent space vector to the image; the diffusion model includes a diffusion stage and a reverse diffusion stage. The diffusion stage maps the latent space vector to the image. The inverse diffusion stage is used to restore the data from the noise distribution to the original image distribution.

[0033] In some embodiments, reference Figure 2 The denoising encoder includes an input convolution layer, multiple cross-attention dimension reduction layers, downsampling dimension reduction layers, an intermediate layer, an upsampling dimension reduction layer, multiple cross-attention dimension raising layers, and an output convolution layer connected in sequence; wherein the multiple cross-attention dimension reduction layers and the downsampling dimension reduction layers are respectively connected to the multiple cross-attention dimension raising layers and the upsampling dimension reduction layers using jump connections; the multiple cross-attention dimension reduction layers, the downsampling dimension reduction layers, the intermediate layer, the upsampling dimension reduction layers, and the multiple cross-attention dimension raising layers are respectively connected to the conditional input e output by the conditional encoding module; in this embodiment, the input convolution layer and the output convolution layer use a 3×3 convolution kernel to adjust the dimensions of the input and output;

[0034] Among them, multiple cross-attention dimensionality reduction layers each include two residual blocks, two Transformer blocks, and a downsampling operation connected at the end, and multiple cross-attention dimensionality increase layers each include two residual blocks, two Transformer blocks, and a upsampling operation connected at the end; the residual blocks and Transformer blocks in multiple cross-attention dimensionality reduction layers and multiple cross-attention dimensionality increase layers are arranged in an alternating manner;

[0035] The middle layer consists of residual blocks, Transformer blocks and residual blocks connected sequentially.

[0036] In some embodiments, the step S2 specifically includes the following steps:

[0037] S21. Abnormal shape, abnormal size, abnormal location, and abnormal type are included as controllable conditions;

[0038] S22, generate corresponding templates through morphological operations on labels with abnormal shapes, sizes, and positions, and then input the corresponding templates into the residual network ResNet-50 in the conditional coding module to obtain multi-scale features, fuse the multi-scale features using the feature pyramid layer in the conditional coding module, and extract information through multiple fully connected layers to obtain spatial information. , the calculation formula is as follows:

[0039] ;

[0040] in, represents the conditional coding module; Represents a template;

[0041] S23. Transform the exception type through Bidirectional Encoder Representations from Transformers (BERT) to convert the text into word vectors to obtain type information ;

[0042] S24, spatial information With type information Combined to form the output condition e of the conditional encoding module, .

[0043] In some embodiments, S3 specifically includes the following steps:

[0044] S31, first the negative sample image Input to the image generation module, the variational encoder in the image generation module Negative sample images Compressed to the latent feature space, the latent space vector is obtained ; It is expressed by the formula as follows:

[0045] ;

[0046] S32, enter the diffusion stage, the diffusion model in the image generation module follows the Markov property to cyclically transfer the latent space vector Add random Gaussian noise to get the noise code ;

[0047] S33, enter the reverse diffusion stage, the diffusion model in the image generation module follows the Markov property to predict the noise coding Corresponding The mean of the Gaussian distribution at time and variance ;

[0048] S34, then based on the mean and variance And the output condition e of the conditional encoding module is calculated to obtain the latent space vector ;

[0049] S35. The latent space vector Input to decoder In the figure, we get the reconstructed negative sample image .

[0050] In some embodiments, the diffusion stage in S32 is represented by the following formula:

[0051] ;

[0052] Among them, q (.) represents the diffusion operation, represents the noise code at the t-1th time step; represents the total number of time steps, Indicates the Noise encoding of time steps; express Towards The diffusion process, The calculation formula is as follows:

[0053] ;

[0054] in, yes time steps The variance of , I represents the identity matrix; Represents a normal distribution.

[0055] In some embodiments, the reverse diffusion stage in S33 is expressed by the formula as follows:

[0056] ;

[0057] in, Indicates from The reverse diffusion operation;

[0058] The latent space vector in S34 The calculation formula is:

[0059] ;

[0060] in, In the reverse diffusion process, And under the conditions of output condition e, Probability of occurrence.

[0061] In some embodiments, reference Figure 3 , the S34 specifically includes the following steps:

[0062] S341, the output condition e of the conditional coding module is input into the denoising encoder, and the matrix, Matrix and The calculation formulas of the three matrices are as follows:

[0063] ;

[0064] ;

[0065] ;

[0066] in, Represents the intermediate layer representation within the denoising encoder; 、 、 Both are learnable projection matrices;

[0067] S342, then matrix, Matrix and The matrix is ​​input into the cross-attention module composed of multiple cross-attention dimension reduction layers and multiple cross-attention dimension increase layers to calculate the attention features. The cross-attention module is expressed by the formula as follows:

[0068] ;

[0069] Among them, Attention (.) represents the cross attention module, T represents transposition, represents the activation function;

[0070] S343, based on the attention characteristics, according to the mean and variance Calculate the latent space vector .

[0071] In some embodiments, the encoder in S4 The total loss function is as follows:

[0072] ;

[0073] in, Representation encoder total losses; represents the reconstruction loss, represents the KL divergence loss, and the reconstruction loss , KL divergence loss The calculation formulas are as follows:

[0074] ;

[0075] ;

[0076] in, is a given latent space vector The probability of reconstructing the data; is the latent space vector No. The mean of the dimensions, is the latent space vector No. The variance of the dimensions, is the latent space vector The dimension size of represents the average value; represents the posterior distribution; represents the prior distribution; z represents the negative sample image Noise coding; represents the posterior distribution and the prior distribution the distance between them;

[0077] The diffusion loss function is specifically as follows:

[0078] ;

[0079] in, represents the diffusion loss, represents the random Gaussian noise added in the diffusion stage, Is the negative sample image after the encoder The compressed latent vector, is the noise predicted by the compressed sensing model (i.e., U-Net network) at time step t; Represents the square of the 2-norm.

[0080] The following experiments verify the effectiveness of the present invention. We use a variety of comparison methods, including autoencoders (AE-L1 and AE-SSIM) and generative adversarial networks (GAN and CycleGAN) commonly used in the field of industrial image generation.

[0081] Evaluation criteria:

[0082] This paper uses three metrics: Peak signal-to-noise ratio (PSNR), Structural Similarity Index Measure (SSIM), and Fréchet Inception Distance (FID) to evaluate the visual fidelity of images and the performance of generative models.

[0083] SSIM: Structural Similarity Index is an indicator that measures the similarity between two images. It captures subtle differences between images by comparing brightness, contrast, and structural information. Its calculation formula is as follows:

[0084] ;

[0085] in, and Represents images and The mean of and Represents images and The standard deviation of is the covariance, and A small constant is introduced to stabilize the calculation. The SSIM value ranges from 0 to 1, where 1 indicates that the two images are completely identical. A higher SSIM indicates better image quality.

[0086] PSNR: Peak signal-to-noise ratio is an indicator of image reconstruction quality. It is usually used to evaluate the similarity between the generated image and the reference image. It is expressed in decibels (dB) and is calculated based on the mean square error (MSE) of the image. The formula is as follows:

[0087] ;

[0088] in, Represents the maximum possible value of an image pixel (for 8-bit images, ), MSE is calculated by the following formula:

[0089] ;

[0090] in, and Represent the pixel values ​​of the original image and the generated image respectively, and are the height and width of the image. A larger PSNR value indicates a higher quality of the generated image.

[0091] FID: It is used to measure the difference between the generated data distribution and the real data distribution. It is often used to evaluate the image quality of generative adversarial networks (GANs). FID first extracts features through the Inception network and then calculates the mean and covariance of the feature distribution. Its calculation formula is as follows:

[0092] ;

[0093] in, and Represents images respectively and The mean of and Represents images respectively and The covariance matrix of Indicates trace operation. The smaller the FID value, the and The higher the similarity, the better the image quality. Unlike SSIM and PSNR, FID considers the feature distribution of the entire image set and therefore has a better evaluation effect on the overall quality of the image set.

[0094] On the other hand, the quality of generated samples is evaluated through downstream tasks such as classification and segmentation. The main indicators include ROC-AUC, PR-AUC, Pixel-level ROC-AUC, IoU and F1. , , , Represents the number of true positive, false positive, true negative, and false negative samples or pixels, respectively. ROC-AUC refers to the area under the ROC curve, with the true positive rate (TPR) on the horizontal axis and the false positive rate (FPR) on the vertical axis.

[0095] ;

[0096] ;

[0097] PR-AUC refers to the area under the PR curve, and its horizontal axis is the accuracy , the vertical axis is the recall rate .

[0098] ;

[0099] ;

[0100] Pixel-level ROC-AUC is used to evaluate model performance at the pixel level. By comparing the detection results with the true segmentation labels, the corresponding TPR and FPR are calculated, and then the ROC curve is plotted and its area is calculated.

[0101] Image quality is a key metric for evaluating the visual quality and authenticity of generated samples. This paper presents generated images for subjective evaluation and uses quantitative metrics for objective evaluation. The comparison methods used include AE-L1, AE-SSIM, GAN, and CycleGAN, aiming to verify the image generation capabilities of the image sample augmentation model. The inputs of AE-L1, AE-SSIM, and GAN are negative samples of randomly masked image blocks, and the training objective is to achieve sample generation. CycleGAN, on the other hand, takes positive samples as input, and its training objective is to achieve the conversion from positive to negative samples.

[0102] like Figure 5 As shown in Table 1, the images generated by AE-L1, AE-SSIM, GAN, and CycleGAN all exhibit a certain degree of blur and distortion. AE-L1 and AE-SSIM both use an autoencoder architecture, and the SSIM loss function exhibits better performance than the L1 norm. Due to the poor stability of generative adversarial networks during training, the sample images generated by GAN and CycleGAN based on such networks have low clarity. In contrast, the images generated by the present invention have higher clarity, and their backgrounds remain consistent with the positive samples. New information elements are introduced, enabling precise control of the size, position, and shape of the generated images. Figure 5 A total of three sets of images obtained by different methods are shown.

[0103] The proposed method surpasses other comparison methods in both SSIM and PSNR, demonstrating its significant advantage in generating single image quality. Furthermore, its FID is lower than that of other methods, indicating that the proposed method better covers the feature distribution range of real samples and has greater diversity.

[0104] Table 1. SSIM, PSNR, and FID values ​​of scratch defect generated images using different generation methods;

[0105]

[0106] On the other hand, the present invention also provides a conditionally controllable image sample expansion system for surface defect detection, including a computer device, which is programmed to or executes the above-mentioned conditionally controllable image sample expansion method.

[0107] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or replacements within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. In addition, the technical solutions between the various embodiments of the present invention can be combined with each other, but it must be based on the ability of ordinary technicians in this field to implement. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the protection scope required by the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A conditionally controllable image sample expansion method for surface defect detection, characterized in that: The steps include: S1. Collect multiple negative sample images and positive sample images, and construct an image sample expansion model. The image sample expansion model includes an image generation module and a conditional coding module connected in sequence; the image generation module includes a compressed sensing model and a diffusion model connected in sequence; the compressed sensing model has a built-in encoder and decoder ;Diffusion model built-in denoising encoder; S2. Input the template and exception type into the conditional encoding module to obtain the output condition e; The template has the defect shape, location and size, and the template and the abnormality type constitute the controllable conditions; S3, encoder in the image generation module Compress the negative sample image into the latent feature space to obtain the latent space vector , then the latent space vector Input into the diffusion model in the image generation module and combined with the output condition e of the conditional encoding module to obtain the reconstructed negative sample image; S4, based on the latent space vector Encoder inside The output of is used to construct the total loss function of the encoder, and then the diffusion loss function is constructed based on the reconstructed negative sample image and the output condition e. The two loss functions are minimized in a loop from S2 to S4 until the preset stop condition is reached. The weights of the image sample expansion model are adjusted during the training process to obtain the trained image sample expansion model. S5. Deploy the trained image sample expansion model to the device, input the positive sample image, design controllable conditions, generate corresponding samples, and implement image sample expansion; The conditional encoding module consists of a sequentially connected residual network ResNet-50, a feature pyramid layer, and multiple fully connected layers; The denoising encoder includes an input convolution layer, multiple cross-attention dimension reduction layers, downsampling dimension reduction layers, an intermediate layer, an upsampling dimension reduction layer, multiple cross-attention dimension raising layers and an output convolution layer connected in sequence; wherein the multiple cross-attention dimension reduction layers and the downsampling dimension reduction layers are respectively connected to the multiple cross-attention dimension raising layers and the upsampling dimension reduction layers using jump connections; the multiple cross-attention dimension reduction layers, the downsampling dimension reduction layers, the intermediate layer, the upsampling dimension reduction layers and the multiple cross-attention dimension raising layers are respectively connected to the conditional input e output by the conditional encoding module; Among them, multiple cross-attention dimensionality reduction layers each include two residual blocks, two Transformer blocks, and a downsampling operation connected at the end, and multiple cross-attention dimensionality increase layers each include two residual blocks, two Transformer blocks, and a upsampling operation connected at the end; the residual blocks and Transformer blocks in multiple cross-attention dimensionality reduction layers and multiple cross-attention dimensionality increase layers are arranged in an alternating manner; The middle layer consists of residual blocks, Transformer blocks and residual blocks connected sequentially.

2. The conditionally controllable image sample expansion method for surface defect detection according to claim 1, characterized in that: The encoder Decoder is used to map images to latent space vectors Used to map the latent space vector to the image; the diffusion model includes a diffusion stage and a reverse diffusion stage. The diffusion stage maps the latent space vector to the image. The inverse diffusion stage is used to restore the data from the noise distribution to the original image distribution.

3. The conditionally controllable image sample expansion method for surface defect detection according to claim 1, characterized in that: The S2 specifically includes the following steps: S21. Abnormal shape, abnormal size, abnormal location, and abnormal type are included as controllable conditions; S22, generate corresponding templates through morphological operations on labels with abnormal shapes, sizes, and positions, and then input the corresponding templates into the residual network ResNet-50 in the conditional coding module to obtain multi-scale features, fuse the multi-scale features using the feature pyramid layer in the conditional coding module, and extract information through multiple fully connected layers to obtain spatial information. ; S23. The exception type is represented by a bidirectional encoder, and the text is converted into a word vector to obtain type information. ; S24, spatial information With type information Combined to form the output condition of the conditional coding module , .

4. The conditionally controllable image sample expansion method for surface defect detection according to claim 1, characterized in that: The S3 specifically includes the following steps: S31, first the negative sample image Input to the image generation module, the variational encoder in the image generation module Negative sample images Compressed to the latent feature space, the latent space vector is obtained ; S32, enter the diffusion stage, the diffusion model in the image generation module follows the Markov property to cyclically transfer the latent space vector Add random Gaussian noise to get the noise code ; S33, enter the reverse diffusion stage, the diffusion model in the image generation module follows the Markov property to predict the noise coding Corresponding The mean of the Gaussian distribution at time and variance ; S34, then based on the mean and variance And the output condition e of the conditional encoding module is calculated to obtain the latent space vector ; S35. The latent space vector Input to decoder In the figure, we get the reconstructed negative sample image .

5. The conditionally controllable image sample expansion method for surface defect detection according to claim 4, characterized in that: The diffusion stage in S32 is expressed by the formula as follows: ; Among them, q (.) represents the diffusion operation, represents the noise code at the t-1th time step; represents the total number of time steps, Indicates the Noise encoding of time steps; express Towards The diffusion process, The calculation formula is as follows: ; in, yes time steps The variance of , I represents the identity matrix; Represents a normal distribution.

6. The conditionally controllable image sample expansion method for surface defect detection according to claim 5, characterized in that: The reverse diffusion stage in S33 is expressed by the formula, which is as follows: ; in, Indicates from arrive The reverse diffusion operation; The latent space vector in S34 The calculation formula is: ; in, In the reverse diffusion process, And under the conditions of output condition e, Probability of occurrence.

7. The conditionally controllable image sample expansion method for surface defect detection according to claim 6, characterized in that: The S34 specifically includes the following steps: S341, the output condition e of the conditional coding module is input into the denoising encoder, and the matrix, Matrix and The calculation formulas of the three matrices are as follows: ; ; ; in, Represents the intermediate layer representation within the denoising encoder; 、 、 Both are learnable projection matrices; S342, then matrix, Matrix and The matrix is ​​input into the cross-attention module composed of multiple cross-attention dimension reduction layers and multiple cross-attention dimension increase layers to calculate the attention features. The cross-attention module is expressed by the formula as follows: ; Among them, Attention (.) represents the cross attention module, T represents transposition, represents the activation function; S343. Based on the characteristics of attention Based on the mean and variance Calculate the latent space vector .

8. The conditionally controllable image sample expansion method for surface defect detection according to claim 7, characterized in that: The encoder in the S4 The total loss function is as follows: ; in, Representation encoder total losses; represents the reconstruction loss, represents the KL divergence loss, and the reconstruction loss , KL divergence loss The calculation formulas are as follows: ; ; in, is a given latent space vector The probability of reconstructing the data; is the latent space vector No. The mean of the dimensions, is the latent space vector No. The variance of the dimensions, is the latent space vector The dimension size of represents the average value; represents the posterior distribution; represents the prior distribution; z represents the negative sample image Noise coding; represents the posterior distribution and the prior distribution the distance between them; The diffusion loss function is specifically as follows: ; in, represents the diffusion loss, represents the random Gaussian noise added in the diffusion stage, Is the negative sample image after the encoder The compressed latent vector, is the noise predicted by the compressed sensing model at time step t; Represents the square of the 2-norm.

9. A conditionally controllable image sample expansion system for surface defect detection, characterized in that: The method comprises a computer device, wherein the computer device is programmed to or executes the conditionally controllable image sample expansion method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Diffusion model-based text graph and diffusion model training method, device and equipment

    CN119169434A

  • Power equipment defect enhancement and generation method and system based on stable diffusion model

    CN119785143A

  • Infrared ship image controllable generation method for offshore scene

    CN119809946A

  • Remote sensing image ground object sample conversion method based on diffusion model

    CN120088650A