A confidence-guided conditional generative adversarial network training method with auxiliary classifier
By designing a new classification loss function and introducing hyperparameters, combined with the KL divergence regularization term, the problem of collapse and low diversity in early training of conditional generative adversarial networks with auxiliary classifiers is solved, and more stable and high-quality image generation is achieved. .
Patent Information
- Application Number
- CN202410344864.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-25
- Publication Date
- 2024-08-23
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Conditional generative adversarial networks with auxiliary classifiers are prone to collapse in the early training stage and generate low diversity data, which has problems with training stability and generation performance.
Design a new classification loss function, introduce hyperparameters to suppress the confidence of the generator, and use KL divergence as a regularization term to optimize the distribution of generated data output and improve classification capabilities.
It effectively avoids early training collapse and overconfidence problems, improves the training stability and generation performance of conditional generative adversarial networks, and improves the diversity and fidelity of generated images.
Smart Images

Figure CN117933320B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image generation, and in particular to a training method for a confidence-guided conditional generative adversarial network with an auxiliary classifier. Background Art
[0002] Currently, Generative Adversarial Network (GAN) is a popular high-fidelity image generation model that has been widely studied in recent years. Although other generative models, such as the diffusion model, have also attracted a lot of attention recently due to their effectiveness in generating high-quality images, the Generative Adversarial Network (GAN) still has several significant advantages in practical applications, such as its lower computational complexity for training and inference. The core idea of GAN is to use the adversarial game method to simultaneously train the generator and the discriminator: the generator uses random noise to generate fake data to deceive the discriminator; at the same time, the discriminator tries to distinguish between real and fake data. The objective loss function of the original generative adversarial network is:
[0003]
[0004] Generally speaking, generative adversarial networks can be divided into unconditional generative adversarial networks and conditional generative adversarial networks (cGANs). Unconditional generative adversarial networks accept unsupervised (unlabeled) real data and low-dimensional latent variables (usually Gaussian or uniformly distributed random vectors) as input to generate images that are consistent with the distribution of real data in the training set; while conditional generative adversarial networks, by introducing supervised learning, can take category labels or certain properties of images as conditional inputs to generate images of specified categories or properties; at the same time, compared with unconditional generative adversarial networks, they often have better generation quality. Although generative adversarial networks based on adversarial learning have achieved great success in the field of image generation, they still have some problems to be solved: such as training stability problems, mode collapse, etc. AC-GAN (Auxiliary classifier Generative Adversarial Network, conditional generative adversarial network with auxiliary classifier) is a representative generative adversarial network with a classifier. It uses an auxiliary classifier to learn the conditional label distribution to guide the generator to generate images of a specific class. Although AC-GAN can achieve good generation quality, recent studies have shown that using AC-GAN in practice often encounters two problems: (1) the performance of the generator suddenly drops in the early training stage, i.e., early training collapse; (2) the generator tends to generate low-diversity data. Summary of the invention
[0005] The purpose of the present invention is to provide a confidence-guided conditional generative adversarial network training method with an auxiliary classifier, which solves the problems of early training collapse and overconfidence by designing a new classification loss function to avoid large feature norms of feature representation.
[0006] The objective of the present invention is achieved through the following technical solutions:
[0007] A confidence-guided conditional generative adversarial network training method with an auxiliary classifier, the method comprising:
[0008] Step 1: Design a new loss function for conditional generative adversarial networks (cGANs) and introduce a hyperparameter to solve the training convergence problem.
[0009] Step 2: When the confidence of the classifier of the confidence-guided conditional generative adversarial network with auxiliary classifier, i.e., CG-GAN, for the generated data exceeds the introduced hyperparameter, the loss function will suppress the confidence of the classifier for the generated data, thereby implicitly affecting the confidence of the real data by suppressing the confidence of the classifier for the generated data;
[0010] Step 3: Customize a priori label distribution based on the hyperparameters introduced previously By adding a reverse or forward KL divergence as a regularization term to CG-GAN, the distribution of the optimized generated data output learns the prior label distribution, thereby improving the classification ability of CG-GAN.
[0011] It can be seen from the technical solution provided by the present invention that the above method avoids large feature norms of feature representation by designing a new classification loss function, solves the problems of early training collapse and overconfidence, and further improves the conditional generation performance while improving the training stability of the conditional generative adversarial network. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0013] Figure 1 A flow chart of a training method for a confidence-guided conditional generative adversarial network with an auxiliary classifier provided in an embodiment of the present invention;
[0014] Figure 2 A schematic diagram of the FID value curve of the example of the present invention on the CIFAR100 data set;
[0015] Figure 3 The figure is a schematic diagram of the FID value curve of the example given in the present invention on the Tiny-ImageNet dataset. DETAILED DESCRIPTION
[0016] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings 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, which does not constitute a limitation of the present invention. 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.
[0017] like Figure 1 The figure is a flow chart of a training method of a confidence-guided conditional generative adversarial network with an auxiliary classifier provided by an embodiment of the present invention, the method comprising:
[0018] Step 1: Design a new loss function for conditional generative adversarial networks (cGANs) and introduce a hyperparameter to solve the training convergence problem.
[0019] In this step, the classic AC-GAN (Auxiliary classifier Generative Adversarial Network) simply continues to minimize the cross entropy loss function of real data when training the discriminator, which can easily lead to the phenomenon of generation performance collapse during training. In order to alleviate the training collapse problem of the conditional generative adversarial network with auxiliary classifiers, this application proposes to maximize the cross entropy loss function for real data in the discriminator optimization stage, and minimize the cross entropy loss function in the generation stage, which is expressed as:
[0020] (1)
[0021] in, Represents the distribution of real data; represents the distribution of generated data; Express request Follow the distribution expectations; express Follow the distribution expectations; , Represents a given sample , its true label The conditional probability distribution of ; is the number of data types; Represents a neural network that maps data into a dimensional vector; It represents the dimensional vector in the true label The scalar value of the corresponding encoding position;
[0022] In practice, directly optimizing the loss function formula (1) may lead to a technical problem: maximizing the cross entropy loss of the generated data may be too large during training, making it difficult for the entire adversarial training process to converge. To avoid this problem, this application introduces an upper bound for the cross entropy loss of the generated data: To constrain the loss function from being optimized too large, that is, when the cross entropy loss of the generated data increases to the value m, stop optimizing the loss function. Specifically:
[0023] When optimizing the discriminator, the loss function of the confidence guided conditional generative adversarial network (CG-GAN) classifier with auxiliary classifier proposed in this application is The definition is as follows:
[0024] (2)
[0025] The symbol Indicates when When it is greater than 0, ;otherwise ;
[0026] When optimizing the generator, the loss function is consistent with the loss function of the classic AC-GAN, expressed as:
[0027] (3)
[0028] In theory, it can be proved that if and only if When , the loss of the CG-GAN classifier can reach the global optimum, which is crucial to ensure that the proposed training method can effectively encourage the generator to learn the real data distribution (i.e., generation ability);
[0029] In addition, this training method ensures that the optimal cross entropy loss function obtained when the loss of the CG-GAN classifier reaches the global optimum will be less than or equal to m, and the corresponding optimal confidence function Should be at least , is an exponential function of -m; this shows that by setting reasonable hyperparameters It can ensure the properties required for the classifier to have good classification ability. In the specific implementation, Can represent the expected confidence of the classifier. In order for the classifier to have classification ability, it is necessary to , K is the number of types of training data; at the same time, in order to avoid the problem of unstable training caused by overconfidence of the classifier, Generally, it should not be set too large, that is, it should be set slightly larger than The value of .
[0030] Step 2: When the confidence of the classifier of the confidence-guided conditional generative adversarial network with auxiliary classifier, i.e., CG-GAN, for the generated data exceeds the introduced hyperparameter, the loss function will suppress the confidence of the classifier for the generated data, thereby implicitly affecting the confidence of the real data by suppressing the confidence of the classifier for the generated data;
[0031] This operation will make the gradient norm in the CG-GAN classifier smaller than that in the AC-GAN, thereby alleviating the gradient explosion problem and improving training stability.
[0032] In this step, for the loss function , using Monte Carlo sampling to write it in the form of empirical loss, for a real data set Samples , there is also Generate samples , first according to the loss function definition:
[0033] (4)
[0034] is the loss function corresponding to the i-th sample (a function of the weight vector corresponding to the fully connected classification layer of the last layer of the neural network);
[0035] The confidence function for real data is written as:
[0036] (5)
[0037] The confidence function for generated data is defined similarly; The feature vector representing the output of the neural network; The weight vector corresponding to the true label of the fully connected classification layer of the last layer of the neural network;
[0038] against , for each , The gradient of is:
[0039] (6)
[0040] in:
[0041] (7)
[0042] (8)
[0043] Note that the gradient norm of the cross entropy loss in the classic AC-GAN in the prior art is always equal to , and AC-GAN continues to increase the norm of the feature vector output by the classifier , which will cause the gradient explosion problem and lead to training collapse. However, the confidence of the CG-GAN classifier proposed in this application for the generated data exceeds the introduced hyperparameter hour, The gradient is equal to , and the loss function at this time This will suppress the classifier's confidence in the generated data, thereby suppressing the norm of the feature vector , which will make the gradient norm in the CG-GAN classifier smaller than that in the AC-GAN, thereby alleviating the gradient explosion problem and improving training stability.
[0044] Step 3: Customize a priori label distribution based on the hyperparameters introduced previously By adding a reverse or forward KL divergence (Kullback–Leibler divergence) as a regularization term to CG-GAN, the distribution of the optimized generated data output learns the prior label distribution, thereby improving the classification ability of CG-GAN and thus improving the generation performance.
[0045] In a specific implementation, when suppressing the confidence of the classifier on the generated data, it is necessary to improve the classification performance of the classifier on the generated data, because suppressing the confidence of the classifier on the generated data may damage the classification performance of the classifier on the generated data. Specifically:
[0046] A good classifier needs to meet the following two conditions:
[0047] (1) ;
[0048] (2) For any ;
[0049] in That is the confidence of the neural network output;
[0050] In order to enable the classifier to meet these two conditions for both real data and generated data, we first define a priori label distribution, expressed as:
[0051] (9)
[0052] Just set , that is, it is established ;
[0053] By adding a reverse or forward KL divergence as a regularization term to CG-GAN, the distribution of the optimized generated data output learns the prior label distribution, thereby prompting the classifier to meet the two conditions proposed; for any two different probability distributions and , the KL divergence is defined as:
[0054]
[0055] In the specific implementation, if we want to obtain rCG-GAN, that is, the confidence-guided conditional generative adversarial network with an auxiliary classifier constrained by reverse KL divergence, we add the CG-GAN target loss function with reverse KL divergence, which is expressed as:
[0056] Where D represents the discriminator; G represents the generator; and They represent the discriminator loss function and the generator loss function of the unconditional generative adversarial network respectively; and It is a custom hyperparameter, which is generally set to 1 in experiments; is the probability distribution of the neural network output;
[0057] Furthermore, if the corresponding KL term in the formula is replaced with forward KL divergence, another fCG-GAN is obtained, namely, a confidence-guided conditional generative adversarial network with an auxiliary classifier constrained by forward KL divergence.
[0058] In the specific implementation, by controlling the value of the introduced hyperparameter desired confidence (conf), that is, It can effectively control the trade-off between generation fidelity (Improved Precision and IS) and diversity (Improved Recall); among them, the larger Values can produce better fidelity generated images; while smaller The value can obtain generated images with better diversity; in this way, more appropriate hyperparameters can be set according to different task needs. For example, some generation tasks may pay more attention to the realism (i.e. fidelity) of the generated images, while some downstream classification tasks may require more diverse generated images as image enhancement.
[0059] It is worth noting that the contents not described in detail in the embodiments of the present invention belong to the prior art known to professional and technical personnel in the field.
[0060] In order to more clearly demonstrate the technical solution and the technical effects provided by the present invention, the effects of the method described in the embodiment of the present invention are compared and explained with specific examples below:
[0061] 1. Training stability comparison:
[0062] like Figure 2 The figure shows a schematic diagram of the FID value curve of the example of the present invention on the CIFAR100 dataset. The FID (the most widely used generation quality measurement indicator, the lower the better) curve on the CIFAR100 dataset shows that the rCG-GAN and fCG-GAN proposed in this application can successfully avoid the training collapse problem. It can be seen that the basic model CG-GAN proposed in this application can achieve better training stability than AC-GAN and AMGAN in the prior art, and the addition of reverse or forward KL divergence optimization items and CG-GAN (i.e. rCG-GAN and fCG-GAN) proposed in this application can successfully avoid the training collapse problem. For comparison, the existing methods include AC-GAN, AMGAN, CG-GAN (i.e. the method proposed in this invention without adding KL divergence optimization items) and the method of simply combining KL optimization items with AC-GAN, all of which have the problem of early training collapse.
[0063] like Figure 3 The figure shows a schematic diagram of the FID value curve of the example of the present invention on the Tiny-ImageNet dataset. The performance of the prior art AC-GAN, AMGAN and MHGAN on the Tiny-ImageNet dataset deteriorates with training, and the performance of the recently proposed ReACGAN and ADC-GAN are far weaker than the rCG-GAN network performance of the present application.
[0064] 2. Comparison of generated quality:
[0065] The methods used for comparison in this example include AC-GAN, PD-GAN, ReACGAN, and ADC-GAN. The generated quality indicators include: "Inception Score (IS)", "Density", "improved Precision", which usually measure the fidelity of the generated images, and "Fr´echet Inception Distance (FID)", "Coverage", "improved Recall" which measure the diversity of the generated images.
[0066] Table 1 Ablation experiment
[0067]
[0068] The best results in Table 1 are bolded in the table, “↑” means higher is better, and “↓” means lower is better.
[0069] It can be seen from Table 1 that the performance of rCG-GAN and fCG-GAN (i.e., the solution of this application) obtained by combining the KL optimization term with CG-GAN are better than that of CG-GAN without the KL term, indicating the necessity of adding the KL term.
[0070] Table 2 below compares the generation quality on CIFAR10, CIFAR100, Tiny-ImageNet, Baby / Papa / Grandpa-ImageNet datasets:
[0071] Table 2
[0072]
[0073] It can be seen from Table 2 above that: in all data sets, the rCG-GAN (confidence-guided conditional generative adversarial network with auxiliary classifier constrained by reverse KL divergence) obtained by the method described in this application achieved the best results in 5 of the 6 indicators, indicating that the method described in this application can achieve better fidelity and better diversity.
[0074] 3. Comparison of generation performance on the large-scale dataset ImageNet:
[0075] Table 3 below is a comparison of the generation quality on the ImageNet dataset. Top-1 Acc. and Top-5 Acc. in Table 3 represent the Top-1 accuracy and Top-5 accuracy of the generated data using the pre-trained classifier, respectively, which can be used to measure the conditional generation ability of the conditional generative adversarial network.
[0076] Table 3
[0077]
[0078] It can be seen from Table 3 above that the method described in the present application not only obtains an IS value that is almost twice as high as that of the existing methods compared and an FID value that is almost half as high as that of the existing methods, but also achieves the best conditional generation performance among all the methods.
[0079] 4. Comparison of conditional generation capabilities on datasets of different classification difficulties:
[0080] Table 4 below is a comparison of conditional generation capabilities on the Baby / Papa / Grandpa-ImageNet datasets. Baby-ImageNet represents the easiest category to classify in ImageNet, while Grandpa-ImageNet represents the most difficult category to classify.
[0081] Table 4
[0082]
[0083] It can be seen from Table 4 above that the method described in this application shows consistent and superior conditional generation performance on data sets of different classification difficulties.
[0084] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with the technical field within the technical scope disclosed in the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims. The information disclosed in the background technology section of this article is only intended to deepen the understanding of the overall background technology of the present invention, and should not be regarded as an admission or in any form that the information constitutes prior art known to those skilled in the art.
Claims
1. A confidence-guided conditional generative adversarial network training method with an auxiliary classifier, characterized in that: The confidence-guided conditional generative adversarial network with an auxiliary classifier is used for image generation, and the method comprises: Step 1: Design a new loss function for conditional generative adversarial networks (cGANs) and introduce a hyperparameter to solve the training convergence problem. In step 1, in order to alleviate the training collapse problem of the conditional generative adversarial network with auxiliary classifier, it is proposed to maximize the cross entropy loss function for the real data in the stage of optimizing the discriminator, and minimize the cross entropy loss function for the generation stage, which is expressed as: (1) in, Represents the distribution of real data; represents the distribution of generated data; Express request Follow the distribution expectations; express Follow the distribution expectations; , Represents a given sample , its true label The conditional probability distribution of ; is the number of data types; Represents a neural network that maps data into a dimensional vector; It represents the dimensional vector in the true label The scalar value of the corresponding encoding position; Furthermore, an upper bound is introduced for the cross entropy loss of generated data To constrain the loss function from being optimized too large, that is, when the cross entropy loss of the generated data increases to the value m, stop optimizing the loss function. Specifically: When optimizing the discriminator, the loss function of the proposed confidence-guided conditional generative adversarial network CG-GAN classifier with auxiliary classifier The definition is as follows: (2) The symbol Indicates when When it is greater than 0, ;otherwise ; When optimizing the generator, the loss function is consistent with the loss function of the classic AC-GAN, expressed as: (3) If and only if When , the loss of the CG-GAN classifier can reach the global optimum; this training method ensures that the optimal cross entropy loss function obtained when the loss of the CG-GAN classifier reaches the global optimum will be less than or equal to m, and the corresponding optimal confidence function Should be at least , is the exponential function of -m, and is also the hyperparameter introduced in step 1; in, Can represent the expected confidence of the classifier. In order for the classifier to have classification ability, it is necessary to , K is the number of types of training data; Step 2: When the confidence of the classifier of the confidence-guided conditional generative adversarial network with auxiliary classifier, i.e., CG-GAN, for the generated data exceeds the introduced hyperparameter, the loss function will suppress the confidence of the classifier for the generated data, thereby implicitly affecting the confidence of the real data by suppressing the confidence of the classifier for the generated data; Step 3: Customize a priori label distribution based on the hyperparameters introduced previously By adding a reverse or forward KL divergence as a regularization term to CG-GAN, the distribution of the optimized generated data output learns the prior label distribution, thereby improving the classification ability of CG-GAN.
2. The training method of the confidence-guided conditional generative adversarial network with an auxiliary classifier according to claim 1, characterized in that: In step 2, for the loss function , using Monte Carlo sampling to write it in the form of empirical loss, for a real data set Samples , there is also Generate samples , first according to the loss function definition: (4) is the loss function corresponding to the i-th sample; The confidence function for real data is written as: (5) The confidence function for generated data is defined similarly; The feature vector representing the output of the neural network; The weight vector corresponding to the true label of the fully connected classification layer of the last layer of the neural network; against , for each , The gradient of is: (6) in: (7) (8) When the confidence of the CG-GAN classifier in the generated data exceeds the introduced hyperparameters hour, The gradient is equal to , and the loss function at this time This will suppress the classifier's confidence in the generated data, thereby suppressing the norm of the feature vector , which will make the gradient norm in the CG-GAN classifier smaller than that in the classic AC-GAN, thereby alleviating the gradient explosion problem and improving training stability.
3. The training method of the confidence-guided conditional generative adversarial network with auxiliary classifier according to claim 1, characterized in that: In step 3, while suppressing the confidence of the classifier on the generated data, it is necessary to improve the classification performance of the classifier on the generated data. Specifically: A good classifier needs to meet the following two conditions: (1) ; (2) For any ; in That is the confidence of the neural network output; In order to enable the classifier to meet these two conditions for both real data and generated data, we first define a priori label distribution, expressed as: (9) Just set , that is, it is established ; By adding a reverse or forward KL divergence as a regularization term to CG-GAN, the distribution of the optimized generated data output learns the prior label distribution, thereby prompting the classifier to meet the two conditions proposed; for any two different probability distributions and , the KL divergence is defined as: In the specific implementation, if we want to obtain rCG-GAN, that is, the confidence-guided conditional generative adversarial network with an auxiliary classifier constrained by the reverse KL divergence, then add the CG-GAN target loss function of the reverse KL divergence, which is expressed as: Where D represents the discriminator; G represents the generator; and They represent the discriminator loss function and the generator loss function of the unconditional generative adversarial network respectively; and is a customized hyperparameter; is the probability distribution of the neural network output; Furthermore, if the corresponding KL term in the formula is replaced with forward KL divergence, another fCG-GAN is obtained, namely, a confidence-guided conditional generative adversarial network with an auxiliary classifier constrained by forward KL divergence.
