Image generation model training method, image generation method and related device
By introducing a diversity penalty term into the loss function of GAN and optimizing training based on the distance information between noise samples and image samples, the problem of GAN mode collapse is solved, the quality of image generation is improved, and the consumption of computing resources is reduced.
Patent Information
- Application Number
- CN202210625806.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-02
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-06-02
AI Technical Summary
Generative adversarial networks (GANs) are prone to mode collapse during the training process, resulting in insufficient diversity of generated images. Existing solutions mainly start from the model structure, which increases the consumption of computing resources and the complexity of model training.
By optimizing the loss function, a diversity penalty term is constructed based on the distance information and discriminant information of random noise samples and image samples, forcing the generator to generate different images when inputting similar noise, broadening the distribution pattern of the generated images, and reducing the gap between the generated images. Similarity.
It effectively solves the problem of mode collapse, improves the quality of image generation, reduces the consumption of computing resources, and achieves efficient image generation model training.
Smart Images

Figure CN115019128B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of deep learning technology, and in particular to an image generation model training method, an image generation method, and related devices. Background Art
[0002] Generative Adversarial Networks (GAN) is a deep learning model and one of the most promising methods for unsupervised learning on complex distributions in recent years. It has received widespread attention in areas such as image generation, image restoration, and image conversion.
[0003] A generative adversarial network (GAN) consists of a generator and a discriminator, which operate in an adversarial relationship. The discriminator learns to distinguish between real samples and fake samples generated by the generator, while the generator tricks the discriminator into believing that its own samples are real. As training progresses, the discriminator's ability to distinguish becomes increasingly stronger, and the samples generated by the generator become closer to real samples. However, the training freedom of GANs is too high, and the generator and discriminator can easily fall into an abnormal adversarial state, causing mode collapse, resulting in a lack of diversity in the generated images. In severe cases, all generated images are identical.
[0004] Currently, most solutions to the mode collapse problem start from the model structure. However, this solution will increase computing resource consumption and the complexity of model training due to model changes. Therefore, how to provide a streamlined and effective training method is a technical problem that needs to be solved. Summary of the Invention
[0005] One of the purposes of the present invention is to provide an image generation model training method, an image generation method and related devices to solve the problem of mode collapse and improve the quality of image generation.
[0006] In a first aspect, the present invention provides an image generation model training method, the method comprising: obtaining random noise samples and image samples; iteratively training an initial generative adversarial network based on the random noise samples and the image samples until a pre-constructed loss function reaches a set condition, and using the trained generative adversarial network as an image generation model; wherein the loss function is constructed based on distance information between generated images obtained from the random noise samples, discrimination information between the generated images and the image samples, and preset parameter information; the iterative training is used to reduce the similarity between the generated images.
[0007] In a second aspect, the present invention provides an image generation method, comprising: obtaining a random noise sample; inputting the random noise sample into an image generation model to generate a first image and a second image, wherein the first image and the second image are different; the image generation model is obtained by the image generation model training method provided in the first aspect.
[0008] In a third aspect, the present invention provides an image generation model training device, comprising: an acquisition module for acquiring random noise samples and image samples; a training module for iteratively training an initial generative adversarial network based on the random noise samples and the image samples until a pre-constructed loss function reaches a set condition, and using the trained generative adversarial network as an image generation model; wherein, in each iterative training, the loss function is constructed based on the distance information between the generated images obtained from the random noise samples, the discrimination information between the generated images and the image samples, and preset parameter information; the iterative training is used to reduce the similarity between the generated images.
[0009] In a fourth aspect, the present invention provides an image generation device, comprising: an acquisition module for acquiring a random noise sample; a generation module for inputting the random noise sample into an image generation model to generate a first image and a second image; the first image and the second image are different; the image generation model is obtained by the image generation model training method as described in the first aspect.
[0010] In a fifth aspect, the present invention provides an electronic device comprising a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and the processor can execute the computer program to implement the method as described in the first aspect or the method as described in the second aspect.
[0011] In a sixth aspect, the present invention provides a storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in the first aspect or the method described in the second aspect.
[0012] The present invention provides an image generation model training method, an image generation method, and related devices. The method comprises: obtaining random noise samples and image samples; iteratively training an initial generative adversarial network based on the random noise samples and the image samples until a pre-constructed loss function meets a set condition, and using the trained generative adversarial network as the image generation model; wherein the loss function is constructed based on distance information between generated images obtained from the random noise samples, discriminant information between the generated images and the image samples, and preset parameter information; and the iterative training is used to reduce the similarity between the generated images. Unlike the prior art approach of addressing mode collapse from the perspective of model structure, the present invention optimizes from the perspective of the loss function, constructing a model based on distance information between generated images obtained from the random noise samples, discriminant information between the generated images and the image samples, and preset parameter information, and training the model based on this loss function. The resulting model can generate different generated images for highly similar noise, increasing the distance between distribution modes corresponding to the generated images, thereby addressing the mode collapse problem. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.
[0014] Figure 1 Schematic diagram of mode collapse in GAN;
[0015] Figure 2 A structural block diagram of an electronic device provided by an embodiment of the present invention;
[0016] Figure 3 A schematic flowchart of constructing a loss function according to an embodiment of the present invention;
[0017] Figure 4 A schematic diagram of the effect of the loss function provided by an embodiment of the present invention;
[0018] Figure 5 A probability curve information diagram between the number of iterations and the balance factor provided by an embodiment of the present invention;
[0019] Figure 6 A schematic flowchart of an image generation model training method provided by an embodiment of the present invention;
[0020] Figure 7 An example diagram of the training method provided by an embodiment of the present invention;
[0021] Figure 8 A schematic diagram showing the effect of the training method provided by an embodiment of the present invention;
[0022] Figure 9 This is a test result diagram of the image generation model provided by an embodiment of the present invention;
[0023] Figure 10 A schematic flow chart of an image generation method provided by an embodiment of the present invention;
[0024] Figure 11 Functional modules of the image generation model training device provided in an embodiment of the present invention;
[0025] Figure 12 This is a functional module diagram of the image generation device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0026] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions of the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of 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. Generally, the components of the embodiments of the present invention described and shown in the drawings herein can be arranged and designed in various different configurations.
[0027] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention as claimed, but rather merely represents selected embodiments of the present invention. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of the present invention without creative effort shall fall within the scope of protection of the present invention.
[0028] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings.
[0029] In the description of the present invention, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. appear, the orientation or position relationship indicated is based on the orientation or position relationship shown in the accompanying drawings, or is the orientation or position relationship in which the product of the invention is usually placed when in use. It is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation. Therefore, it should not be understood as a limitation on the present invention.
[0030] In addition, the terms "first", "second", etc., if used, are merely used to distinguish and describe, and should not be understood as indicating or implying relative importance.
[0031] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.
[0032] Generative Adversarial Networks (GAN) is a deep learning model and one of the most promising methods for unsupervised learning on complex distributions in recent years. It has received widespread attention in areas such as image generation, image restoration, and image conversion.
[0033] Generative adversarial networks (GANs) consist of a generator and a discriminator. The generator's primary function is to capture the probability distribution of real samples and generate samples that resemble them, thereby confusing the discriminator. The discriminator, on the other hand, is responsible for distinguishing fake samples from real ones. During a specific iteration, when the parameters of one module are updated, the parameters of another module are fixed, and then backpropagation is performed to update the model parameters, alternating between the two.
[0034] Since its proposal, GAN has had two serious problems: training instability and mode collapse. In particular, the mode collapse problem is still the most difficult problem for GAN at this stage.
[0035] An important manifestation of mode collapse is that when similar noise samples are input, although they are not the same, the output images are still completely consistent. This phenomenon is particularly obvious when the noise changes are within a small range.
[0036] like Figure 1 As shown, Figure 1 This figure illustrates mode collapse in a GAN. When two random noises, N1 and N2, with a similarity of 91%, are input into the model, the generated images remain identical. This means that when the noise input to the generator varies within a certain range δ, the generated instances remain essentially unchanged. G(z) represents the image generated after the noise passes through the generator. This means that the generator can only cover a limited number of patterns. When faced with complex datasets, limited sample patterns can easily lead to incomplete pattern coverage, ultimately causing mode collapse and resulting in poor quality generated images.
[0037] That is to say, ideally the generator can learn all the pattern distributions in real samples, but this state is actually difficult to achieve. Usually, the generator can only capture part of the patterns in real samples, which will seriously affect the quality of image generation.
[0038] In order to solve the problem of mode collapse, related technologies have proposed the following solutions:
[0039] (1) Modifying the data processing mode is one way to solve the problem of mode collapse. A common method of this type is the Minibatch Discriminator Generative Adversarial Network (Minibatch GAN), which uses the correlation between data in multiple batches to enhance the discriminator's ability to distinguish between real data and generated data, thereby enabling the generator to capture more data patterns.
[0040] (2) Another way to alleviate mode collapse is to add additional discriminators and use multiple discriminators to improve the model's mode capture ability, such as the dual discriminator generative adversarial network (D2GAN). This model simultaneously trains two discriminators to minimize the Kullback-leibler (KL) divergence and the reverse KL divergence, thereby making the mode distribution more uniform. Training multi-generator models is also an important direction to solve mode collapse, such as the MGAN model that uses multiple generators. The use of multiple generators avoids the problem of insufficient fitting ability of a single generator when facing complex data sets. Using multiple generators and assisting a classifier to capture all distributions of real samples can alleviate the mode collapse problem to a certain extent, but the consumption of computing resources also increases to a certain extent.
[0041] (3) AE-OT-GAN theoretically proves that GAN has the problem of mode collapse based on the optimal transfer theory, and proposes to use a discontinuous optimal transfer graph to map the standard distribution of the input generator to a discontinuous distribution in the latent space. It also uses a joint model based on the autoencoder and GAN model, in which the autoencoder is responsible for mapping the real data to the latent space, and the GAN model uses the distribution in the latent space to generate new samples. This scheme also has a certain effect on alleviating mode collapse.
[0042] From the above solutions, we can conclude that most of the current methods to solve the mode collapse problem start from the model structure. However, this solution will increase computing resource consumption due to model changes and increase the complexity of model training. Therefore, how to provide a streamlined and effective training method is a technical problem that needs to be solved.
[0043] Therefore, an embodiment of the present invention provides a training method that solves the mode collapse problem from the perspective of loss function optimization, thereby improving the image generation quality. The idea of this training method is: when two similar noises N1 and N2 are input into the model, a diversity penalty constraint is added to the model to increase the distance between its generated results and force the model to not generate completely identical results.
[0044] Before introducing the training method provided by the embodiment of the present invention, an electronic device is first introduced. Figure 2, Figure 2 A structural block diagram of an electronic device provided in an embodiment of the present invention, wherein the electronic device can be the executor of the training method provided in an embodiment of the present invention, and can also be the executor of the image generation method provided in an embodiment of the present invention, and the electronic device can be, but is not limited to, a server, a mobile terminal, etc.
[0045] like Figure 2 As shown, electronic device 200 includes memory 201, processor 202, and communication interface 203. Memory 201, processor 202, and communication interface 203 are electrically connected to each other directly or indirectly to enable data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses or signal lines.
[0046] The memory 201 can be used to store software programs and modules, such as the instructions / modules of the image generation model training device 300 or the image generation device 400 provided in the embodiment of the present invention, which can be stored in the memory 201 in the form of software or firmware or solidified in the operating system (OS) of the electronic device 200. The processor 202 executes the software programs and modules stored in the memory 201 to perform various functional applications and data processing. The communication interface 203 can be used for signaling or data communication with other node devices.
[0047] Among them, the memory 201 can be, but is not limited to, random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0048] The processor 202 can be an integrated circuit chip with signal processing capabilities. The processor 202 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0049] I understand. Figure 2 The structure shown is for illustration only. The electronic device 200 may also include Figure 2 More or fewer components than shown, or with Figure 2 Different configurations shown. Figure 2 The components shown may be implemented in hardware, software, or a combination thereof.
[0050] Before introducing the training method provided by the embodiment of the present invention, we first introduce the method for constructing the loss function in the embodiment of the present invention. Figure 3 , Figure 3 A schematic flowchart of constructing a loss function provided in an embodiment of the present invention includes:
[0051] S31, constructing a distance information loss model according to the first generated image and the second generated image obtained from the random noise sample.
[0052] The first generated image is generated based on a random noise sample; and the second generated image is generated based on a random perturbation sample of the noise sample.
[0053] As Figure 1 As shown in FIG, since within a certain noise range, two noise samples with the same distribution pattern generate the same image, therefore, in the embodiment of the present invention, for two noise samples N1 and N2 with very high similarity (equivalent to the above-mentioned random noise sample and random perturbation sample), a diversity penalty constraint is added to the model, that is, a distance information loss model, which can increase the distance between the distribution patterns of the generated images corresponding to N1 and N2, forcing the model to not generate completely consistent results, such as Figure 4 As shown, Figure 4 A schematic diagram of the effect of the loss function provided in an embodiment of the present invention.
[0054] In an optional implementation manner, the diversity penalty constraint in the embodiment of the present invention, that is, the distance information loss model, may satisfy the following relationship:
[0055] Diversity=KL(G(z)||G(z+δ))
[0056] Among them, G(z) represents the first image generated by the generator after the random noise sample z passes through the generator, and G(z+δ) represents the second image generated by the generator after the random noise sample z is slightly perturbed by δ. δ represents the noise threshold. KL divergence (Kullback-Leibler Divergence) is used to measure the "distance" between the probability distribution functions of two samples.
[0057] It should be noted that the above-mentioned KL divergence can also be replaced by other types of divergence models, which are not limited here.
[0058] The working mechanism of the above diversity penalty term is: in the initial stage, the generation pattern of z and z+δ covers the area such as Figure 4 As shown in (a) in the figure, during the training process, the diversity penalty term will always focus on the distance between the sampling point z in the noise space and the generated samples in the z+δ region, and apply reverse gradient update power to the samples with overlapping generated patterns during the training process, so that the generated patterns corresponding to the noise interval gradually widen, and finally reach Figure 4 As shown in (b).
[0059] S32: Construct a discriminant information loss model according to the discriminant information of the first generated image and the image sample, and the first weight information.
[0060] In an embodiment of the present invention, the discriminant information is generated by the discriminator based on the first image and the image sample. In an optional implementation, the discriminant information loss model may satisfy the following relationship:
[0061]
[0062] Among them, Ez~Z[D(G(z))]-Ex~Pr[D(x)] is the basic loss of the GAN model, D(G(z)) represents the discriminant information of the first image; D(x) represents the discriminant information of the image sample; Z represents the distribution model of the random noise sample z; Pr represents the distribution model of the image sample; E represents the expectation; λ1, λ2 are the first weight information.
[0063] The above gradient penalty It is used to restrict the Lipschitz continuity of the discriminator in the distribution between generated data and real data. This continuity restriction makes the model meet the Kantorovich-Rubenstein duality requirement, thereby converting the calculation of the Wassertein optimal distance into the optimization problem of the generative adversarial network loss function. At the same time, it limits the gradient within a certain range, greatly reducing the occurrence of the gradient explosion problem and fundamentally alleviating the training instability problem of GAN. Satisfies the following relationship:
[0064]
[0065] Among them, the distribution The data points corresponding to the distribution Pg of the generated image move to Pr and are uniformly sampled on the straight line.
[0066] The above consistency penalty term CT| x′,x "" is used to limit the Lipschitz continuity of the discriminator on the real data distribution, so that the data distribution generated in the early stage of model training can be more quickly shortened to the distance from the real data distribution. At the same time, it also has a certain effect on improving the generation quality of the model and alleviating the mode collapse problem.
[0067] The above consistency penalty term CT| x′,x "Satisfies the following relationship:
[0068]
[0069] Among them, d(*,*) represents the calculation of the L2 norm, D(x′) and D(x″) are the discriminant information output by the discriminator after applying two perturbations of different degrees to the image sample x. The perturbation method of the data is to randomly dropout the hidden layer of the discriminator. When the dropout probability is very small, the output of the perturbed discriminator can be regarded as the output of the original discriminator for the data point x′ not far from x, and D(x′) is used to represent the discriminant information corresponding to x′. Then, the discriminant information D(x″) of the second data point x″ around x is found in the same way, and the value of M′ is set to 0. In actual experiments, it was found that restricting the penultimate layer D_(·) of the model can slightly improve the performance of the model, so two outputs D_(x′) and D_(x″) are added to the CT penalty term.
[0070] S33, constructing a loss function based on the distance information loss model, the second weight information corresponding to the distance information loss model, and the discriminant information loss model; or, constructing the loss function based on the distance information loss model, the second weight information corresponding to the distance information loss model, the discriminant information loss model, and the balance factor and random coefficient, constructing the loss function.
[0071] In one embodiment, the distance information loss model and the discriminant information loss model obtained in step S31 and step S32 are added together to obtain the loss function constructed in the embodiment of the present invention. The loss function can be expressed as equation (1):
[0072]
[0073] Here, λ3 represents the second weight information.
[0074] In another possible implementation, since pattern diversity and generation quality show contradictory trends to a certain extent, when sample diversity decreases, generation quality will show a certain increase, and when sample diversity increases, generation quality will show a certain downward trend. In order to balance sample diversity and generation quality, the present invention introduces a balance factor p, which can regulate the proportion of distance information loss mode and discriminant information loss model in the update process. When the balance factor increases, the proportion of diversity penalty terms will be increased, thereby increasing generation diversity. When the balance factor decreases, the proportion of basic loss terms will be increased, thereby improving the generation quality of the image. The specific working method of the balance factor is to perform a probability-based backpropagation update on the diversity penalty term in each iteration during the training process, and the probability value is adjustable, so as to achieve the purpose of controlling the proportion of the two losses in the update process.
[0075] The loss function obtained according to the above method can be expressed as the following equation (2):
[0076]
[0077] Where p represents the balance factor; μ represents the random coefficient, which satisfies the uniform distribution U(0, 1).
[0078] It should be noted that, in the actual model training process, the mode collapse problem in the prior art can be solved by using any loss function in the above relationship (1) or relationship (2).
[0079] In an optional embodiment, for the loss function shown in the above relation (2), the specific values of the balancing factor and the random coefficient may be determined in each iterative training process. Therefore, in a possible embodiment, the balancing factor and the random coefficient may be determined as follows:
[0080] In each iterative training, the value of the balance factor corresponding to each iterative training is determined according to the probability curve information between the preset number of iterations and the balance factor, and the random coefficient is obtained by random sampling from a preset distribution model.
[0081] See Figure 5 , Figure 5 The probability curve information diagram between the number of iterations and the balance factor provided by the embodiment of the present invention is based on Figure 5 , the balance factor corresponding to each number of iterations can be determined. The preset distribution model can be a uniform distribution model U(0, 1). Random sampling from the uniform distribution model can obtain a random coefficient.
[0082] Based on the loss function constructed above, the image generation model training method provided by the implementation of the present invention is introduced below.
[0083] See Figure 6 , Figure 6 This is a schematic flow chart of the image generation model training method provided by the embodiment of the present invention. The execution subject of this method can be Figure 2 The electronic device shown, the method includes:
[0084] S601: Obtain random noise samples and image samples.
[0085] Among them, the random noise sample can satisfy the preset Gaussian distribution model. In one possible implementation, a Gaussian distribution model can be determined first, such as a Gaussian distribution N(0,1) with a mean of 0 and a variance of 1. Random sampling from N(0,1) can obtain a random noise sample. The random noise sample is subsequently characterized by z in the embodiment of the present invention.
[0086] The above-mentioned image sample can be any real image obtained from an image dataset. In the embodiment of the present invention, x is used to represent the image sample.
[0087] S602, iteratively training the initial generative adversarial network based on the random noise samples and the image samples until the pre-built loss function meets the set conditions, and using the trained generative adversarial network as the image generation model;
[0088] Among them, the above-mentioned generative adversarial network has a generator and a discriminator. During the training process, the network parameters of the discriminator can be fixed, and the network parameters of the generator can be updated based on the loss value of the loss function constructed in the embodiment of the present application until the set conditions are reached.
[0089] In the embodiment of the present invention, the setting condition may be that the loss function is in a convergence state, or that the number of iterations reaches a preset number of iterations, which is not limited here.
[0090] The above-mentioned loss function is constructed based on the distance information between the generated images obtained based on the random noise samples, the discrimination information of the generated images and the image samples, and the preset parameter information, wherein the generated images are generated by the generator. In an embodiment of the present invention, after inputting the above-mentioned random noise samples into the generator, the generated images can be obtained, and the generated images and the image samples are input into the discriminator to obtain the discrimination information.
[0091] It can be understood that in the process of constructing the loss function, the distance information between the generated images and the discrimination information between the generated images and the image samples are used. During the iterative training process, the loss function is optimized through the distance information and the discrimination information, and the network parameters of the generator are continuously updated based on the loss value of the loss function, so that the generator can gradually reduce the similarity between the generated images, so that the generated images are generated in an increasingly different trend, and the distance between the distribution patterns corresponding to the generated images is widened, thereby solving the pattern collapse problem.
[0092] In an optional implementation, to facilitate understanding of the above training process, step S602 provided in this embodiment of the present invention may include:
[0093] Step 1: Input a random noise sample into the generator to obtain a first generated image and a second generated image;
[0094] Step 2: Input the first generated image and the image sample into the discriminator to obtain discriminant information;
[0095] Step 3: inputting the distance information of the first generated image and the second generated image into the distance information loss model, and inputting the discrimination information into the discrimination information loss model to obtain the loss value of the loss function;
[0096] Step 4: Keep the network parameters of the discriminator fixed and update the network parameters of the generator based on the loss value;
[0097] Step 5: When the set conditions are not met, return to the step of inputting the random noise sample into the generator to obtain the first generated image and the second generated image, until the loss function reaches the set conditions, and use the trained generative adversarial network as the image generation model.
[0098] In an optional embodiment, in order to obtain the first generated image and the second generated image, the above step 1 may include the following steps:
[0099] A1, determine the noise threshold.
[0100] In an optional embodiment, in order to maximize the benefits of the diversity penalty term, it is necessary to determine a noise threshold δ to limit the penalty term to only be effective for noise within the sampling point threshold range, and then determine the random perturbation sample corresponding to the random noise sample based on the noise threshold, and obtain the second generated image.
[0101] An implementation method for determining a noise threshold is given below, which may include the following steps:
[0102] A1-1, randomly sampling from a preset data distribution model to obtain multiple random values, and according to each random value, obtaining each random disturbance sample corresponding to the random noise sample;
[0103] A1-2, according to the generator, obtain the generated image corresponding to the random noise sample and the generated image corresponding to each random perturbation sample;
[0104] A1-3, determine the similarity between the generated image corresponding to the random noise sample and the generated image corresponding to each random perturbation sample;
[0105] A1-4, the generated image with the minimum similarity is determined as the target generated image, and the random value corresponding to the target generated image is determined as the noise threshold.
[0106] In an optional embodiment, the embodiment of the present invention can randomly sample a sample z from a distribution obeying N(0,1) and input the model to obtain the first generated image Fake1 = G(z). Then, a perturbation noise δ is randomly sampled from a distribution obeying N(0,x), where x is a real number greater than 0. The perturbation noise δ is added to the clean input z to obtain the perturbation input z+δ. This perturbation input is then input into the generator to obtain the perturbation to obtain the second generated image Fake2 = G(z+δ). Therefore, it is only necessary to observe the changing trend of the generator output as the perturbation noise δ changes, and then compare the similarity between the generated images Fake1 and Fake2 to determine the noise critical value of the generation mode change, thereby determining the threshold δ of the perturbation noise. The present invention designs a comparative experiment to explore the noise threshold δ. The experiment uses the trained generator G as the basic model, sets Fake1 = G(z), Fake2 = G(z+δ), tests the degree of influence of a series of x values on the difference between the outputs Fake1 and Fake2, and ultimately determines the threshold δ.
[0107] A2, based on the noise threshold, determines the random perturbation sample of the random noise sample.
[0108] A3, obtain a first generated image based on the random noise sample, and obtain a second generated image based on the random perturbation sample.
[0109] See Figure 7 , Figure 7This is an example diagram of the training method provided by an embodiment of the present invention. In each training process, some random noise z is first input to the GAN generator to output Fake1=G(z) and Fake1=G(z+δ), where G(z) represents the generated image after the random noise z passes through the generator, and δ is a noise threshold, indicating a slight disturbance. The first image and the second image can be as follows Figure 8 As shown, Figure 8 This is a schematic diagram of the training method provided by an embodiment of the present invention. The distance information corresponding to the generator's outputs Fake1 = G(z) and Fake2 = G(z+δ) can be used to optimize the loss function, increasing the distance between Fake1 and Fake2. This forces the generator to not generate completely identical results when similar noise is input, thereby avoiding mode collapse. Simultaneously, Fake1 is fed into the discriminator along with the real image for discrimination. The generator and discriminator compete with each other in a reciprocating cycle, generating high-quality images under the influence of the diversity penalty mechanism.
[0110] The present invention uses two quantitative measurement methods to evaluate the method: Inception Score (IS) and Fréchet Inception Distance (FID). IS measures sample quality and diversity by finding the predicted label entropy; higher IS indicates better model performance. FID evaluates the generation effect by calculating a "distance value" by comparing the generated image with the real image. It measures the similarity between real and fake samples by fitting a multivariate Gaussian (MVG) model to their intermediate representations. For FID, the lower the score, the better the model performance.
[0111] Table 1 shows the IS and FID scores of the proposed training method on the CIFAR-10 dataset, along with the scores of some common GAN models. It can be seen that the proposed training method offers some improvement over the CT-GAN model, achieving state-of-the-art results. More importantly, while achieving even better results, it also saves a significant amount of additional computing power.
[0112] Table 1 Comparison of IS scores of different models on the CIFAR-10 dataset
[0113]
[0114] In order to intuitively observe the effect of the improved loss function of the present invention in alleviating mode collapse, it is assumed that the model inputs two noises N1 and N2 to obtain a generated image, where N2 = N1 + δ, and then compares the difference between the corresponding generated images G(N1) and G(N2).
[0115] Figure 9This is a test effect diagram of the image generation model provided by an embodiment of the present invention, showing a comparison diagram of the generation effect when the diversity penalty term is applied to the CIFAR-10 dataset training. Figure 9 (a) is the image generation effect of the existing technology. Figure 9 (b) shows the image generation effect using the training method provided by an embodiment of the present invention. The upper image is the first generated image corresponding to G(N1), and the lower image is the second generated image corresponding to G(N2). From the comparison results, it can be seen that for the existing technology, the generated images G(N1) and G(N2) are very close, and there is no obvious pattern change between the two. However, for the optimization method with added diversity penalty, a clear pattern difference can be seen between G(N1) and G(N2), proving that the diversity penalty does indeed broaden the generated patterns within the noise threshold range, achieving the purpose of enhancing the model's resistance to pattern collapse.
[0116] Based on the image generation model obtained above, the embodiment of the present invention also provides an image generation method, see Figure 10 , Figure 10 A schematic flow chart of an image generation method provided in an embodiment of the present invention, the method comprising:
[0117] S701, obtaining a random noise sample;
[0118] S702 , inputting a random noise sample into an image generation model to generate a first image and a second image, wherein the first image and the second image are different.
[0119] In the embodiment of the present invention, the first generated image and the second generated image are different, which can also be understood as the first generated image and the second generated image are not similar, that is, the similarity between the two is less than the similarity threshold; the similarity threshold can be used to measure the similarity between the two, and the similarity threshold can be customized according to actual conditions. The smaller the similarity threshold, the less similar the two are.
[0120] The above-mentioned image generation model is obtained through the image generation model training method provided by the embodiment of the present invention.
[0121] See Figure 11 , Figure 11 This is a functional module diagram of an image generation model training device provided by an embodiment of the present invention. The image generation model training device 300 includes:
[0122] An acquisition module 310 is configured to acquire random noise samples and image samples;
[0123] A training module 320 is configured to iteratively train the initial generative adversarial network based on random noise samples and image samples until a pre-built loss function meets a set condition, and use the trained generative adversarial network as an image generation model;
[0124] In each iterative training, the loss function is constructed based on the distance information between the generated images obtained from random noise samples, the discriminant information between the generated images and the image samples, and the preset parameter information; the iterative training is used to reduce the similarity between the generated images.
[0125] In an optional embodiment, the image generation model training device 300 may further include a construction module for executing Figure 3 Each step in the process is performed to achieve the corresponding technical effects.
[0126] In an optional embodiment, the above-mentioned training module 320 can be specifically used to execute steps 1 to 5, and each step included in step 1 to achieve corresponding technical effects.
[0127] In an optional embodiment, the above-mentioned training module 320 can also be specifically used to determine the value of the balance factor corresponding to each iterative training according to the probability curve information between the preset number of iterations and the balance factor in each iterative training, and randomly sample from the preset distribution model to obtain the random coefficient.
[0128] See Figure 12 , Figure 12 This is a functional module diagram of an image generation device provided by an embodiment of the present invention. The image generation device 400 includes:
[0129] The acquisition module 410 is configured to acquire random noise samples.
[0130] Generation module 420 is used to input random noise samples into the image generation model to generate a first image and a second image; the first generated image and the second generated image are different; the above-mentioned image generation model is obtained by the image generation model training method provided by an embodiment of the present invention.
[0131] An embodiment of the present invention further provides a storage medium storing a computer program that, when executed by a processor, implements the image generation model training method or image generation method described in any of the aforementioned embodiments. The computer-readable storage medium may be, but is not limited to, a USB flash drive, a mobile hard drive, ROM, RAM, PROM, EPROM, EEPROM, a magnetic disk, or an optical disk, among other media capable of storing program code.
[0132] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, improvements, and the like made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention. It should be noted that similar reference numerals and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it need not be further defined or explained in subsequent figures.
Claims
1. A method for training an image generation model, characterized in that: The method comprises: Get random noise samples and image samples; Iteratively training the initial generative adversarial network according to the random noise samples and the image samples until the pre-constructed loss function reaches a set condition, and using the trained generative adversarial network as an image generation model; The loss function is constructed based on the distance information between the generated images obtained from the random noise samples, the discrimination information between the generated images and the image samples, and the preset parameter information; and the iterative training is used to reduce the similarity between the generated images; The loss function is constructed as follows: Constructing a distance information loss model based on a first generated image and a second generated image obtained from the random noise sample; wherein the first generated image is generated based on the random noise sample; and the second generated image is generated based on a random perturbation sample of the noise sample; Constructing a discriminant information loss model according to the discriminant information of the first generated image and the image sample, and the first weight information; constructing the loss function based on the distance information loss model, the second weight information corresponding to the distance information loss model, and the discriminant information loss model; or, The loss function is constructed based on the distance information loss model, the second weight information corresponding to the distance information loss model, the discriminant information loss model, the balance factor, and the random coefficient.
2. The image generation model training method according to claim 1, characterized in that: The method further comprises: In each iterative training, the value of the balance factor corresponding to each iterative training is determined according to the probability curve information between the preset number of iterations and the balance factor, and the random coefficient is obtained by random sampling from a preset distribution model.
3. The image generation model training method according to claim 1, characterized in that: The generative adversarial network includes a generator and a discriminator; According to the random noise sample and the image sample, the initial generative adversarial network is iteratively trained until the pre-constructed loss function reaches a set condition, and the trained generative adversarial network is used as an image generation model, including: Inputting the random noise sample into the generator to obtain the first generated image and the second generated image; Inputting the first generated image and the image sample into the discriminator to obtain the discriminant information; Inputting distance information of the first generated image and the second generated image into the distance information loss model, and inputting the discrimination information into the discrimination information loss model, to obtain a loss value of the loss function; Keeping the network parameters of the discriminator fixed, and updating the network parameters of the generator based on the loss value; When the set condition is not met, return to the step of inputting the random noise sample into the generator to obtain the first generated image and the second generated image, until the loss function reaches the set condition, and use the trained generative adversarial network as the image generation model.
4. The image generation model training method according to claim 3, characterized in that: Inputting the random noise sample into the generator to obtain a first generated image and a second generated image, the method further comprising: Determine the noise threshold; Based on the noise threshold, determining a random disturbance sample of the random noise sample; The first generated image is obtained based on the random noise samples, and the second generated image is obtained based on the random disturbance samples.
5. The image generation model training method according to claim 4, characterized in that: Determine the noise threshold, including: Randomly sampling from a preset data distribution model to obtain a plurality of random values, and obtaining each of the random disturbance samples corresponding to the random noise sample according to each of the random values; According to the generator, a generated image corresponding to the random noise sample and a generated image corresponding to each of the random disturbance samples are obtained; Determine the similarity between a generated image corresponding to the random noise sample and a generated image corresponding to each of the random disturbance samples; The generated image with the minimum similarity is determined as the target generated image, and the random value corresponding to the target generated image is determined as the noise threshold.
6. An image generation method, characterized in that: The method comprises: Get a random noise sample; The random noise sample is input into an image generation model to generate a first image and a second image, wherein the first image and the second image are different; the image generation model is obtained by the image generation model training method according to any one of claims 1 to 5.
7. An image generation model training device, characterized in that: include: An acquisition module, used for acquiring random noise samples and image samples; A training module, used to iteratively train the initial generative adversarial network according to the random noise samples and the image samples until the pre-constructed loss function reaches a set condition, and use the trained generative adversarial network as an image generation model; Wherein, in each iterative training, the loss function is constructed based on the distance information between the generated images obtained from the random noise samples, the discrimination information between the generated images and the image samples, and the preset parameter information; the iterative training is used to reduce the similarity between the generated images; The loss function is constructed as follows: Constructing a distance information loss model based on a first generated image and a second generated image obtained from the random noise sample; wherein the first generated image is generated based on the random noise sample; and the second generated image is generated based on a random perturbation sample of the noise sample; Constructing a discriminant information loss model according to the discriminant information of the first generated image and the image sample, and the first weight information; constructing the loss function based on the distance information loss model, the second weight information corresponding to the distance information loss model, and the discriminant information loss model; or, The loss function is constructed based on the distance information loss model, the second weight information corresponding to the distance information loss model, the discriminant information loss model, the balance factor, and the random coefficient.
8. An image generating device, characterized in that: include: An acquisition module is used to obtain random noise samples; A generation module, used to input the random noise sample into an image generation model to generate a first image and a second image; the first image and the second image are different; the image generation model is obtained by the image generation model training method as described in any one of claims 1-5.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a computer program executable by the processor, and the processor can execute the computer program to implement the method according to any one of claims 1 to 5 or the method according to any one of claim 6.
10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
