Training sample generation method, device and computer equipment based on diffusion model

By using the loss value update of the matching model and diffusion model in industrial defect detection, high-quality defect samples are generated, which solves the problem of insufficient sample generation quality in the prior art and improves sample generation efficiency and quality.

CN118445626BActive Publication Date: 2024-11-05SHENZHEN ZVIT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410904650.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-08
Publication Date
2024-11-05
Estimated Expiration
2044-07-08

AI Technical Summary

Technical Problem

The existing defect sample generation method based on diffusion model requires a large number of samples to be generated and the generation quality is insufficient, making it difficult to effectively expand the training data in industrial defect detection.

Method used

By selecting sample pairs with different categories, using the matching model and diffusion model to calculate the loss value for the model to update, generate a new sample pair corresponding to the original sample pair, and calculate the difference loss value through the difference function to update the model, and finally generate a high-quality wait Generate samples.

Benefits of technology

The efficiency and quality of defect sample generation is improved, the dependence on generated samples is reduced, and the quality of samples generated by diffusion model is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118445626B_ABST
    Figure CN118445626B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a method, device and computer equipment for generating training samples based on a diffusion model, which are applied to text image generation, wherein the method comprises: selecting first sample pairs of different categories based on an existing training sample set, then calculating corresponding label prediction loss values ​​based on a preset matching model and a diffusion model, and updating the matching model based on the loss value; then generating a second sample pair corresponding to the first sample pair based on the diffusion model, performing feature calculation based on the matching model and then calculating the difference loss value between the first sample pair and the second sample pair, then updating the matching model and the diffusion model based on the loss value, and then generating new generated samples for the samples to be generated based on the diffusion model that has completed the model update. The embodiment of the present invention can improve the quality and efficiency of defect sample generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of industrial defect detection, and in particular to a method, device and computer equipment for generating training samples based on a diffusion model. Background Art

[0002] In the process of industrial defect detection, the number of good products is often much larger than the number of defective products. In other words, the number of defective products is small, and defective products appear in various forms, which leads to a relatively long process of collecting defective products, and the number and form of defective products that can be collected are also very limited. The deep learning algorithm is based on a certain amount of data samples, so it is necessary to use defect generation methods to expand the collected data samples so that the training model can reach the accuracy level required by the customer. In the relevant technical solutions, the commonly used defect sample generation methods are based on probabilistic models such as GAN and autoencoders. At present, the diffusion model has been widely used in text image generation. However, the current process of expanding and generating defect samples based on the diffusion model requires a large number of samples to be generated, and the quality of sample generation has certain shortcomings. Summary of the invention

[0003] Based on this, it is necessary to propose a method, device and computer equipment for generating training samples based on a diffusion model to address the above problems.

[0004] In the first part of the present invention, a method for generating training samples based on a diffusion model is provided, the method comprising:

[0005] Selecting a first sample pair from a preset training sample set, the first sample pair comprising a first sample and a second sample, the first sample and the second sample corresponding to different categories;

[0006] Based on a preset matching model, the second sample and the corresponding second category label are input to calculate a first loss value; based on a preset diffusion model and a preset matching model, the second sample and the corresponding second category label are input to calculate a corresponding second loss value; a first target loss value is determined according to the first loss value and the second loss value, and the matching model is updated according to the first target loss value;

[0007] Based on the diffusion model, generating a second sample pair corresponding to the first sample pair according to the input of the first sample pair, wherein the second sample pair includes a third sample corresponding to the first sample and a fourth sample corresponding to the second sample; inputting the first sample pair and the second sample pair into the matching model and a preset difference function, calculating a second target loss value corresponding to the first sample pair and the second sample pair, wherein the second target loss value is used to represent a difference value between the first sample pair and the second sample pair; and updating the matching model and the diffusion model according to the second target loss value;

[0008] A sample to be generated is obtained, the sample to be generated is input into the diffusion model that completes the model update, and an output of the diffusion model is obtained as a target generated sample corresponding to the sample to be generated.

[0009] In the second part of the present invention, a training sample generation device based on a diffusion model is provided, the device comprising:

[0010] A sample pair acquisition module, configured to select a first sample pair from a preset training sample set, wherein the first sample pair includes a first sample and a second sample, and the first sample and the second sample correspond to different categories;

[0011] The first model updating module is used to input the second sample and the corresponding second category label based on the preset matching model to calculate the first loss value; input the second sample and the corresponding second category label based on the preset diffusion model and the preset matching model to calculate the corresponding second loss value; determine the first target loss value according to the first loss value and the second loss value, and update the matching model according to the first target loss value;

[0012] a second model updating module, configured to generate, based on the diffusion model and according to the first sample pair, a second sample pair corresponding to the first sample pair, the second sample pair including a third sample corresponding to the first sample and a fourth sample corresponding to the second sample; input the first sample pair and the second sample pair into the matching model and a preset difference function, calculate a second target loss value corresponding to the first sample pair and the second sample pair, the second target loss value being used to represent a difference value between the first sample pair and the second sample pair; and perform model updating on the matching model and the diffusion model according to the second target loss value;

[0013] The sample expansion module is used to obtain the sample to be generated, input the sample to be generated into the diffusion model that completes the model update, and obtain the output of the diffusion model as the target generated sample corresponding to the sample to be generated.

[0014] In the third part of the present invention, a computer device is provided, the computer device includes a memory and a processor, the memory has executable code, when the executable code is run on the processor to implement the above-mentioned method for generating training samples based on the diffusion model.

[0015] The embodiments of the present invention have the following beneficial effects:

[0016] After adopting the above-mentioned method, device and computer equipment for generating training samples based on the diffusion model, when defective sample expansion is required, a first sample pair of different categories can be selected based on the existing training sample set, and then the corresponding label prediction loss value is calculated based on the preset matching model and diffusion model, and the matching model is updated based on the loss value; then a second sample pair corresponding to the first sample pair is generated based on the diffusion model, and feature calculation is performed based on the matching model and the preset difference function, and then the difference loss value between the first sample pair and the second sample pair is calculated, and then the matching model and the diffusion model are updated based on the loss value. Then, for the samples to be generated, new generated samples are generated based on the diffusion model that has completed the model update. Among them, the samples generated by the diffusion model are evaluated for differences through the matching model, so that the quality of the samples generated by the diffusion model is higher, and no specific or large number of samples to be generated are required, thereby improving the efficiency and quality of defective sample generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] in:

[0019] Figure 1 A schematic diagram of a flow chart of a method for generating training samples based on a diffusion model in an embodiment;

[0020] Figure 2 is a structural schematic diagram of a training sample generating device based on a diffusion model in an embodiment;

[0021] Figure 3 The figure is a schematic diagram of the structure of a computer device for running the above-mentioned method for generating training samples based on the diffusion model in one embodiment. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0023] In this embodiment, a method for generating training samples based on a diffusion model is provided. Based on this method, a generation model with the diffusion model as the main body is generated, and the existing sufficient training data set is used to learn and update the matching model and the diffusion model respectively, so as to complete the model update of the matching model and the training model. Then, based on the diffusion model that has completed the model update, new sample data is generated by inputting the small sample data to be generated, thereby achieving the purpose of expanding the sample.

[0024] For details, see Figure 1 , a flow chart of the above-mentioned method for generating training samples based on the diffusion model is given, wherein the method includes the following steps:

[0025] S101: Sample pair acquisition step: selecting a first sample pair from a preset training sample set, the first sample pair comprising a first sample and a second sample, the first sample and the second sample corresponding to different categories;

[0026] S102: First model updating step: Based on a preset matching model, input the second sample and the corresponding second category label, and calculate the first loss value; Based on a preset diffusion model and a preset matching model, input the second sample and the corresponding second category label, and calculate the corresponding second loss value; Determine a first target loss value according to the first loss value and the second loss value, and update the matching model according to the first target loss value;

[0027] S103: A second model updating step: based on the diffusion model, according to the input of the first sample pair, generating a second sample pair corresponding to the first sample pair, the second sample pair including a third sample corresponding to the first sample and a fourth sample corresponding to the second sample; inputting the first sample pair and the second sample pair into the matching model and a preset difference function, calculating a second target loss value corresponding to the first sample pair and the second sample pair, the second target loss value being used to represent the difference value between the first sample pair and the second sample pair; updating the matching model and the diffusion model according to the second target loss value;

[0028] S104: Sample generation step: obtaining a sample to be generated, inputting the sample to be generated into the diffusion model that has completed the model update, and obtaining the output of the diffusion model as a target generated sample corresponding to the sample to be generated.

[0029] The specific implementation of each step is described in detail below.

[0030] In step S101, firstly, an existing data set needs to be obtained, which is a preset training sample set. This training sample set may not be a sample to be generated, but may be another existing data set. It contains multiple samples and the category label corresponding to each sample. Here, data under n categories needs to be selected as the training sample set. , is the subset corresponding to all samples of the i-th category (i-th category label).

[0031] Then in the training sample set In , two samples are randomly selected to form a sample pair for single model training (the first sample pair) ,in 1,n], 1,n] and , ; Here, the first sample pair Including the first sample and the second sample , and the first sample The corresponding first category label and the second sample The corresponding second category label are different.

[0032] In step S102, the matching model needs to be updated.

[0033] Specifically, in this embodiment, the matching model G is mainly used to calculate sample features and evaluate the differences between generated samples. The specific model structure of the matching model G can be any combination of common layers such as convolutional layers, batch normalization, and activation layers. This is not limited here.

[0034] Specifically, based on the preset matching model, the second sample and the corresponding second category label are input to calculate the first loss value; based on the preset diffusion model and the preset matching model, the second sample and the corresponding second category label are input to calculate the corresponding second loss value; the first target loss value is determined according to the first loss value and the second loss value, and the matching model is updated according to the first target loss value.

[0035] The calculation of the first loss value also includes the calculation of the gradient loss value. Based on the preset matching model, according to the second sample and the second category label corresponding to the second sample, the corresponding first loss value and gradient loss value are calculated. and the second category label Input into the matching model G and calculate the first predicted feature vector , the first predicted category vector ,Right now ,in, The feature dimension can be set as needed.

[0036] Then, based on the preset label loss function (Function used to predict label loss), calculate the corresponding first loss value , and, based on the preset gradient calculation function autograd, calculate the gradient loss value .

[0037] Furthermore, based on a preset diffusion model, a second intermediate sample is generated according to the second sample, and based on a preset matching model, a corresponding second loss value is calculated according to the second intermediate sample and the second category label. Input the diffusion model D to generate a second intermediate sample corresponding to the second sample ,Right now .

[0038] Then, the second intermediate sample and the second category label Input the matching model G to obtain the second intermediate sample The corresponding second prediction feature vector , the second predicted category vector ,Right now . According to the preset label loss function , calculate the second loss value based on the second predicted category vector .

[0039] Then, the overall loss value (first target loss value) in the first model update step in step S102 above is is determined based on the first loss value, the gradient loss value and the second loss value, for example, the first target loss value The first loss value , The sum of the three is .

[0040] Then we can use the target loss value The matching model G is updated to complete the model updating step in this stage.

[0041] In step S103, in the second model update step, it is necessary to complete the model update of the diffusion model D and the matching model G. In the specific implementation, based on step S102, it is necessary to generate a second sample pair corresponding to the first sample pair based on the diffusion model and according to the input of the first sample pair, the second sample pair includes a third sample corresponding to the first sample and a fourth sample corresponding to the second sample; the first sample pair and the second sample pair are input into the matching model and a preset difference function, and a second target loss value corresponding to the first sample pair and the second sample pair is calculated, the second target loss value is used to represent the difference value between the first sample pair and the second sample pair; the matching model and the diffusion model are updated according to the second target loss value.

[0042] Specifically, based on the diffusion model D, the first sample pair is input , generating a pair with the first sample The corresponding second sample pair , the second sample pair A third sample corresponding to the first sample is included and a fourth sample corresponding to the second sample That is to say, , Here, the core idea of ​​the diffusion model D is to define a Markov chain of diffusion steps, continuously add random noise to the data, and then learn the inverse diffusion process to construct new data samples from the noise. The diffusion model D here can adopt the diffusion model in the prior art and is not limited here.

[0043] Then the first sample pair and the second sample pair are input into the matching model and the preset difference function to calculate the second target loss value corresponding to the first sample pair and the second sample pair, where the second target loss value is used to represent the difference value between the first sample pair and the second sample pair. , calculate the first difference between the first sample and the third sample ,Right now .here, It can be any function or network combination for calculating the difference, and is not limited here.

[0044] The second sample Input the matching model G, and calculate a third loss value corresponding to the third sample based on the matching model G , and the fourth loss value corresponding to the fourth sample Specifically, the second sample pair is input into the matching model, and a third feature vector corresponding to the third sample is calculated. , the third predicted category label and the fourth eigenvector corresponding to the fourth sample and the fourth predicted class label ;Right now ,as well as .

[0045] According to the preset label loss function, the third loss value is calculated based on the third predicted category label , calculate the fourth loss value based on the fourth predicted category label .

[0046] The first sample The matching model G is input, and a second difference value between the first sample and the fourth sample and a third difference value between the second sample and the third sample are calculated based on the matching model G and a preset difference function. The first feature vector is calculated based on the first sample and the first category label. And calculate the second feature vector based on the second sample and the second category label According to the difference function , based on the second difference value between the first sample and the fourth sample , and the third difference value between the second sample and the third sample .

[0047] The overall loss in step S103 (second target loss value) is obtained by combining the first difference value, the second difference value, the third difference value, the third loss value and the fourth loss value. For example, for , , , The sum of, that is, .

[0048] Then, the matching model and the diffusion model are updated based on the second target loss value to complete the model update of the matching model and the diffusion model at this stage.

[0049] Furthermore, in this embodiment, it is necessary to repeat the above steps S101-S103, select sample pairs multiple times and perform iterative model updates multiple times, until the preset number of iterations is met or the first target loss value and / or the second target loss value is less than the preset loss value threshold, then the matching model and the diffusion model are updated and the training is terminated. Here, the matching model and the training model that have completed the model update and training can be used for subsequent sample generation.

[0050] S104: Sample generation step: obtaining a sample to be generated, inputting the sample to be generated into the diffusion model that has completed the model update, and obtaining the output of the diffusion model as a target generated sample corresponding to the sample to be generated.

[0051] In this step, for a given sample to be generated, each sample to be generated is input into the diffusion model D that has completed model training and updating, so as to obtain the output of the diffusion model D as the corresponding target generated sample, thereby achieving the purpose of sample expansion.

[0052] After adopting the above-mentioned method for generating training samples based on the diffusion model, when it is necessary to expand the samples, the above-mentioned method can be used to learn and train the matching model and the diffusion model through the existing training data set, and the matching model can be used to control the characteristics and difference values ​​between the samples, thereby improving the quality of the diffusion model training samples and greatly improving the quality and quantity of the generated samples.

[0053] Further, in this embodiment, see Figure 2 , and also provides a training sample generation device based on a diffusion model, the device comprising:

[0054] A sample pair acquisition module 101 is used to select a first sample pair from a preset training sample set, where the first sample pair includes a first sample and a second sample, and the first sample and the second sample correspond to different categories;

[0055] The first model updating module 102 is used to input the second sample and the corresponding second category label based on a preset matching model to calculate a first loss value; input the second sample and the corresponding second category label based on a preset diffusion model and a preset matching model to calculate a corresponding second loss value; determine a first target loss value based on the first loss value and the second loss value, and update the matching model based on the first target loss value;

[0056] The second model updating module 103 is used to generate a second sample pair corresponding to the first sample pair based on the diffusion model and according to the first sample pair, wherein the second sample pair includes a third sample corresponding to the first sample and a fourth sample corresponding to the second sample; input the first sample pair and the second sample pair into the matching model and a preset difference function, calculate a second target loss value corresponding to the first sample pair and the second sample pair, wherein the second target loss value is used to represent the difference value between the first sample pair and the second sample pair; and update the matching model and the diffusion model according to the second target loss value;

[0057] The sample expansion module 104 is used to obtain the sample to be generated, input the sample to be generated into the diffusion model that completes the model update, and obtain the output of the diffusion model as the target generated sample corresponding to the sample to be generated.

[0058] In an optional embodiment, the first model updating module 102 is further used to: based on a preset matching model, calculate the corresponding first loss value and gradient loss value according to the second sample and the first category label corresponding to the second sample.

[0059] In an optional embodiment, the first model updating module 102 is also used to: generate a second intermediate sample according to the second sample based on a preset diffusion model, and calculate a corresponding second loss value according to the second intermediate sample and the second category label based on a preset matching model.

[0060] In an optional embodiment, the first model updating module 102 is further used to: determine a first target loss value according to the first loss value, the gradient loss value and the second loss value; and update the matching model based on the target loss value.

[0061] In an optional embodiment, the first model updating module 102 is also used to: input the second sample and the second category label into the matching model to obtain a first prediction feature vector and a first prediction category vector corresponding to the second sample; calculate the corresponding first loss value based on the first prediction category vector according to a preset label loss function; calculate the corresponding gradient loss value based on the second sample and the first prediction feature vector according to a preset gradient calculation function.

[0062] In an optional embodiment, the second model updating module 103 is also used to: input the second sample into the diffusion model to generate a second intermediate sample corresponding to the second sample; input the second intermediate sample and the second category label into the matching model to obtain a second predicted feature vector and a second predicted category vector corresponding to the second intermediate sample; and calculate a second loss value based on the second predicted category vector according to a preset label loss function.

[0063] In an optional embodiment, the second model updating module 103 is further used to: calculate a first difference value between the first sample and the third sample according to a preset difference function; input the second sample pair into the matching model, and calculate a third loss value corresponding to the third sample and a fourth loss value corresponding to the fourth sample based on the matching model; input the first sample pair into the matching model, and calculate a second difference value between the first sample and the fourth sample and a third difference value between the second sample and the third sample based on the matching model; calculate a second target loss value according to the first difference value, the second difference value, the third difference value, the third loss value and the fourth loss value;

[0064] In an optional embodiment, the second model updating module 103 is further used to: input the second sample pair into the matching model, calculate the third feature vector and the third predicted category label corresponding to the third sample and the fourth feature vector and the fourth predicted category label corresponding to the fourth sample; calculate the third loss value based on the third predicted category label and calculate the fourth loss value based on the fourth predicted category label according to a preset label loss function.

[0065] In an optional embodiment, the second model updating module 103 is further used to: input the first sample pair into the matching model, calculate the first eigenvector and the second eigenvector based on the first sample pair and the first category label and the second category label; and calculate the second difference value between the first eigenvector and the fourth eigenvector, and the third difference value between the second eigenvector and the third eigenvector according to the difference function.

[0066] In an optional embodiment, the second model updating module 103 is further used to: when the first target loss value and / or the second target loss value is less than a preset loss value threshold, determine that the updating of the matching model and the diffusion model is completed.

[0067] Figure 3 FIG. 1 shows an internal structure diagram of a computer device that implements the above-mentioned method for generating training samples based on a diffusion model in an embodiment. The computer device may be a terminal or a server. Figure 3 As shown, the computer device includes a processor, a memory and a network interface connected via a system bus. The memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device stores an operating system and may also store a computer program. When the computer program is executed by the processor, the processor can implement the above method. The internal memory may also store a computer program. When the computer program is executed by the processor, the processor can implement the above method. Those skilled in the art can understand that Figure 3The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0068] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

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

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

Claims

1. A method for generating training samples based on a diffusion model, characterized in that: Applied to text image generation, the method comprises: Selecting a first sample pair from a preset training sample set, the first sample pair comprising a first sample and a second sample, the first sample and the second sample corresponding to different categories; Based on a preset matching model, the second sample and the corresponding second category label are input to calculate a first loss value; based on a preset diffusion model and a preset matching model, the second sample and the corresponding second category label are input to calculate a corresponding second loss value; a first target loss value is determined according to the first loss value and the second loss value, and the matching model is updated according to the first target loss value; Based on the diffusion model, generating a second sample pair corresponding to the first sample pair according to the input of the first sample pair, wherein the second sample pair includes a third sample corresponding to the first sample and a fourth sample corresponding to the second sample; inputting the first sample pair and the second sample pair into the matching model and a preset difference function, calculating a second target loss value corresponding to the first sample pair and the second sample pair, wherein the second target loss value is used to represent a difference value between the first sample pair and the second sample pair; and updating the matching model and the diffusion model according to the second target loss value; A sample to be generated is obtained, the sample to be generated is input into a diffusion model that completes model updating, and an output of the diffusion model is obtained as a target generated sample corresponding to the sample to be generated.

2. The method for generating training samples based on a diffusion model according to claim 1, characterized in that: The step of inputting the second sample and the corresponding second category label based on the preset matching model and calculating the first loss value further includes: calculating the corresponding first loss value and gradient loss value according to the second sample and the first category label corresponding to the second sample based on the preset matching model; The step of inputting the second sample and the corresponding second category label based on the preset diffusion model and calculating the corresponding second loss value further includes: generating a second intermediate sample according to the second sample based on the preset diffusion model, and calculating the corresponding second loss value according to the second intermediate sample and the second category label based on the preset matching model; The step of determining the first target loss value according to the first loss value and the second loss value, and updating the matching model according to the first target loss value, further includes: A first target loss value is determined according to the first loss value, the gradient loss value, and the second loss value; and the matching model is updated based on the target loss value.

3. The method for generating training samples based on a diffusion model according to claim 2, characterized in that: The step of calculating the corresponding first loss value and gradient loss value based on the preset matching model according to the second sample and the first category label corresponding to the second sample also includes: Inputting the second sample and the second category label into the matching model to obtain a first prediction feature vector and a first prediction category vector corresponding to the second sample; According to a preset label loss function, a corresponding first loss value is calculated based on the first predicted category vector; According to a preset gradient calculation function, a corresponding gradient loss value is calculated based on the second sample and the first predicted feature vector.

4. The method for generating training samples based on a diffusion model according to claim 3, characterized in that: The step of generating a second intermediate sample according to the second sample based on a preset diffusion model, and calculating a corresponding second loss value according to the second intermediate sample and the second category label, further includes: inputting the second sample into a diffusion model to generate a second intermediate sample corresponding to the second sample; Inputting the second intermediate sample and the second category label into the matching model to obtain a second prediction feature vector and a second prediction category vector corresponding to the second intermediate sample; According to a preset label loss function, a second loss value is calculated based on the second predicted category vector.

5. The method for generating training samples based on a diffusion model according to claim 1, characterized in that: The step of inputting the first sample pair and the second sample pair into the matching model and calculating the second target loss value corresponding to the first sample pair and the second sample pair further includes: Calculating a first difference value between the first sample and the third sample according to a preset difference function; Inputting the second sample pair into the matching model, and calculating a third loss value corresponding to the third sample and a fourth loss value corresponding to the fourth sample based on the matching model; Inputting the first sample pair into the matching model, and calculating a second difference value between the first sample and the fourth sample, and a third difference value between the second sample and the third sample based on the matching model; A second target loss value is calculated according to the first difference value, the second difference value, the third difference value, the third loss value and the fourth loss value.

6. The method for generating training samples based on a diffusion model according to claim 5, characterized in that: The step of inputting the second sample pair into the matching model and calculating a third loss value corresponding to the third sample and a fourth loss value corresponding to the fourth sample based on the matching model further includes: Input the second sample pair into the matching model, calculate a third feature vector and a third predicted category label corresponding to the third sample, and a fourth feature vector and a fourth predicted category label corresponding to the fourth sample; According to a preset label loss function, a third loss value is calculated based on the third predicted category label, and a fourth loss value is calculated based on the fourth predicted category label.

7. The method for generating training samples based on a diffusion model according to claim 6, characterized in that: The step of inputting the first sample pair into the matching model and calculating the second difference value between the first sample and the fourth sample and the third difference value between the second sample and the third sample based on the matching model further includes: Inputting the first sample pair into the matching model, and calculating a first feature vector and a second feature vector based on the first sample pair and the first category label; According to the difference function, a second difference value between the first eigenvector and the fourth eigenvector and a third difference value between the second eigenvector and the third eigenvector are calculated.

8. The method for generating training samples based on a diffusion model according to any one of claims 1 to 7, characterized in that: The method further comprises: When the first target loss value and / or the second target loss value is smaller than a preset loss value threshold, it is determined that the updating of the matching model and the diffusion model is completed.

9. A training sample generation device based on a diffusion model, characterized in that: Applied to text image generation, the device comprises: A sample pair acquisition module, configured to select a first sample pair from a preset training sample set, wherein the first sample pair includes a first sample and a second sample, and the first sample and the second sample correspond to different categories; The first model updating module is used to input the second sample and the corresponding second category label based on the preset matching model to calculate the first loss value; input the second sample and the corresponding second category label based on the preset diffusion model and the preset matching model to calculate the corresponding second loss value; determine the first target loss value according to the first loss value and the second loss value, and update the matching model according to the first target loss value; a second model updating module, configured to generate, based on the diffusion model and according to the first sample pair, a second sample pair corresponding to the first sample pair, the second sample pair including a third sample corresponding to the first sample and a fourth sample corresponding to the second sample; input the first sample pair and the second sample pair into the matching model and a preset difference function, calculate a second target loss value corresponding to the first sample pair and the second sample pair, the second target loss value being used to represent a difference value between the first sample pair and the second sample pair; and perform model updating on the matching model and the diffusion model according to the second target loss value; The sample expansion module is used to obtain the sample to be generated, input the sample to be generated into the diffusion model that completes the model update, and obtain the output of the diffusion model as the target generated sample corresponding to the sample to be generated.

10. A computer device, characterized in that: The computer device includes a memory and a processor, the memory has executable code, and when the executable code is run on the processor, the method for generating training samples based on the diffusion model as described in any one of claims 1 to 8 is implemented.