GAN 培训
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
由于 GAN 包含两个单独训练的网络,因此其训练算法必须解决两个复杂问题:
- GAN 必须同时进行两种不同类型的训练(生成器和鉴别器)。
- 很难确定 GAN 是否已收敛。
交替训练
生成器和鉴别器具有不同的训练过程。那么,我们如何整体训练 GAN?
GAN 训练会交替进行:
- 分类器会训练一个或多个 epoch。
- 生成器会进行一个或多个 epoch 的训练。
- 重复第 1 步和第 2 步,继续训练生成器网络和鉴别器网络。
在鉴别器训练阶段,我们会让生成器保持不变。由于判别器训练会尝试找出如何区分真实数据和虚假数据,因此它必须学习如何识别生成器的缺陷。这对于经过充分训练的生成器来说是一个不同于生成随机输出的未训练生成器的问题。
同样,在生成器训练阶段,我们会让鉴别器保持不变。否则,生成器会尝试命中移动目标,并且可能永远不会收敛。
正是这种来回交互,让 GAN 能够解决原本难以解决的生成问题。我们从一个更简单的分类问题入手,逐步进入难度更高的生成问题。反之,如果您无法训练分类器来区分真实数据和生成的数据(即使是初始随机生成器输出),则无法开始 GAN 训练。
收敛
随着生成器在训练过程中不断改进,鉴别器的性能会变得更差,因为鉴别器无法轻易区分真实图片和虚假图片。如果生成器完全成功,则判别器的准确性为 50%。实际上,判别器会抛硬币来进行预测。
这种进展会给 GAN 的整体收敛带来问题:随着时间的推移,鉴别器反馈的意义会越来越小。如果 GAN 在分类器提供完全随机反馈之后继续训练,则生成器会开始根据垃圾反馈进行训练,其自身质量可能会崩溃。
对于 GAN,收敛通常是一种短暂的状态,而不是稳定的状态。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-02-26。
[null,null,["最后更新时间 (UTC):2025-02-26。"],[[["\u003cp\u003eGenerative Adversarial Networks (GANs) employ two neural networks, a generator and a discriminator, trained in alternating periods to create realistic data.\u003c/p\u003e\n"],["\u003cp\u003eGAN training involves a dynamic where the discriminator learns to distinguish real from fake data, while the generator learns to produce increasingly realistic data to fool the discriminator.\u003c/p\u003e\n"],["\u003cp\u003eA key challenge in GAN training is identifying convergence, as the discriminator's performance degrades as the generator improves, potentially leading to unstable training and a collapse in the generator's quality.\u003c/p\u003e\n"],["\u003cp\u003eWhile GANs can solve complex generative problems, their success relies on a balance between the generator and discriminator, with the discriminator providing meaningful feedback to guide the generator's learning.\u003c/p\u003e\n"]]],[],null,["# GAN Training\n\n\u003cbr /\u003e\n\nBecause a GAN contains two separately trained networks, its training algorithm\nmust address two complications:\n\n- GANs must juggle two different kinds of training (generator and discriminator).\n- GAN convergence is hard to identify.\n\nAlternating Training\n--------------------\n\nThe generator and the discriminator have different training processes. So how\ndo we train the GAN as a whole?\n\nGAN training proceeds in alternating periods:\n\n1. The discriminator trains for one or more epochs.\n2. The generator trains for one or more epochs.\n3. Repeat steps 1 and 2 to continue to train the generator and discriminator networks.\n\nWe keep the generator constant during the discriminator training phase. As\ndiscriminator training tries to figure out how to distinguish real data from\nfake, it has to learn how to recognize the generator's flaws. That's a different\nproblem for a thoroughly trained generator than it is for an untrained\ngenerator that produces random output.\n\nSimilarly, we keep the discriminator constant during the generator training\nphase. Otherwise the generator would be trying to hit a moving target and might\nnever converge.\n\nIt's this back and forth that allows GANs to tackle otherwise intractable\ngenerative problems. We get a toehold in the difficult generative problem by\nstarting with a much simpler classification problem. Conversely, if you can't\ntrain a classifier to tell the difference between real and generated data even\nfor the initial random generator output, you can't get the GAN training started.\n\nConvergence\n-----------\n\nAs the generator improves with training, the discriminator performance gets\nworse because the discriminator can't easily tell the difference between real\nand fake. If the generator succeeds perfectly, then the discriminator has a 50%\naccuracy. In effect, the discriminator flips a coin to make its prediction.\n\nThis progression poses a problem for convergence of the GAN as a whole: the\ndiscriminator feedback gets less meaningful over time. If the GAN continues\ntraining past the point when the discriminator is giving completely random\nfeedback, then the generator starts to train on junk feedback, and its own\nquality may collapse.\n\nFor a GAN, convergence is often a fleeting, rather than stable, state."]]