本文主要是介绍DENOISING DIFFUSION IMPLICIT MODELS(DDIM 去噪扩散隐式模型公式推导),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
DENOISING DIFFUSION IMPLICIT MODELS(DDIM 去噪扩散隐式模型公式推导)
DDIM思想,去掉DDPM去噪过程的马尔可夫性质,达到跳步去噪的目的。DDIM思想实现方法:假设一个不服从马尔可夫的逆向去噪转移分布 P ( x t ∣ x t − 1 , x 0 ) ∼ N ( k x 0 + m x t , σ 2 I ) P(x_t \mid x_{t-1},x_0)\sim N(kx_0+mx_t,\sigma^2I) P(xt∣xt−1,x0)∼N(kx0+mxt,σ2I)。
推导
P ( x t − 1 ∣ x t , x 0 ) = P ( x t ∣ x t − 1 , x 0 ) ⋅ P ( x t − 1 ∣ x 0 ) P ( x t ∣ x 0 ) (1) P(x_{t-1}\mid x_t,x_0) = \frac{P(x_t \mid x_{t-1},x_0)\cdot P(x_{t-1}\mid x_0)}{P(x_t\mid x_0)} \tag{1} P(xt−1∣xt,x0)=P(xt∣x0)P(xt∣xt−1,x0)⋅P(xt−1∣x0)(1)
其中 P ( x t ∣ x t − 1 , x 0 ) P(x_t \mid x_{t-1},x_0) P(xt∣xt−1,x0) 由于不服从马尔可夫性质,不能像DDPM一样化简为 P ( x t ∣ x t − 1 ) P(x_t \mid x_{t-1}) P(xt∣xt−1)
现在假设
P ( x t ∣ x t − 1 , x 0 ) ∼ N ( k x 0 + m x t , σ 2 I ) (2) P(x_t \mid x_{t-1},x_0)\sim N(kx_0+mx_t,\sigma^2I) \tag{2} P(xt∣xt−1,x0)∼N(kx0+mxt,σ2I)(2)
显示表达为:
x t − 1 = k x 0 + m x t + σ ϵ (3) x_{t-1}=kx_0+mx_t+\sigma\epsilon \tag{3} xt−1=kx0+mxt+σϵ(3)
由于DDIM的前向加噪过程和DDPM一样,那么:
x t = α t ‾ x 0 + 1 − α t ‾ ϵ ′ (4) x_t = \sqrt{\overline{\alpha_t}}x_{0}+\sqrt{1-\overline{\alpha_t}}\epsilon^\prime \tag{4} xt=αtx0+1−αtϵ′(4)
带入可知:
x t − 1 = k x 0 + m ( α t ‾ x 0 + 1 − α t ‾ ϵ ′ ) + σ ϵ = ( k + m α t ‾ ) x 0 + ( m 1 − α t ‾ ) ϵ ′ + σ ϵ = ( k + m α t ‾ ) x 0 + m 2 ( 1 − α t ‾ ) + σ 2 ϵ ( 重参数化技巧 ) \begin{align} x_{t-1}&=kx_0+m(\sqrt{\overline{\alpha_t}}x_{0}+\sqrt{1-\overline{\alpha_t}}\epsilon^\prime)+\sigma\epsilon \\ &=(k+m\sqrt{\overline{\alpha_t}})x_0+(m\sqrt{1-\overline{\alpha_t}})\epsilon^\prime+\sigma\epsilon \\ &=(k+m\sqrt{\overline{\alpha_t}})x_0+\sqrt{m^2(1-\overline{\alpha_t})+\sigma^2}\epsilon ~~~~~~~~~~~(重参数化技巧) \tag{5} \end{align} xt−1=kx0+m(αtx0+1−αtϵ′)+σϵ=(k+mαt)x0+(m1−αt)ϵ′+σϵ=(k+mαt)x0+m2(1−αt)+σ2ϵ (重参数化技巧)(5)
由于:
x t − 1 = α t − 1 ‾ x 0 + 1 − α t − 1 ‾ ϵ (6) x_{t-1} = \sqrt{\overline{\alpha_{t-1}}}x_{0}+\sqrt{1-\overline{\alpha_{t-1}}}\epsilon \tag{6} xt−1=αt−1x0+1−αt−1ϵ(6)
对比公式(5)(6)得到:
{ k + m α t ‾ = α t − 1 ‾ m 2 ( 1 − α t ‾ ) + σ 2 = 1 − α t − 1 ‾ (7) \begin{cases} k+m\sqrt{\overline{\alpha_t}}&= \sqrt{\overline{\alpha_{t-1}}} \\ m^2(1-\overline{\alpha_t})+\sigma^2 &= 1-\overline{\alpha_{t-1}} \tag{7} \end{cases} {k+mαtm2(1−αt)+σ2=αt−1=1−αt−1(7)
解方程组得到:
{ m = 1 − α t − 1 ‾ − σ 2 1 − α t ‾ k = α t − 1 ‾ − 1 − α t − 1 ‾ − σ 2 α t ‾ 1 − α t ‾ (8) \begin{cases} m &= \frac{\sqrt{1-\overline{\alpha_{t-1}}-\sigma^2}}{\sqrt{1-\overline{\alpha_t}}} \\ k &= \sqrt{\overline{\alpha_{t-1}}} -\sqrt{1-\overline{\alpha_{t-1}}-\sigma^2} \frac{\sqrt{\overline{\alpha_t}}}{\sqrt{1-\overline{\alpha_t}}} \tag{8} \end{cases} ⎩ ⎨ ⎧mk=1−αt1−αt−1−σ2=αt−1−1−αt−1−σ21−αtαt(8)
带入 m , k m,k m,k 得到
x t − 1 = α t − 1 ‾ x 0 + 1 − α t − 1 ‾ − σ 2 x t − α t ‾ x 0 1 − α t ‾ (9) x_{t-1} =\sqrt{\overline{\alpha_{t-1}}}x_0+\sqrt{1-\overline{\alpha_{t-1}}-\sigma^2}\frac{x_t-\sqrt{\overline{\alpha_t}}x_0}{\sqrt{1-\overline{\alpha_t}}} \tag{9} xt−1=αt−1x0+1−αt−1−σ21−αtxt−αtx0(9)
利用公式(4),将公式(9)中的 x 0 x_0 x0由 x t x_t xt表示,那么可以化简为( ϵ θ ( x t ) \epsilon_\theta(x_t) ϵθ(xt) 为公式4中的 ϵ ′ \epsilon^\prime ϵ′)
x t − 1 = α t − 1 ‾ ( x t − 1 − α t ‾ ϵ θ ( x t ) α t ‾ ) + 1 − α t − 1 ‾ − σ 2 ϵ θ ( x t ) + σ ϵ (10) x_{t-1} = \sqrt{\overline{\alpha_{t-1}}}(\frac{x_t-\sqrt{1-\overline{\alpha_t}}\epsilon_\theta(x_t)}{\sqrt{\overline{\alpha_t}}})+\sqrt{1-\overline{\alpha_{t-1}}-\sigma^2}\epsilon_\theta(x_t)+\sigma\epsilon \tag{10} xt−1=αt−1(αtxt−1−αtϵθ(xt))+1−αt−1−σ2ϵθ(xt)+σϵ(10)
用 s s s表示 t − 1 t-1 t−1, k k k 表示 t t t得出通用公式:
x s = α s ‾ ( x k − 1 − α k ‾ ϵ θ ( x k ) α k ‾ ) + 1 − α s ‾ − σ 2 ϵ θ ( x k ) + σ ϵ (11) x_{s} = \sqrt{\overline{\alpha_{s}}}(\frac{x_k-\sqrt{1-\overline{\alpha_k}}\epsilon_\theta(x_k)}{\sqrt{\overline{\alpha_k}}})+\sqrt{1-\overline{\alpha_{s}}-\sigma^2}\epsilon_\theta(x_k)+\sigma\epsilon \tag{11} xs=αs(αkxk−1−αkϵθ(xk))+1−αs−σ2ϵθ(xk)+σϵ(11)
通过公式(11)实现DDIM去马尔可夫化,跨越多步采样。
DDIM完结
参考:
DDPM推导
简短清晰的DDIM视频讲解
比较白话的DDIM视频讲解
文章信息
发表时间:2021,发表地点:ICLR,作者:Jiaming Song,机构:stanford
@inproceedings{
song2021denoising,
title={Denoising Diffusion Implicit Models},
author={Jiaming Song and Chenlin Meng and Stefano Ermon},
booktitle={International Conference on Learning Representations},
year={2021},
url={https://openreview.net/forum?id=St1giarCHLP}
}
这篇关于DENOISING DIFFUSION IMPLICIT MODELS(DDIM 去噪扩散隐式模型公式推导)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!