Defect detection sample generation method and device

By combining text-based graph models and graph-based graph models, defect detection samples are automatically generated and labeled, solving the problems of scarce defect samples and low labeling efficiency. This achieves efficient and automated defect detection sample generation and enhancement, improving the quality and diversity of training samples.

CN121544980APending Publication Date: 2026-02-17CHINA MOBILE GROUP JIANGSU +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511686480.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-18
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

The scarcity of defective samples and low annotation efficiency in existing technologies limit the acquisition of high-quality training samples, especially in the development of object detection algorithms, which makes it difficult to meet the needs of large-scale datasets.

Method used

By combining text-based graph models and graph-based graph models, defect detection samples are automatically generated and labeled. Iterative generation and sample enhancement are performed using sampling parameter sets and enhancement parameter sets to ensure the diversity and coverage of the generated samples. Finally, automatic labeling is performed using a target detection model.

Benefits of technology

It achieves efficient and automated generation of defect detection samples, significantly improves the ability to obtain high-quality training samples, and solves the problems of sample scarcity and low annotation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121544980A_ABST
    Figure CN121544980A_ABST
Patent Text Reader

Abstract

The invention provides a defect detection sample generation method and device, and the method comprises the steps: obtaining a sample generation request of a defect detection sample, determining a sampling parameter set of a text graph model according to the total amount of samples, inputting the sample generation request into the text graph model, and obtaining an initial defect detection sample set outputted by the text graph model; wherein the text graph model is used for performing iterative generation of defect detection samples based on the sampling parameter set; respectively inputting each initial defect sample in the initial defect sample set into a graph generation and drawing model for sample enhancement to obtain an enhanced defect sample set output by the graph generation and drawing model; the enhanced defect sample set is automatically labeled, target defect detection samples are constructed, and the number of the target defect detection samples is equal to the total number of the samples. Therefore, through combination of the text-to-graph model and the graph-to-graph model, the target defect detection samples which are sufficient in number and accurate in labeling can be constructed, and efficient and automatic generation of the defect detection samples is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a method and apparatus for generating defect detection samples. Background Technology

[0002] In the current field of object detection algorithm development, especially for tasks involving specific defect identification, the insufficiency of training samples has become a pressing problem. To overcome this challenge, traditional methods mainly rely on manually collecting large amounts of data. However, this method is limited by time and resources, and often fails to meet the needs of large-scale datasets.

[0003] The scarcity of defect samples is the primary manifestation of this problem. For example, potential defects in safety buckles, such as material fatigue, manufacturing flaws, wear, and cracks, are often minute and difficult to detect. In real-world usage environments, these defects occur infrequently and are diverse, making the collection of natural samples for each type of defect extremely difficult. Furthermore, deliberately creating or waiting for defects in safety buckles to occur for sample collection is not only impractical but also violates safety principles. Therefore, the number of defect samples obtained through field accidents or malfunctions is extremely limited. Even if defect samples are successfully collected, the labeling process faces challenges. Defect detection requires extremely high positioning accuracy and classification accuracy, which not only requires specialized knowledge but also consumes significant time and financial resources. Manual labeling is tedious and error-prone, especially when dealing with defects of complex and varied shapes, making it difficult to guarantee consistency in labeling.

[0004] In summary, existing technologies suffer from the problems of scarce defective samples and low annotation efficiency, which limit the acquisition of high-quality training samples. Summary of the Invention

[0005] This application provides a method and apparatus for generating defect detection samples to solve the technical problem in the prior art that the scarcity of defect samples and low annotation efficiency limit the acquisition of high-quality training samples.

[0006] To solve the above-mentioned technical problems, this application is implemented as follows:

[0007] In a first aspect, embodiments of this application provide a method for generating defect detection samples, the method comprising:

[0008] Obtain a sample generation request for defect detection samples, wherein the sample generation request includes the total number of defect detection samples to be generated;

[0009] Based on the total number of samples, the sampling parameter set of the textural graph model is determined, and the sample generation request is input into the textural graph model to obtain the initial defect detection sample set output by the textural graph model; wherein, the textural graph model is used to iteratively generate defect detection samples based on the sampling parameter set;

[0010] Each initial defect sample in the initial defect sample set is input into the graph-generated graph model for sample augmentation, resulting in the augmented defect sample set output by the graph-generated graph model.

[0011] The enhanced defect sample set is automatically labeled to construct target defect detection samples, wherein the number of target defect detection samples is equal to the total number of samples.

[0012] Optionally, the sampling parameter set includes at least one of the following: the adjustment amount of the classifier's free-guided scale parameter, the random seed parameter, and the noise reduction parameter sequence.

[0013] Optionally, if the sampling parameter set includes the adjustment amount of the classifier's free-guided scaling parameter, the sampling parameter set of the Wensheng graph model is determined based on the total number of samples, including:

[0014] Based on the total number of samples, the quality score and diversity score of the initial defect detection samples currently output by the Wensheng graph model, and the target quality score and target diversity score of the currently output initial defect detection samples, the adjustment amount of the classifier's free-guided scale parameter is determined.

[0015] The adjustment amount of the classifier's free-guided scale parameter is inversely proportional to the total number of samples.

[0016] Optionally, if the sampling parameter set includes the random seed parameter, the sampling parameter set of the Wensheng graph model is determined based on the total number of samples, including:

[0017] The total number of samples is hashed to obtain the random seed parameters.

[0018] Optionally, if the sampling parameter set includes the denoising parameter sequence, the sampling parameter set of the Wensheng image model is determined based on the total number of samples, including:

[0019] Based on the total sample size, the preset total diffusion steps, and the current time step generated by the iteration, the noise reduction parameter sequence is determined.

[0020] Optionally, each initial defect sample in the initial defect sample set is input into the graph-based model for sample augmentation, resulting in an augmented defect sample set output by the graph-based model, including:

[0021] Traverse the initial defect sample set to obtain each initial defect sample in the initial defect sample set;

[0022] The set of enhancement parameters for the graph-generated model is determined based on the total sample size.

[0023] The initial defect sample is input into the graph-generated graph model to obtain the enhanced defect sample set output by the graph-generated graph model, wherein the graph-generated graph model is used to iteratively generate enhanced defect samples based on the enhanced parameter set.

[0024] Optionally, the enhancement parameter set includes at least one of the following: noise reduction parameters and style intensity parameters; when the enhancement parameter set includes the noise reduction parameters, determining the enhancement parameter set of the graph-generated model based on the total number of samples includes:

[0025] The noise reduction parameters are determined based on the total sample size, the preset initial maximum noise reduction value, and the preset first proportional coefficient.

[0026] When the enhancement parameter set includes the style intensity parameter, determining the enhancement parameter set of the graph-generated model based on the total sample size includes:

[0027] The style intensity parameter is determined based on the total sample size, the noise reduction parameter, the current time step generated by the iteration, the preset initial style intensity value, and the preset second proportional coefficient.

[0028] Optionally, the enhanced defect sample set is automatically labeled to construct target defect detection samples, including:

[0029] Each enhancement defect sample in the enhancement defect sample set is input into the target detection model for automatic annotation, and the annotation information output by the target detection model is obtained.

[0030] The enhanced defect sample set and all the annotation information are stored in different directories to obtain the target defect detection sample.

[0031] Secondly, embodiments of this application provide an apparatus for generating defect detection samples, the apparatus comprising:

[0032] The acquisition module is used to acquire a sample generation request for defect detection samples, wherein the sample generation request includes the total number of defect detection samples to be generated;

[0033] An execution module is used to determine the sampling parameter set of the textural graph model based on the total number of samples, and input the sample generation request into the textural graph model to obtain the initial defect detection sample set output by the textural graph model; wherein, the textural graph model is used to iteratively generate defect detection samples based on the sampling parameter set;

[0034] Each initial defect sample in the initial defect sample set is input into the graph-generated graph model for sample augmentation, resulting in the augmented defect sample set output by the graph-generated graph model.

[0035] The enhanced defect sample set is automatically labeled to construct target defect detection samples, wherein the number of target defect detection samples is equal to the total number of samples.

[0036] Thirdly, embodiments of this application provide a network device, including: a processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, it implements the steps of the defect detection sample generation method as described in the first aspect.

[0037] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the defect detection sample generation method as described in the first aspect.

[0038] Fifthly, embodiments of this application provide a computer program product, including computer instructions, which, when executed by a processor, implement the steps of the defect detection sample generation method as described in the first aspect.

[0039] In this embodiment, by obtaining sample generation requests for defect detection samples, the total number of samples to be generated is determined. Based on this total number, the sampling parameter set of the graph-based model is determined for iterative generation of initial defect samples, ensuring the diversity and coverage of the generated samples. Subsequently, the initial defect sample set is input into the graph-based model for sample augmentation, further improving the diversity and complexity of the samples. Finally, the augmented defect sample set is automatically labeled, constructing a sufficient number of accurately labeled target defect detection samples. This solves the problems of sample scarcity and low labeling efficiency in traditional methods, achieving efficient and automated generation and augmentation of defect detection samples. Furthermore, the defect detection samples can be used for model training, significantly improving the ability to obtain high-quality training samples. Attached Figure Description

[0040] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:

[0041] Figure 1 A flowchart illustrating a method for generating defect detection samples provided in an embodiment of this application;

[0042] Figure 2 A flowchart illustrating a method for generating defect detection samples provided in an embodiment of this application;

[0043] Figure 3 A schematic diagram of a security buckle rust defect image generated from a textural model provided in this application embodiment;

[0044] Figure 4 A structural block diagram of a defect detection sample generation device provided in an embodiment of this application;

[0045] Figure 5 This is a structural block diagram of a network device provided in an embodiment of this application. Detailed Implementation

[0046] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0047] Figure 1 This paper illustrates a method for generating defect detection samples according to an embodiment of this application, such as... Figure 1 As shown, the method includes:

[0048] Step S101: Obtain the sample generation request for the defect detection sample;

[0049] The sample generation request includes the total number of defect detection samples to be generated.

[0050] Step S102: Based on the total number of samples, determine the sampling parameter set of the Wensheng image model, and input the sample generation request into the Wensheng image model to obtain the initial defect detection sample set output by the Wensheng image model;

[0051] Among them, the Wensheng graph model is used for iterative generation of defect detection samples based on the sampling parameter set;

[0052] Step S103: Input each initial defect sample in the initial defect sample set into the graph-based model for sample augmentation, and obtain the augmented defect sample set output by the graph-based model;

[0053] Step S104: Automatically label the enhanced defect sample set to construct the target defect detection sample;

[0054] The number of target defect detection samples is equal to the total number of samples.

[0055] The sampling parameter set includes at least one of the following: the adjustment amount of the classifier-free guidance scale (CFG Scale), the random seed parameter, and the noise reduction parameter sequence.

[0056] It should be noted that, Figure 1 This paper describes a complete method for automatically generating defect detection samples for defect detection tasks. First, a sample generation request is received, explicitly specifying the total number of defect detection samples required (i.e., the total sample size). Based on this total sample size, key generation settings of the text-based image model are configured, namely the sampling parameter set. This parameter set includes one or more parameters such as adjustments to the classifier's free-guided scale parameters to control the consistency between the generated content and the text description, random seed parameters to ensure the repeatability of the generation process, or a sequence of denoising parameters for fine-tuning the image denoising process. After setting the parameters, the generation request is input into the text-based image model, which generates an initial set of defect detection samples based on the sampling parameter set through a series of iterative steps.

[0057] Subsequently, to enhance data diversity, each sample in the initial defect sample set is fed into a graph-to-graph model for processing. The graph-to-graph model transforms and enhances the input image based on its own set of enhancement parameters, resulting in a larger or more comprehensive enhanced defect sample set. Finally, to ensure these generated images can be directly used to train the defect detection algorithm, an automatic annotation stage is implemented. This involves using a pre-trained object detection model to automatically analyze each sample in the enhanced defect sample set, identifying and annotating the location and category of defects. Ultimately, these annotated image data are properly stored to construct a directly usable target defect detection sample set, ensuring that its total number is exactly the same as the total number of samples specified in the initial request.

[0058] Figure 1The method described illustrates an automated sample generation and annotation process. Its core value lies in the orderly combination of the creative capabilities of text-based graph models, the scalability of graph-based graph models, and the annotation capabilities of object detection models. Through parameterized configuration (sampling parameter set, enhancement parameter set), the process is ensured to be controllable and the results reliable. Ultimately, it efficiently generates a precise and fully annotated defect detection sample set, providing a systematic solution to the problem of obtaining high-quality training data in fields such as industrial quality inspection.

[0059] In one possible implementation, when the sampling parameter set includes the adjustment amount of the classifier's free-guided scale parameter, the sampling parameter set of the Wensheng graph model is determined based on the total number of samples. This includes: determining the adjustment amount of the classifier's free-guided scale parameter based on the total number of samples, the quality score and diversity score of the initial defect detection samples currently output by the Wensheng graph model, and the target quality score and target diversity score of the initial defect detection samples currently output by the model; wherein the adjustment amount of the classifier's free-guided scale parameter is inversely proportional to the total number of samples.

[0060] It should be noted that when the sampling parameter set includes adjustments to the classifier's free-guided scale parameter, its determination process is a dynamic and goal-oriented decision. Specifically, the system needs to calculate the most suitable adjustment for the classifier's free-guided scale parameter based on the planned total number of samples and the gap between the actual performance of the initial defect detection samples currently output by the Wensheng graph model and the expected target.

[0061] This decision-making process comprehensively analyzes the total sample size, the specific quality scores and diversity scores obtained after evaluating the initial defect detection samples, and compares these actual scores with pre-set, desired target quality and diversity scores. Through this comprehensive consideration, the system can intelligently determine how to adjust the classifier's free-guided scaling parameter to make subsequent generated samples closer to the ideal target. It is particularly important to note that there is an inverse relationship between the adjustment amount of the classifier's free-guided scaling parameter and the total sample size. This means that when the total number of samples to be generated is large, the adjustment value is usually set smaller, and conversely, when the total sample size is small, the adjustment value may be increased accordingly.

[0062] This section elaborates on the key sampling parameters: how the adjustment amount of the classifier's freely guided scale parameter is intelligently and dynamically determined, thereby achieving refined and adaptive control of the text image model generation process as a whole, aiming to efficiently generate defect detection samples that simultaneously meet quality and diversity requirements.

[0063] In one possible implementation, when the sampling parameter set includes a random seed parameter, the sampling parameter set of the Wensheng graph model is determined based on the total number of samples by performing a hash operation on the total number of samples to obtain the random seed parameter.

[0064] It should be noted that when the sampling parameter set includes a random seed parameter, the strategy adopted is to directly perform a hash operation on the total number of defect detection samples to be generated as specified in the sample generation request.

[0065] Hash operations are unidirectional algorithms with a fixed output length. They map input data of arbitrary length—in this scenario, the total number of samples—to a seemingly random hash value of fixed length. This calculated hash value can be directly defined as the random seed parameter required by the Wensheng graph model. The random seed parameter plays a crucial role in the generation process of the Wensheng graph model because it is essentially the starting point or initial condition for all random number generators within the model. By setting a specific, fixed random seed parameter, it can be ensured that when the same total number of samples is used for generation, all the random choices within the Wensheng graph model—such as random noise patterns introduced during iterative denoising—follow the exact same sequence. This macroscopically guarantees that when the total number of samples is the same, the entire sample generation process and its final output have a high degree of reproducibility and determinism. Therefore, this provides a fundamental data guarantee for the large-scale, standardized, and traceable automated production of defect detection samples.

[0066] In one possible implementation, when the sampling parameter set includes a denoising parameter sequence, the sampling parameter set of the Wensheng graph model is determined based on the total number of samples, including: determining the denoising parameter sequence based on the total number of samples, the preset total diffusion steps, and the current time step generated by iteration.

[0067] It should be noted that when the sampling parameter set includes a denoising parameter sequence, the determination of this sequence is a dynamic computational process tightly coupled with the generation process. Specifically, it is not a fixed denoising parameter sequence pre-set, but is determined by three core elements: first, the macroscopic scale of the generation task, i.e., the total number of samples; second, a predefined total diffusion step that represents the level of detail in the entire denoising generation process, which specifies the total number of iterations required from the initial noise to the final clear image; and third, the current time step in the real-time process of iterative generation by the text-based image model.

[0068] The denoising parameter sequence is essentially a series of key values ​​used to control the denoising intensity and method of the Wensheng graph model in each iteration. The specific values ​​are directly dependent on the comprehensive consideration of the three factors mentioned above. The total number of samples affects the overall requirements for generation efficiency or quality. The preset total diffusion step provides a basic framework for the length and range of variation of the sequence, while the current time step generated in the iteration ensures that the parameter determination can respond in real time to the specific stage of the generation process. For example, in the early, middle, or late stages of the iteration, the denoising parameters may need to be adaptively adjusted according to the position of the current time step relative to the total diffusion step to achieve a more accurate and stable generation effect.

[0069] In one possible implementation, each initial defect sample in the initial defect sample set is input into the graph-based model for sample augmentation to obtain the augmented defect sample set output by the graph-based model. This includes: traversing the initial defect sample set to obtain each initial defect sample in the initial defect sample set; determining the augmentation parameter set of the graph-based model based on the total number of samples; and inputting the initial defect samples into the graph-based model to obtain the augmented defect sample set output by the graph-based model. The graph-based model is used for iterative generation of augmented defect samples based on the augmentation parameter set.

[0070] It's important to note that the process begins by iterating through the initial defect sample set, acquiring each initial defect sample in the set one by one as the basic unit for subsequent processing. Then, the set of enhancement parameters required by the graph-to-graph model is determined based on the initially specified total number of samples. This means the strength or characteristics of the enhancement process are related to the final number of samples required. Next, each acquired initial defect sample is independently input into the graph-to-graph model, which iteratively generates enhanced defect samples based on the determined set of enhancement parameters. This is a technique that uses existing images as conditions and gradually applies changes to create new samples. By performing the above operations on each initial defect sample, the graph-to-graph model ultimately outputs a scaled-up set of enhanced defect samples containing all the generated results.

[0071] Therefore, a traversal mechanism ensures that each sample is processed, and the enhancement parameter set is dynamically configured according to the overall goal (total number of samples). Ultimately, the model's iterative generation capability enables the diversified expansion of samples. This process is a key step in realizing the automated and large-scale construction of the defect detection sample library, significantly improving the richness and diversity of the samples.

[0072] In one possible implementation, the enhancement parameter set includes at least one of the following: denoising parameters and style intensity parameters; when the enhancement parameter set includes denoising parameters, determining the enhancement parameter set of the graph-generated model based on the total number of samples includes: determining the denoising parameters based on the total number of samples, a preset initial maximum denoising value, and a preset first scaling factor; when the enhancement parameter set includes style intensity parameters, determining the enhancement parameter set of the graph-generated model based on the total number of samples includes: determining the style intensity parameters based on the total number of samples, denoising parameters, the current time step generated by iteration, a preset initial style intensity value, and a preset second scaling factor.

[0073] It should be noted that the key parameters included in the enhancement parameter set used by the graph-to-graph model are at least one of the denoising parameters and style intensity parameters. When the enhancement parameter set needs to include denoising parameters, the system will determine the specific value of the denoising parameters through a specific calculation relationship based on the total number of defect detection samples to be generated, a pre-set initial maximum denoising value as an upper limit reference, and a first scaling factor that is also pre-set to adjust the scaling relationship.

[0074] When the enhancement parameter set needs to include style intensity parameters, its determination process becomes more complex and dynamic. It not only depends on the total number of samples but also requires comprehensive consideration of the calculated denoising parameter values, the real-time state of the graph-to-graph model during iterative sample enhancement (i.e., the current time step), a pre-defined baseline value for style influence (i.e., the initial style intensity value), and a pre-set second proportional coefficient specifically used to adjust the style intensity calculation relationship. All these factors work together to ultimately determine the value of the style intensity parameter. Therefore, by determining the enhancement parameter set, more refined control over the sample enhancement effect can be achieved.

[0075] In one possible implementation, the enhanced defect sample set is automatically labeled to construct the target defect detection sample, including: inputting each enhanced defect sample in the enhanced defect sample set into the target detection model for automatic labeling to obtain the labeling information output by the target detection model; storing the enhanced defect sample set and all the labeling information in different directories to obtain the target defect detection sample.

[0076] It's important to note that, firstly, the system inputs each enhanced defect sample from the enhanced defect sample set obtained through the graph-to-graph model into a pre-trained target detection model for processing. This model automatically identifies the specific location and category of defects in the image and outputs corresponding, standardized annotation information. Subsequently, the system performs a structured storage operation, separating all image data contained in the enhanced defect sample set from all annotation information generated by the target detection model for each sample in the previous step. These are stored separately in pre-planned, independent directories within the file system. This physical storage separation strategy ensures that image data and annotation information are independent and clearly correlated. Once this storage operation is complete, the final usable target defect detection sample containing image data and its corresponding standard annotation information is officially constructed. Thus, target defect detection samples that can be directly used to train the defect detection model can be obtained, significantly improving the ability to acquire high-quality training samples.

[0077] In summary, in this embodiment, by obtaining sample generation requests for defect detection samples, the total number of samples to be generated is determined. Based on this total number, the sampling parameter set of the graph model is determined for iterative generation of initial defect samples, ensuring the diversity and coverage of the generated samples. Subsequently, the initial defect sample set is input into the graph model for sample augmentation, further improving the diversity and complexity of the samples. Finally, the augmented defect sample set is automatically labeled, constructing a sufficient number of accurately labeled target defect detection samples. This solves the problems of sample scarcity and low labeling efficiency in traditional methods, achieving efficient and automated generation and augmentation of defect detection samples. Furthermore, the defect detection samples can be used for model training, significantly improving the ability to obtain high-quality training samples.

[0078] From the perspective of the application scenarios of the technical solution, the method for generating defect detection samples shown in the embodiments of this application is described in general. The key points of the solution are:

[0079] First, based on the text-based image prompts, the parameters of the text-based image K-sampler are automatically adjusted when generating images, resulting in an image set A1. Thus, by performing multiple sampling on the sampler, the sample size is enriched, and the generated content is less prone to homogenization.

[0080] Secondly, leveraging advanced text-to-image technology, such as ComfyUI + stable diffusion, a series of high-definition images containing various potential defects are automatically generated by setting defect type descriptions and typical scene characteristics through prompts. For example, setting a scenario of a safety buckle defect with rust, the prompt could be "Construction worker wearing a safety harness with visible signs of wear and rust on the buckle, illustrating the need for equipment inspection and maintenance." By setting the number of images generated per workflow execution, image width, and image height, and by repeatedly calling and adjusting the sampler's noise reduction parameters through the API (Application Programming Interface), a large number of complex and varied defect samples under different environments can be synthesized. This step fully utilizes the creative potential of artificial intelligence, overcoming the barriers of obtaining samples in reality to generate a large number of diverse defect sample images.

[0081] Subsequently, these initial synthetic images are further mutated and expanded using a graph-to-image algorithm. Defect areas are redrawn using a mask, and cue words are altered to simulate material wear, thereby increasing the richness and realism of the samples and ensuring the model can handle various complex and diverse detection needs. By repeatedly calling the API and adjusting the sampler's denoising parameters, smaller denoising parameters result in less change in the graph-to-image, achieving the effect of increasing data augmentation capacity.

[0082] Finally, the defect sample set with annotations is automatically generated. As mentioned earlier, a large number of defect samples are generated by calling the ComfyUI + stable diffusion model algorithm via API. Further, annotation results are automatically generated based on a cue word target detection algorithm. This is done by calling the GroundingDINO model algorithm via API, allowing input cue words (but not limited to defect targets), and generating annotated images and bounding box coordinates based on the cue words and the input defect sample materials. Finally, an image directory and an annotation directory can be generated according to the sample set requirements. The image directory contains all defect samples, and the annotation directory contains all annotation files. The annotation files contain, but are not limited to, image names, image sizes, bounding box coordinates, and categories.

[0083] Based on the above key points, the steps of the defect detection sample generation method shown in the embodiments of this application are as follows (refer to...). Figure 2 ):

[0084] Step 1: User sets text-to-image prompts

[0085] Based on the ComfyUI + stable diffusion model algorithm environment, users set text-based image prompts. The prompt content is set as a description of the defect type and typical scene characteristics. This method pre-sets 10 common defect scenes to choose from, including rusted safety buckles, cracked wood surfaces, cracked tile surfaces, fabric defects, cracked glass, car body paint, scratches on steel plates, abnormal solder joints on circuit boards, damaged packaging bags, and cracked tire surfaces. For example, to set the safety buckle rust defect scene, the prompt is "Construction worker wearing a safety harness with visible signs of wear and rust on the buckle, illustrating the need for equipment inspection and maintenance."

[0086] Step Two: Based on the text-to-image prompts, automatically adjust the parameters of the text-to-image generator to generate an image set A1 (e.g., ...). Figure 3 (As shown).

[0087] The system automatically calculates sampler parameters to generate diverse defect samples. In this crucial step, the system intelligently adjusts the sampler settings to ensure that each generated defect sample possesses unique characteristics. Subtle changes in the sampler parameters with each request result in different details being displayed in the plotting results, thus ensuring the richness and diversity of the sample library. This strategy not only improves the quality of the samples but also enhances the accuracy and reliability of subsequent analysis and processing.

[0088] It should be noted that the method shown in this application uses a K-sampler to progressively reduce noise and restore image details. The textural image model is based on a diffusion process, which involves a forward process and a reverse process. In the reverse process, the model progressively reduces noise and restores image details, a process that depends on different samplers. The K-sampler can generate high-quality images in fewer iterations. Parameters are flexible and controllable, supporting fine-tuning of the generation process and achieving a high degree of customization of the output image style. The method shown in this application intelligently adjusts the sampler parameters to generate diverse defect samples. Based on the total amount S of generated sample data required by the user, three sampler parameters are intelligently calculated: CFG Scale, random seed, and noise reduction parameters. Specifically:

[0089] (1) The CFG Scale parameter controls the balance between conditional generation and unconditional generation. A higher value will cause the generated defect sample image to follow the user-defined prompt words more closely.

[0090] First, some key metrics can be defined, such as the quality and diversity of the generated defective sample images, and target values ​​for these metrics. Then, the CFG Scale value is updated using a formula to bring it closer to the optimal value.

[0091]

[0092] An adjustment rule can be defined based on the quality Q of the generated defective image and the defect diversity D. Here, Q represents the quality score of the current image. Let represent the desired defective image quality score target, and D represent the diversity score of the current image. This represents the desired defect image diversity score objective. This represents the difference between the current quality score and the target quality score. If Q > 0. If the quality score is too high, the CFG Scale should be reduced; conversely, it should be increased. This represents the difference between the current defect diversity score and the target diversity score. If D < If the sample diversity is insufficient, the CFG Scale should be increased; otherwise, it should be decreased. This represents the image quality learning rate, used to adjust the degree of influence of the image quality score on the CFG Scale prompt words. The image diversity learning rate is used to adjust the influence of image diversity scores on CFG Scale prompts. As the total number of samples S increases, the adjustment amount of CFG Scale gradually decreases, thus maintaining a balance between defective sample diversity and image quality.

[0093] (2) The random seed parameter determines the initial state of the random number generator and has an important impact on the generated image. A strategy can be adopted to intelligently select the random seed.

[0094]

[0095] Here, hash(S) is a hash function used to map the total number of samples S to an integer value. The mod operator ensures that the seed value is within a reasonable range.

[0096] (3) The noise reduction parameters affect the clarity and detail of the defect image generated by the final large model. A high noise reduction value may cause the defect image to be too smooth and lose details, while a low noise reduction value may cause the defect image to be blurry. Therefore, it is necessary to dynamically adjust the formula to calculate the K sampler noise reduction parameters according to the quality and diversity of the image.

[0097] ;in This represents the denoising parameters at time step t, which affect the quality and detail of the generated image. T is the total number of diffusion steps, and its magnitude is directly related to the final sharpness and complexity of the image. K is an adjustment coefficient used to ensure... For a series that remains stationary throughout the entire time series, the calculation formula is:

[0098]

[0099] Where S is the total number of defect samples to be generated, the noise reduction parameter is used to control the noise level at each time step during the sampling process, and is a function that varies with the diffusion steps, and T is the total number of diffusion steps.

[0100] Step 3: Traverse the generated image set, automatically adjust the parameters of the image generator, and generate image set A2 based on the image generator.

[0101] This process iterates through the defect sample set A1 generated in the previous step using program code, automatically adjusts the graph generator parameters, and then calls the API of the generative large-scale model stable diffusion via HTTP (Hypertext Transfer Protocol) to generate defect samples, thereby further enhancing the defect data. Based on the total amount of generated sample data S required by the user, it intelligently calculates two key sampler parameters: noise reduction parameters and style intensity.

[0102] The denoising parameter affects the sharpness and detail of defective images generated from large model-generated raw images. A high denoising value may cause the raw image to change too smoothly, resulting in a loss of detail, while a low denoising value may lead to a blurry image. Therefore, as S increases, the change in the denoising parameter should be more gradual. A feasible approach is to define the change in the denoising parameter using an exponential decay form, which will ensure that the change in the denoising parameter becomes more gradual with increasing S. Assume the denoising parameter is... Its relationship with S can be defined as follows:

[0103]

[0104] As S increases, the noise reduction parameters The noise reduction parameters decay exponentially, resulting in increasingly gradual changes. These gradual parameter changes allow for a smoother transition during image generation, avoiding the image quality degradation or loss of detail that can occur with sudden, drastic changes. S represents the initial maximum denoising parameter value. In the early stages of image generation, a larger denoising parameter helps to quickly remove noise, while in later stages, smaller parameter changes help with fine-tuning and retain more detail. This gradual approach helps maintain image sharpness and detail throughout the generation process. k is a positive scaling factor used to control the rate at which the denoising parameter decreases as S increases. A gradual parameter change improves the stability of the generation process, allowing the model to learn the image distribution more steadily during iterations, thus generating higher-quality images. By controlling the decay rate of the denoising parameter, the image generation process can be better controlled to meet specific quality and diversity requirements.

[0105] Style strength describes the dynamic adjustment mechanism of style strength in tasks such as image generation or style transfer. The total amount of sample data S is added to the formula as a variable, which affects the style strength.

[0106]

[0107] The formula defines the style intensity as a function of time t and the noise reduction parameter. The total sample size S varies. In the generative framework of the diffusion model, noise is progressively added to the original image, and then the noise is progressively removed and the stylized image is gradually restored through a reverse process. The formula describes the dynamic adjustment mechanism of style intensity in the image generation task.

[0108] in, It is the initial style intensity, that is, when =0 and The style intensity value when =0. k is a constant coefficient used to adjust... The magnitude of its impact on the final style intensity. This describes the change in style intensity over time and with variations in denoising parameters. As time t decreases, noise in the image decreases, and style intensity gradually increases; while the denoising parameters... When the size is smaller, more noise is removed, resulting in a more distinct style, but details may be reduced; conversely, when the size is larger... It retains more detail, but the stylistic intensity may not be as strong. It is more noticeable when the size is smaller. The function depends only on the noise reduction parameters This describes the effect of noise on style intensity. Larger... It might help retain more detail, but the style might not be prominent enough; smaller It helps enhance the style, but may result in a loss of detail. The function depends only on time *t*, describing the change in style intensity over time. A smaller time *t*, implying a longer iteration time, tends to produce a stronger style effect; while a larger time *t*, implying a shorter iteration time, tends to preserve more of the original image features, resulting in a relatively weaker style intensity. Here, *c* is a positive scaling factor; as the number of samples increases, the style intensity also increases accordingly. This represents the style intensity contribution that changes as the total sample size S increases.

[0109] Step 4: Based on the image set in image set A2, automatically mark the defects and summarize the defect file and the annotation file.

[0110] Specifically, the annotation results are automatically generated using a large-scale model for target detection based on prompt words. The prompt words for the defect targets to be annotated are set; if it's a safety hook, it's set to "buckle". Using a single defect sample image and the prompt word as input, the grounding DINO API is called for automatic annotation. Further, a JSON file of the annotation results is generated, containing, but not limited to, image name, image size, bounding box coordinates, and category. This process is repeated for all defect images until all defect images are automatically annotated. Finally, all defect samples and annotation files are compiled into separate directories for defect sample images and annotation files. Images and annotation files have a one-to-one relationship, with the same filename but different file extensions.

[0111] In summary, by using a multimodal model combined with prompt word input to generate training sample materials for specified defect types in batches, and employing text-to-image and image-to-image methods to automatically generate controllable images, coupled with automatic annotation techniques to generate labeled data, the following problems are effectively solved:

[0112] Defect sample collection is challenging: Collecting a large number of defect samples for training is crucial when developing defect detection algorithms. To ensure the algorithm's accuracy and robustness, extensive training with numerous defect samples is necessary. By employing innovative text-to-image and image-to-image techniques, diverse and highly realistic defect samples are automatically generated, significantly improving sample collection efficiency.

[0113] Defect Sample Diversity: Text-based image generation technology allows for the automatic generation of corresponding images based on text descriptions, which greatly expands sample diversity. Various defect samples can be generated by describing different defect types, sizes, shapes, and backgrounds. Image-based image generation technology, on the other hand, can add or modify defect features based on existing images to generate new samples, ensuring both sample diversity and quality.

[0114] Sample annotation cost: To improve efficiency and reduce costs, a cue word-based object detection algorithm was used to automatically generate annotation results. Manual annotation is easily affected by subjective factors, leading to unstable annotation quality. Automated annotation through algorithms not only improves annotation speed but also ensures consistency and accuracy.

[0115] In summary, the defect detection sample generation method shown in this application can generate high-quality images in fewer iterations by adjusting the parameters of the K-sampler when generating images. Furthermore, the parameters are flexible and controllable, supporting fine-tuning of the generation process and enabling a high degree of customization of the output image style. It also significantly reduces the defect detection algorithm's reliance on on-site sample collection, improving model training efficiency and detection performance.

[0116] Figure 4 An apparatus for generating a defect detection sample according to an embodiment of this application is shown, such as Figure 4 As shown, the device 40 includes:

[0117] The acquisition module 401 is used to acquire the sample generation request of the defect detection sample, wherein the sample generation request contains the total number of defect detection samples to be generated;

[0118] The execution module 402 is used to determine the sampling parameter set of the text graph model based on the total number of samples, and input the sample generation request into the text graph model to obtain the initial defect detection sample set output by the text graph model; wherein, the text graph model is used to iteratively generate defect detection samples based on the sampling parameter set;

[0119] Each initial defect sample in the initial defect sample set is input into the graph-based model for sample augmentation, resulting in the augmented defect sample set output by the graph-based model.

[0120] The enhanced defect sample set is automatically labeled to construct the target defect detection sample, wherein the number of target defect detection samples is equal to the total number of samples.

[0121] In one possible implementation, the sampling parameter set includes at least one of the following: the adjustment amount of the classifier's free-guided scale parameter, the random seed parameter, and the noise reduction parameter sequence.

[0122] In one possible implementation, when the sampling parameter set includes the adjustment amount of the classifier free-guided scale parameter, the execution module 402 is further configured to determine the adjustment amount of the classifier free-guided scale parameter based on the total number of samples, the quality score and diversity score of the initial defect detection samples currently output by the Wensheng graph model, and the target quality score and target diversity score of the currently output initial defect detection samples; wherein the adjustment amount of the classifier free-guided scale parameter is inversely proportional to the total number of samples.

[0123] In one possible implementation, if the sampling parameter set includes a random seed parameter, the execution module 402 is further configured to perform a hash operation on the total number of samples to obtain the random seed parameter.

[0124] In one possible implementation, if the sampling parameter set includes a denoising parameter sequence, the execution module 402 is further configured to determine the denoising parameter sequence based on the total number of samples, the preset total diffusion steps, and the current time step generated by the iteration.

[0125] In one possible implementation, the execution module 402 is further configured to traverse the initial defect sample set, obtain each initial defect sample in the initial defect sample set; determine the enhancement parameter set of the graph-generated model based on the total number of samples; input the initial defect samples into the graph-generated model to obtain the enhanced defect sample set output by the graph-generated model, wherein the graph-generated model is used to iteratively generate enhanced defect samples based on the enhancement parameter set.

[0126] In one possible implementation, the enhancement parameter set includes at least one of the following: noise reduction parameters and style intensity parameters; if the enhancement parameter set includes noise reduction parameters, the execution module 402 is further configured to determine the noise reduction parameters based on the total number of samples, the preset initial maximum noise reduction value, and the preset first proportional coefficient.

[0127] When the enhancement parameter set includes the style intensity parameter, the execution module 402 is further configured to determine the style intensity parameter based on the total number of samples, the noise reduction parameter, the current time step generated by the iteration, the preset initial style intensity value, and the preset second scaling factor.

[0128] In one possible implementation, the execution module 402 is further configured to input each enhanced defect sample in the enhanced defect sample set into the target detection model for automatic annotation, thereby obtaining the annotation information output by the target detection model; and to store the enhanced defect sample set and all the annotation information in different directories to obtain the target defect detection sample.

[0129] In summary, in this embodiment, by obtaining sample generation requests for defect detection samples, the total number of samples to be generated is determined. Based on this total number, the sampling parameter set of the graph model is determined for iterative generation of initial defect samples, ensuring the diversity and coverage of the generated samples. Subsequently, the initial defect sample set is input into the graph model for sample augmentation, further improving the diversity and complexity of the samples. Finally, the augmented defect sample set is automatically labeled, constructing a sufficient number of accurately labeled target defect detection samples. This solves the problems of sample scarcity and low labeling efficiency in traditional methods, achieving efficient and automated generation and augmentation of defect detection samples. Furthermore, the defect detection samples can be used for model training, significantly improving the ability to obtain high-quality training samples.

[0130] This application provides a network device 50, such as... Figure 5 As shown, the network device 50 includes a processor 501, a memory 502, and a program stored in the memory 502 and executable on the processor 501. When the program is executed by the processor 501, it implements the steps of a method for generating a defect detection sample as shown in the above embodiment.

[0131] This application also provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the steps of a defect detection sample generation method as shown in the above embodiments, achieving the same technical effect. To avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0132] This application also provides a computer program product, including computer instructions. When executed by a processor, the computer instructions implement the steps of the defect detection sample generation method shown in the above embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0133] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0134] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0135] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A method for generating defect detection samples, characterized in that, The method includes: Obtain a sample generation request for defect detection samples, wherein the sample generation request includes the total number of defect detection samples to be generated; Based on the total number of samples, the sampling parameter set of the textural graph model is determined, and the sample generation request is input into the textural graph model to obtain the initial defect detection sample set output by the textural graph model; wherein, the textural graph model is used to iteratively generate defect detection samples based on the sampling parameter set; Each initial defect sample in the initial defect sample set is input into the graph-generated graph model for sample augmentation, resulting in the augmented defect sample set output by the graph-generated graph model. The enhanced defect sample set is automatically labeled to construct target defect detection samples, wherein the number of target defect detection samples is equal to the total number of samples.

2. The method according to claim 1, characterized in that, The sampling parameter set includes at least one of the following: the adjustment amount of the classifier's free-guided scale parameter, the random seed parameter, and the noise reduction parameter sequence.

3. The method according to claim 2, characterized in that, When the sampling parameter set includes the adjustment amount of the classifier's free-guided scale parameter, the sampling parameter set of the Wensheng graph model is determined based on the total number of samples, including: Based on the total number of samples, the quality score and diversity score of the initial defect detection samples currently output by the Wensheng graph model, and the target quality score and target diversity score of the currently output initial defect detection samples, the adjustment amount of the classifier's free-guided scale parameter is determined. The adjustment amount of the classifier's free-guided scale parameter is inversely proportional to the total number of samples.

4. The method according to claim 2, characterized in that, When the sampling parameter set includes the random seed parameter, the sampling parameter set for the Wensheng graph model is determined based on the total number of samples, including: The total number of samples is hashed to obtain the random seed parameters.

5. The method according to claim 2, characterized in that, When the sampling parameter set includes the noise reduction parameter sequence, the sampling parameter set of the text image model is determined based on the total number of samples, including: Based on the total sample size, the preset total diffusion steps, and the current time step generated by the iteration, the noise reduction parameter sequence is determined.

6. The method according to claim 1, characterized in that, Each initial defect sample in the initial defect sample set is input into the graph-based model for sample augmentation, resulting in an augmented defect sample set output by the graph-based model, including: Traverse the initial defect sample set to obtain each initial defect sample in the initial defect sample set; The set of enhancement parameters for the graph-generated model is determined based on the total sample size. The initial defect sample is input into the graph-generated graph model to obtain the enhanced defect sample set output by the graph-generated graph model, wherein the graph-generated graph model is used to iteratively generate enhanced defect samples based on the enhanced parameter set.

7. The method according to claim 6, characterized in that, The enhancement parameter set includes at least one of the following: noise reduction parameters and style intensity parameters; When the enhancement parameter set includes the noise reduction parameters, determining the enhancement parameter set of the graph-generated model based on the total number of samples includes: The noise reduction parameters are determined based on the total sample size, the preset initial maximum noise reduction value, and the preset first proportional coefficient. When the enhancement parameter set includes the style intensity parameter, determining the enhancement parameter set of the graph-generated model based on the total sample size includes: The style intensity parameter is determined based on the total sample size, the noise reduction parameter, the current time step generated by the iteration, the preset initial style intensity value, and the preset second proportional coefficient.

8. The method according to any one of claims 1-7, characterized in that, The enhanced defect sample set is automatically labeled to construct target defect detection samples, including: Each enhancement defect sample in the enhancement defect sample set is input into the target detection model for automatic annotation, and the annotation information output by the target detection model is obtained. The enhanced defect sample set and all the annotation information are stored in different directories to obtain the target defect detection sample.

9. A device for generating defect detection samples, characterized in that, The device includes: The acquisition module is used to acquire a sample generation request for defect detection samples, wherein the sample generation request includes the total number of defect detection samples to be generated; An execution module is used to determine the sampling parameter set of the textural graph model based on the total number of samples, and input the sample generation request into the textural graph model to obtain the initial defect detection sample set output by the textural graph model; wherein, the textural graph model is used to iteratively generate defect detection samples based on the sampling parameter set; Each initial defect sample in the initial defect sample set is input into the graph-generated graph model for sample augmentation, resulting in the augmented defect sample set output by the graph-generated graph model. The enhanced defect sample set is automatically labeled to construct target defect detection samples, wherein the number of target defect detection samples is equal to the total number of samples.

10. A network device, characterized in that, include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the steps of a method for generating a defect detection sample as claimed in any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of a method for generating a defect detection sample as described in any one of claims 1 to 8.

12. A computer program product, characterized in that, It includes computer instructions that, when executed by a processor, implement the steps of a method for generating a defect detection sample as described in any one of claims 1 to 8.