生成对抗网络训练
Let us assume Sergio is planning his next big heist and he needs his team to travel to a foreign country. Owing to the nature of his job he has decided to generate fake passports. He doesn’t want to take any chances because he believes that the passport officer can discriminate between original and fake passports. He has decided to use his network of designers and experts to carry out his plans effectively.
让我们假设塞尔吉奥正在计划他的下一次大劫案,他需要他的团队前往国外。 由于工作性质,他决定生产假护照。 他不想冒险,因为他认为护照人员可以区分原始护照和伪造护照。 他决定利用自己的设计师和专家网络有效地执行他的计划。
Generative Adversarial Networks have two components a generator and a discriminator. Just take my words as of now :)Let's get back to Sergio's plan and problems.
塞尔吉奥护照生成器 (Sergio’s Passport Generator)
The diagram below represents Sergio’s plan of action in which a fake passport is generated by using the combined skills of the professionals.
下图显示了塞尔吉奥的行动计划,其中利用专业人员的综合技能生产了假护照。
![Image for post](https://miro.medium.com/max/9999/1*kfnR0nv5YnOgRLyU3TE3xw.png)
If we were to generalise Sergio’s plan we can say, the diagram is a generator of fake passports. A network of professionals who essentially know the security features of a passports try to recreate a similar one by using their knowledge. In other words given a space the goal is to draw an example which resembles the original space.
如果我们概括一下塞尔吉奥的计划,可以说,该图是伪造护照的产生者。 本质上了解护照安全特性的专业人士网络试图利用他们的知识来重建相似的护照。 换句话说,给定一个空间,目标是绘制一个类似于原始空间的示例。
This is precisely what the generator component of a GAN does. It feeds upon the real world examples to observe their features and then create a new example which resembles the original examples.
这正是GAN的生成器组件所做的。 它以现实世界中的示例为例,观察它们的功能,然后创建一个类似于原始示例的新示例。
护照主任作为鉴别人员 (Passport Officer as Discriminator)
The following diagram represents the workflow of a passport officer. He checks hundreds of passports daily and Sergio wants his generated passports to be identified as the real ones.
下图显示了护照工作人员的工作流程。 他每天检查数百本护照,而塞尔吉奥(Sergio)希望将其生成的护照识别为真实护照。
![Image for post](https://miro.medium.com/max/9999/1*SeIvL98zZxnv-w74V-kOaA.png)
The passport officer resembles to the second component of GAN called as the discriminator. The job of the discriminator is classification. It identifies the real instances of data from the fake or generated instances of data.
护照人员类似于GAN的第二部分,称为鉴别器 。 鉴别器的工作是分类。 它从伪造或生成的数据实例中识别数据的真实实例。
Under the given circumstances of counterfeiting, Sergio and the passport officer are competing against each other. Sergio wants his generated passports to be categorised as real ones, while the passport officer wants to do a good job of detecting fake passports. This makes them adversaries, hence the name adversarial network.
在伪造的特定情况下,塞尔吉奥和护照人员将相互竞争。 塞尔吉奥(Sergio)希望将其生成的护照归类为真实护照,而护照官员则希望能很好地发现假护照。 这使他们成为对手,因此命名为对抗网络 。
Now that we understand about the two components of a GAN let’s see how to train them to obtain a GAN.
现在,我们了解了GAN的两个组成部分,让我们看看如何训练它们以获得GAN。
把它放在一起 (Putting it Together)
鉴别训练 (Discriminator Training)
A discriminator is simply a classifier in case of a GAN which labels a given instance as either real or fake. You can use any neural network which suits your problem statement.
如果GAN将给定实例标记为真或假,则鉴别器只是分类器。 您可以使用任何适合您的问题陈述的神经网络。
When a discriminator is trained it is fed with examples from real world as positive instances and examples generated from the generator network as negative instances. While training a discriminator the generator is not trained which is to say that its weights are not changed. Simply, the generator’s output is fed to the discriminator as negative instances. If the discriminator then classifies a negative instance as positive or vice-versa it is penalised by the loss function and its weights are updated through backpropagation.
训练鉴别器时,会将来自现实世界的示例作为正面实例,并从生成器网络生成的示例作为负面实例。 在训练鉴别器时,不训练发电机,这就是说其权重没有改变。 简单来说,生成器的输出作为否定实例被馈送到鉴别器。 如果判别器然后将否定实例分类为肯定实例,反之亦然,则损失函数会对其进行惩罚,并通过反向传播更新其权重。
![Image for post](https://miro.medium.com/max/9999/1*fAl040xLmTC7T6JRVP37AQ.png)
发电机培训 (Generator Training)
We have already seen that the job of the generator is to output new data instances. Generator is simply nothing but a neural network. However, neural networks have inputs. In case of generators noise is fed to them as input and eventually it learns to generate perceptible data. For any generated image the generator is penalized if the discriminator classifies it as fake. Only the weights of generator are updated while training it.
我们已经看到生成器的工作是输出新的数据实例。 生成器只是神经网络而已。 但是,神经网络具有输入。 在发电机的情况下,噪声作为输入被馈送到发电机,并最终学会生成可感知的数据。 对于任何生成的图像,如果鉴别器将其分类为伪造,则生成器将受到处罚。 训练时仅更新发生器的权重。
![Image for post](https://miro.medium.com/max/9999/1*F1DVSjY8u4ACFp4s2fWwqg.png)
In practice, an iterative approach is used to train a GAN in which you switch between training the generator for one iteration and then training the discriminator for the next iteration.
在实践中,使用迭代方法来训练GAN,您可以在训练GAN的过程中进行一次迭代,然后再对鉴别器进行下一次迭代。
翻译自: https://towardsdatascience.com/generative-adversarial-network-74eef7a82117
生成对抗网络训练