生成式模型之 GAN

生成对抗网络(Generative Adversarial Networks,GANs),由2014年还在蒙特利尔读博士的Ian Goodfellow引入深度学习领域。2016年,GANs热潮席卷AI领域顶级会议,从ICLR到NIPS,大量高质量论文被发表和探讨。Yann LeCun曾评价GANs是”20年来机器学习领域最酷的想法”。

Generative Adversarial Nets(GAN)

Generative Adversarial Networks论文提出了一种通过对抗过程来评估生成模型。其训练两个模型:仿照原始数据分布生成数据的模型G和评估数据来源(原始数据/生成数据)的模型D。训练G的目标是最大化D犯错的概率,训练D的目标是最大化区分真实训练样本与G生成的样本的能力。

如果能够知道训练样本的分布(p(x)),那么就可以在分布中随机采样得到新样本,大部分的生成式模型都采用这种思路,GAN则是在学习从随机变量z到训练样本x的映射关系,其中随机变量可以选择服从正太分布,那么就能得到一个由多层感知机组成的生成网络(G(z;\theta_g)),网络的输入是一个一维的随机变量,输出是一张图片。

GAN的优化是一个极小极大博弈问题,公式如下:

[\underset{G}{\min} \: \underset{D}{\max}V(D,G) =\mathbb E_{x\sim p_{data}(x)}[logD(x)]+\mathbb E_{z\sim p_{z}(z)}[log(1-D(G(z)))] ]

优化这个函数,使(p_z(x))接近(p_{data}).下面首先去掉期望符号:

[\begin{align} V(G,D)&=\int_x p_{data}(x)\log(D(x))dx+\int_zp_z(z)\log(1-D(g(z)))dz \ &=\int_x [p_{data}(x)\log(D(x))+p_g(x)\log(1-D(x))]dx \end{align} ]

首先确定G,求(下集{D}{max}V(DMagne G)),使其导数等于0,得到D的最优解。

[En]

First fix G, find ( underset {D} { max} V (DMagne G)), make its derivative equal to 0, and get the optimal solution of D.

[D^*G(x)={p{data}(x)\over p_{data}(x)+p_g(x)} ]

现在固定D,优化G:将(D^*_G)带入目标函数。

[\begin{align} \underset{G}\min V(G,D^*G) &= \int_x [p{data}(x)\log{p_{data}(x)\over p_{data}(x)+p_g(x)}+p_g(x)\log{p_g(x)\over p_{data}(x)+p_g(x)}]dx \ &= \mathbb E_{x\sim p_{data}}[\log{p_{data}(x)\over p_{data}(x)+p_g(x)}]+\mathbb E_{x\sim p_g}[\log{p_g(x)\over p_{data}(x)+p_g(x)}] \ &= -\log 4+KL(p_{data}\|{p_{data}+p_g\over 2})+KL(p_g\|{p_{data}+p_g\over 2}) \ &= -\log 4+2JS(p_{data}\|p_g) \end{align} ]

其中KL散度:(KL(P\|Q)=\mathbb E_{x\sim P}\log{P\over Q}=\int_xP(x)\log{P(x)\over Q(x)}dx)

JS散度:(JS(P\|Q)={1\over 2}KL(P\|{P+Q\over 2})+{1\over 2}KL(Q\|{P+Q\over 2}))

JS散度具有对称性,而KL没有。

只要P和Q之间没有重叠,或者重叠可以忽略,JS散度总是恒定的,这意味着对于梯度下降法-梯度是零!此时,对于最优鉴别器,生成器无法获得梯度信息;即使对于接近最优的鉴别器,生成器也很有可能面临梯度消失的问题。

[En]

As long as there is no overlap between P and Q or the overlap can be ignored, the JS divergence is always constant, and this means that for the gradient descent method-the gradient is zero! At this time, for the optimal discriminator, the generator can not get the gradient information; even for the near-optimal discriminator, the generator has a good chance to face the problem of gradient disappearance.

参考 WGAN的介绍

f-GAN

在GAN中可以使用任意的f-divergency,相关论文f-GAN(Sebastian Nowozin, Botond Cseke, Ryota Tomioka, “f-GAN: Training Generative Neural Samplers using Variational Divergence Minimization”, NIPS, 2016)

f-divergence

P和Q是两个分布,p(x),q(x)是x的分布概率

[D_f(P||Q)=\int_x q(x)f({p(x)\over q(x)})dx ]

其中f是凸函数且f(1)=0,(D_f(P||Q))衡量了P和Q之间的距离.

当(\forall x,p(x)=q(x))时,(D_f(P||Q))具有最小值0.

当(f(x)=x\log x)时,(D_f(P||Q)=\int_xp(x)\log({p(x)\over q(x)})dx),即KL divergence.

当(f(x)=-\log x)时,(D_f(P||Q)=\int_xq(x)\log({q(x)\over p(x)})dx),即reverse KL divergence.

当(f(x)=(x-1)^2)时,(D_f(P||Q)=\int_x{(p(x)-q(x))^2\over q(x)}dx)为Chi Square divergence.

Fenchel Conjugate

每个凸函数f都有一个与之相反的共轭函数休闲态

[En]

Every convex function f has a conjugate function fallow as opposed to it

(f^ (t)=\max_{x\in dom(f)}{xt-f(x)}),且(f ) * = f.

(f(x)=\max_{t\in dom(f^)}{xt-f^(t)}),带入(D_f(P||Q))得:

[\begin{align} D_f(P||Q) &=\int_x q(x)f({p(x)\over q(x)})dx \ &=\int_xq(x)(\max_{t\in dom(f^)}{{p(x)\over q(x)}t-f^(t)})dx \ &=\max_D\int_x p(x)D(x)dx-\int_x q(x)f^*(D(x))dx \ &\text{(t=D(x))} \end{align} ]

所以在甘肃,

[En]

So in GAN,

[D_f(P_{data}\|P_G)=\max_D{E_{x\sim P_{data}}[D(x)]-E_{x\sim P_G}[f^*(D(x))]} ]

您可以使用任何f-散度,例如JS、Jeffrey、Pearson。

[En]

You can use any f-divergence, such as JS,Jeffrey,Pearson.

WGAN

原版:重量裁剪,改进版:渐变惩罚。

[En]

Original version: weight clipping, improved version: gradient penalty.

论文:

[En]

Thesis:

  • Martin Arjovsky, Soumith Chintala, Léon Bottou, Wasserstein GAN, arXiv preprint, 2017
  • Ishaan Gulrajani, Faruk Ahmed, Martin Arjovsky, Vincent Dumoulin, Aaron Courville,”Improved Training of Wasserstein GANs”, arXiv preprint, 2017

大意:用推土机距离(沃瑟斯坦距离)来评估两个分布之间的距离。推土机距离表示将一种配送转化为另一种配送的最小运输量。

[En]

Main idea: use Earth Mover’s Distance (Wasserstein Distance) to evaluate the distance between two distributions. The bulldozer distance represents the minimum amount of transport that transforms one distribution into another.

GaN以前使用的JS发散的缺点是,当两个分布不相交时,距离为0,梯度为0,网络很难学习。推土机的距离可以解决这个问题。此时,网络可以继续学习,但为了防止梯度爆炸,需要采取权重裁剪等手段。

[En]

The disadvantage of JS divergence used by GAN before is that when the two distributions do not intersect, the distance is 0 and the gradient is 0, the network is very difficult to learn. Earth Mover’s Distance can solve this problem. At this time, the network can continue to learn, but in order to prevent gradient explosion, weight clipping and other means are needed.

对抗样本(adversarial examples)

14年的时候Szegedy在研究神经网络的性质时,发现针对一个已经训练好的分类模型,将训练集中样本做一些细微的改变会导致模型给出一个错误的分类结果,这种虽然发生扰动但是人眼可能识别不出来,并且会导致误分类的样本被称为对抗样本,他们利用这样的样本发明了对抗训练(adversarial training),模型既训练正常的样本也训练这种自己造的对抗样本,从而改进模型的泛化能力[1]。如下图所示,在未加扰动之前,模型认为输入图片有57.7%的概率为熊猫,但是加了之后,人眼看着好像没有发生改变,但是模型却认为有99.3%的可能是长臂猿。

生成式模型之 GAN

对抗样本与生成性对抗网络没有直接关系,生成性对抗网络希望学习样本的内在表达,从而生成新的样本。然而,对抗样本的存在在一定程度上表明,模型并没有学习数据的一些内在表达或分布,而可能是学习了一些特定的模式就足以达到分类或回归的目的。

[En]

Confrontation samples are not directly related to generative confrontation networks, which want to learn the internal expression of samples so that they can generate new samples. however, the existence of confrontation samples to a certain extent shows that the model does not learn some internal expression or distribution of data, but may be that learning some specific patterns is enough to achieve the goal of classification or regression.

GAN生成的图片能否用于CNN训练?

就目前而言,这应该是不可能的。由于GaN是通过从一个小的分布中采样产生的,它在现实世界中只是一个非常小的部分,因此它不能广泛适用于训练。此外,目前的GaN很难产生更大的图像(32×32以上)。

[En]

For now, it should not be possible. Because GAN is generated by sampling from a small distribution, it is a very small part of the real world, so it is not widely applicable for training. In addition, it is difficult for the current GAN to generate larger images (above 32×32).

参考资料

Original: https://www.cnblogs.com/makefile/p/GAN.html
Author: 康行天下
Title: 生成式模型之 GAN

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/6531/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部