[ICML 2017] Wasserstein Generative Adversarial Networks (WGAN)

Introduction

冷知识: Wasserstein 中的 W W W v v v (因为是俄语)

  • 在原始 GAN 中,discriminator 衡量的是两个分布间的 JS 散度,而作者指出了使用 JS 散度会导致训练不稳定。为了解决上述问题,作者使用 Wasserstein Distance 来衡量两个概率分布间的距离,相应地提出了 WGAN提高 GAN 模型训练的稳定性避免 mode collapse提供可用于 debug 和超参搜索的有意义的训练曲线

Wasserstein Distance (Earth Mover’s Distance)

Wasserstein Distance

Earth Mover’s Distance

  • Considering one distribution P P P as a pile of earth, and another distribution Q Q Q as the target.
    在这里插入图片描述
  • There many possible “moving plans”. Using the “moving plan” with the smallest average distance to define the earth mover’s distance.
    在这里插入图片描述

Formal Definition

  • A “moving plan” is a matrix. The value of the element is the amount of earth from one position to another.
    在这里插入图片描述Wasserstein Distance 即为 :
    W [ p , q ] = min ⁡ γ ∈ Π [ p , q ] ∑ x p , x q γ ( x p , x q ) d ( x p , x q ) \mathcal{W}[p,q]=\min_{\gamma\in \Pi[p,q]}\sum_{x_p,x_q}\gamma(x_p,x_q)d(x_p,x_q) W[p,q]=γΠ[p,q]minxp,xqγ(xp,xq)d(xp,xq)其中, γ \gamma γ 表示运输方案, γ ∈ Π [ p , q ] \gamma\in \Pi[p,q] γΠ[p,q] 表示 γ \gamma γ 是一个联合分布,它的边缘分布就是原来的 p p p q q q,即
    ∑ x γ ( x , y ) = p ( y ) , ∑ y γ ( x , y ) = p ( x ) \sum_x\gamma(x,y)=p(y),\sum_y\gamma(x,y)=p(x) xγ(x,y)=p(y),yγ(x,y)=p(x) γ ( x , y ) \gamma(x,y) γ(x,y) 为从 x x x 运到 y y y 的土量, d ( x , y ) d(x,y) d(x,y)成本函数,代表从 x x x 运输到 y y y 的成本. 常用的 d d d 是基于 l l l 范数衍生出来的,比如
    ∥ x − y ∥ 1 , ∥ x − y ∥ 2 , ∥ x − y ∥ 2 2 \Vert\boldsymbol{x}-\boldsymbol{y}\Vert_1,\quad\Vert\boldsymbol{x}-\boldsymbol{y}\Vert_2,\quad \Vert\boldsymbol{x}-\boldsymbol{y}\Vert_2^2 xy1,xy2,xy22
  • 推广到连续概率分布,Wasserstein Distance
    W [ p , q ] = inf ⁡ γ ∈ Π [ p , q ] ∬ γ ( x , y ) d ( x , y ) d x d y \mathcal{W}[p,q]=\inf_{\gamma\in \Pi[p,q]} \iint \gamma(\boldsymbol{x},\boldsymbol{y}) d(\boldsymbol{x},\boldsymbol{y}) d\boldsymbol{x}d\boldsymbol{y} W[p,q]=γΠ[p,q]infγ(x,y)d(x,y)dxdy其中, γ ( x , y ) \gamma(\boldsymbol{x},\boldsymbol{y}) γ(x,y) 表示要从 x x x 处搬 γ ( x , y ) d x γ(x,y)dx γ(x,y)dx 那么多的东西到 y y y 处, inf ⁡ \inf inf 表示下确界

Why Earth Mover’s Distance?

Different Distances between two distributions

  • The Total Variation (TV) distance
    在这里插入图片描述其中, X \mathcal X X 为图像空间 [ 0 , 1 ] d [0,1]^d [0,1]d Σ \Sigma Σ X \mathcal X X 的所有 Borel subsets 的集合
  • The Kullback-Leibler (KL) divergence
    在这里插入图片描述
  • The Jensen-Shannon (JS) divergence
    在这里插入图片描述其中, P m = ( P r + P g ) / 2 \mathbb P_m=(\mathbb P_r+\mathbb P_g)/2 Pm=(Pr+Pg)/2
  • The Earth-Mover (EM) distance or Wasserstein-1
    在这里插入图片描述其中, Π ( P r , P g ) \Pi\left(\mathbb{P}_r, \mathbb{P}_g\right) Π(Pr,Pg) 为所有联合分布 γ ( x , y ) \gamma(x,y) γ(x,y) 的集合, γ ( x , y ) \gamma(x,y) γ(x,y) 的边缘分布为 P r , P g \mathbb{P}_r, \mathbb{P}_g Pr,Pg

假设数据集分布为 P 0 \mathbb P_0 P0,模型学得的数据分布为 P θ \mathbb P_\theta Pθ. 下面作者给出了具体的例子来说明在某些情况下,使用 EM 距离作为概率分布间的距离度量能够使得 P θ \mathbb P_\theta Pθ 收敛,而使用其余距离度量则不能收敛

在这里插入图片描述

  • 在上述例子中,只有 EM 距离能收敛的原因就在于,当两个概率分布不重合时,只有 EM 距离是连续的并能为模型参数提供有效的梯度信息
    在这里插入图片描述

W ( P r , P θ ) W (\mathbb P_r, \mathbb P_θ) W(Pr,Pθ) is a continuous loss function on θ θ θ under mild assumptions

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

  • 这种连续的性质对于实际的图像生成任务是十分重要的。首先,假设数据集样本分布为 P d a t a P_{data} Pdata,模型生成的样本分布为 P G P_{G} PG,则在大部分情况下,这两个分布都是没有交集的。这是因为图像是高维空间中的低维流形,两个不同的图像分布往往交集很小,同时我们往往是通过采样的方式来估计分布,采样不充分也会导致采样出的分布没有交集。而以原始 GAN 使用的 JS 散度为例,当两个分布不重合时,JS 散度就为 log ⁡ 2 \log2 log2,当刚开始训练 GAN 时, P G P_G PG P d a t a P_{data} Pdata 一直都没有重合,因此 JS divergence 一直为 log ⁡ 2 \log2 log2,使得 Generater 的 loss function L ( D ) L(D) L(D) 一直为 0,训练难以收敛
    在这里插入图片描述相比之下,EM 距离就好在它在衡量两个低维流形上分布间的距离时更加敏感,它处处连续,几乎处处可导且导数不为 0
    在这里插入图片描述

作者进一步用以下定理证明了使用 EM 距离进行训练的优越性

在这里插入图片描述

Wasserstein GAN

WGAN (Weight Clipping)

  • EM 距离里有一个下确界比较难以处理,因此现在的问题就是如何去估算出 EM 距离。Kantorovich-Rubinstein duality 给出了估算方法:
    W ( P r , P θ ) = sup ⁡ ∥ f ∥ L ≤ 1 E x ∼ P r [ f ( x ) ] − E x ∼ P θ [ f ( x ) ] W\left(\mathbb{P}_r, \mathbb{P}_\theta\right)=\sup _{\|f\|_L \leq 1} \mathbb{E}_{x \sim \mathbb{P}_r}[f(x)]-\mathbb{E}_{x \sim \mathbb{P}_\theta}[f(x)] W(Pr,Pθ)=fL1supExPr[f(x)]ExPθ[f(x)]其中, f : X → R f:\mathcal X\rightarrow\R f:XR 为所有满足 1-Lipschitz 性质的函数。如果 f f f 仅满足 K K K-Lipschitz 性质,则有
    K ⋅ W ( P r , P θ ) = sup ⁡ ∥ f ∥ L ≤ K E x ∼ P r [ f ( x ) ] − E x ∼ P θ [ f ( x ) ] K\cdot W\left(\mathbb{P}_r, \mathbb{P}_\theta\right)=\sup _{\|f\|_L \leq K} \mathbb{E}_{x \sim \mathbb{P}_r}[f(x)]-\mathbb{E}_{x \sim \mathbb{P}_\theta}[f(x)] KW(Pr,Pθ)=fLKsupExPr[f(x)]ExPθ[f(x)]其中, K K K-Lipschitz 是指
    ∥ f ( x 1 ) − f ( x 2 ) ∥ ≤ K ∥ x 1 − x 2 ∥ \|f(x_1)-f(x_2)\|\leq K\|x_1-x_2\| f(x1)f(x2)Kx1x2( K = 1 K=1 K=1 for “1 −Lipschitz ⇒ \Rightarrow ∣ ∣ f ( x 1 ) − f ( x 2 ) ∣ ∣ ≤ ∣ ∣ x 1 − x 2 ∣ ∣ ||f(x_1)-f(x_2)||\leq||x_1-x_2|| ∣∣f(x1)f(x2)∣∣∣∣x1x2∣∣) 也就是说,Lipschitz 性质是要求 f f f 足够光滑,当输入发生改变时,输出发生的改变不会太大 (function does not change fast). 试想如果没有 Lipschitz 约束,由于 real data 和 generated data 之间很少会有 overlap,那么 f f f (i.e., discriminator) 会使 real data 对应的值趋近于 ∞ \infty ,generated data 对应的值趋近于 − ∞ -\infty ,因此训练永远都不会收敛。因此,WGAN 的优化目标
    在这里插入图片描述
  • 那么我们如何保证 f f f (i.e., discriminator) 满足 K K K-Lipschitz 呢?WGAN 采用的方法是在每次梯度更新后进行 weight clip,保证权重 w w w 里的每个值都介于 c c c − c -c c 之间 (if w > c w > c w>c, w = c w = c w=c; if w < − c w < -c w<c, w = − c w = -c w=c)。直观上看, w w w 里的值都比较小,因此当输入变化时,输出的变化总是有限的

在这里插入图片描述

WGAN 优化器的选择:作者发现 WGAN 在使用 Adam (with β 1 > 0 β_1 > 0 β1>0) 等 momentum based optimizer 或是采用大学习率时训练就会变得不稳定。对此,作者的解释是 “Since the loss for the critic is nonstationary, momentum based methods seemed to perform worse. We identified momentum as a potential cause because, as the loss blew up and samples got worse, the cosine between the Adam step and the gradient usually turned negative. The only places where this cosine was negative was in these situations of instability.” 因此,作者采用 RMSProp 优化器,该优化器在 nonstationary problems 上表现较好


Limitation of Weight Clipping

  • (1) We only ensure that ⇒ \Rightarrow ∣ ∣ f ( x 1 ) − f ( x 2 ) ∣ ∣ ≤ K ∣ ∣ x 1 − x 2 ∣ ∣ ||f(x_1)-f(x_2)||\leq K||x_1-x_2|| ∣∣f(x1)f(x2)∣∣K∣∣x1x2∣∣ for some K K K. 最后得出来的 wasserstein distance 时原来的 K K K,并且这个 K K K 是未知的
  • (2) Do not truly find function f f f maximizing the function: 有可能 w w w 不满足 weight clipping 的条件,但也可以使 f f f 满足 1-Lipschitz 限制;也就是说,weight clipping 只覆盖了满足 1-Lipschitz 限制的所有函数的一个 subspace

Two main benefits of WGAN

Meaningful loss metric

  • 由于 discriminator 衡量的是 wasserstein distance,因此 discriminator 的损失函数可以直观地反映 generator 是否收敛及其生成质量
  • 如果不使用 WGAN,由于 real data 和 generated data 之间通常没有 overlap,因此 JS divergence 经常保持在 log ⁡ 2 ≈ 0.69 \log2\approx0.69 log20.69,无法通过 loss function 来判断 real data 和 generated data 的相似程度
    在这里插入图片描述使用 WGAN 后,就可以用 wasserstein distance 来衡量 GAN 训练的好坏了!但需要注意的是,该损失函数并不能直接量化 GAN 的性能,这是因为我们只能约束 discriminator 满足 K K K-Lipschitz 性质,因此最终的损失函数其实是 K K K 倍的 wasserstein distance. 此外,实际中的 discriminator 也不是最优的,该损失函数也只是 wasserstein distance 的一个近似
    在这里插入图片描述

Improved stability

  • 在设计 GAN 的网络结构时,我们需要合理地平衡 generator 和 discriminator 的性能来保证训练的稳定性,一旦 discriminator 的性能过强,能完美区分生成数据和真实数据,JS 散度就会变成一个常数,损失函数无法给 generator 提供有效的梯度信息,训练就会停滞。通常的解决方法有 (1) 削弱 discriminator 的能力: 通过给它添加 Dropout、减少更新次数,让它无法 overfitting;但 Discriminator 能力过弱也有问题,它就无法衡量 JS divergence 了… (2) Add Noise (Noises decay over time): Add some artificial noise to the inputs of discriminator; Make the labels noisy for the discriminator (train discriminator 时,给 input / label 加 noise) ⇒ \Rightarrow P d a t a ( x ) P_{data}(x) Pdata(x) and P G ( x ) P_G(x) PG(x) have some overlap. Discriminator cannot perfectly separate real and generated data. 而由于 WGAN 采用 wasserstein distance,因此我们不用特别考虑 generator 和 discriminator 的平衡,可以大胆地训练 discriminator 到最优,discriminator 性能越好,衡量的 wasserstein distance 就越准确,给 generator 提供的梯度信息也就越有意义
  • 此外,作者还观察到 WGAN 对 generator 模型架构的选择更具鲁棒性,能极大地避免了 GAN 中经常出现的 mode collapse
    在这里插入图片描述在这里插入图片描述

References

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值