Diffusion Model(2):前向扩散过程和逆向降噪过程

Diffusion Model(2):前向扩散过程和逆向降噪过程

​ 观看本文之前建议先观看以下文章:

​ 在推导过程中会参考其中中的一些公式,使用到的公式都会标注出来。

​ Diffusion Models(扩散模型)包含以下三类:

​ 本文以2020年Ho等人的DDPM为例,其包含了前向扩散过程反向的扩散过程

​ 其中,前向扩散过程是为了将复杂的分布转化为一个简单的分布。而反向扩散过程则是从简单分布逆转得到复杂分布。

Forward diffusion process

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

​ 扩散(Diffusion)在热力学中指细小颗粒从高密度区域扩散至低密度区域,在统计领域,扩散则指将复杂的分布转换为一个简单的分布的过程。

​ Diffusion模型定义了一个概率分布转换模型 T \mathcal{T} T,能将原始数据 x 0 x_0 x0构成的复杂分布 q c o m p l e x q_{\mathrm{complex}} qcomplex转换为一个简单的已知参数的先验分布 p p r i o r p_{\mathrm{prior}} pprior
x 0 ∼ q c o m p l e x ⟹ T ( x 0 ) ∼ p p r i o r \begin{equation} \mathbf{x}_0 \sim q_\mathrm{complex}⟹\mathcal{T}(\mathbf{x}_0) \sim p_\mathrm{prior} \end{equation} x0qcomplexT(x0)pprior
​ 具体来说,Diffusion模型提出可以用马尔科夫链(Markov Chain)来构造 T \mathcal{T} T,即定义一系列条件概率分布 q ( x t ∣ x t − 1 ) t ∈ { 1 , 2 , 3... T } q(\mathbf{x}_t \vert \mathbf{x}_{t-1})\quad t\in\{1,2,3...T\} q(xtxt1)t{ 1,2,3...T},将 x 0 \mathbf{x_0} x0依次转换为 x 1 \mathbf{x_1} x1 x 2 \mathbf{x_2} x2 , . . . , x T ,...,\mathbf{x_T} ,...,xT,希望当 T → inf ⁡ T \rightarrow \inf Tinf时, x T ∼ p prior  \mathbf{x}_{T} \sim p_{\text {prior }} xTpprior 

​ 为了简洁和有效,此处的 p prior  p_{\text {prior }} pprior 选择高斯分布,因此整个前向扩散过程可以被看作是,在 T T T步内,不断添加少量的高斯噪声到样本中。
q ( x t ∣ x t − 1 ) = N ( x t ; 1 − β t x t − 1 , β t I ) q ( x 1 : T ∣ x 0 ) = ∏ t = 1 q ( x t ∣ x t − 1 ) q ( x T ) = p prior  ( x T ) = N ( x T ; 0 , I )  where  T → inf ⁡ \begin{equation} \begin{array}{c} q\left(\mathbf{x}_{t} \vert \mathbf{x}_{t-1}\right)=\mathcal{N}\left(\mathbf{x}_{t} ; \sqrt{1-\beta_{t}} \mathbf{x}_{t-1}, \beta_{t} \mathrm{I}\right) \\ q\left(\mathbf{x}_{1: T} \vert \mathbf{x}_{0}\right)=\prod_{t=1} q\left(\mathbf{x}_{t} \vert \mathbf{x}_{t-1}\right)\\ q\left(\mathbf{x}_{T}\right)=p_{\text {prior }}\left(\mathbf{x}_{T}\right)=\mathcal{N}\left(\mathbf{x}_{T} ; \mathbf{0}, \mathrm{I}\right) \quad \text { where } T \rightarrow \inf \end{array} \end{equation} q(xtxt1)=N(xt;1βt xt1,βtI)q(x1:Tx0)=t=1q(xtxt1)q(xT)=pprior (xT)=N(xT;0,I) where Tinf
​ 即已知 x t − 1 \mathbf{x_{t-1}} xt1的时候, x t \mathbf{x_t} xt的概率分布为一个平均值为 1 − β t x t − 1 \sqrt{1-\beta_{t}} \mathbf{x}_{t-1} 1βt xt1,方差为 β t I \beta_tI βtI的高斯分布。随着 T T T的不断增大,最终数据分布变成了一个简单固定的高斯分布。

​ 然后对公式2使用Diffusion Model(1):预备知识中提到的重参数化技巧(以下Diffusion Model(1):预备知识中的公式用1-xx代替)进行重参数化可以得到:
x t = 1 − β t x t − 1 + β t z t − 1  where  z t − 1 ∈ N ( 0 , I ) \begin{equation} \mathbf{x}_{t}=\sqrt{1-\beta_{t}} \mathbf{x}_{t-1}+\sqrt{\beta_{t}} \mathbf{z}_{t-1} \quad \text { where } \mathbf{z}_{t-1} \in \mathcal{N}(0, \mathbf{I}) \end{equation} xt=1βt xt1+βt zt1 where zt1N(0,I)
​ 这一过程即将高斯分布采样的过程变成了将 x t − 1 \mathbf{x_{t-1}} xt1与标准高斯分布噪声 z \mathbf{z} z混合,扩散率系数 β t \beta_t βt控制融合 x t − 1 \mathbf{x_{t-1}} xt1分布和标准高斯分布的比例。

​ 设 α t = 1 − β t \alpha_t=1-\beta_t αt=1βt以及 α ˉ t = ∏ i = 1 t α i \bar{\alpha}_{t}=\prod_{i=1}^{t} \alpha_{i} αˉt=i=1tαi,那么公式3就变成了:
x t = α t x t − 1 + 1 − α t z t − 1 ;  where  z t − 1 , z t − 2 , ⋯ ∼ N ( 0 , I ) = α t ( α t − 1 x t − 2 + 1 − α t − 1 z t − 2 ) + 1 − α t z t − 1 = α t α t − 1 x t − 2 + α t ( 1 − α t − 1 ) z t − 2 + 1 − α t z t − 1 = α t α t − 1 x t − 2 + 1 − α t − 1 α t z ˉ t − 2 ;  where  z ˉ t − 2 , z ˉ t − 3 , ⋯ ∼ N ( 0 , I ) = α ˉ t x 0 + 1 − α ˉ t z \begin{equation} \begin{array}{rlr} \mathbf{x}_{t} & =\sqrt{\alpha_{t}} {\color{blue}\mathbf{x}_{t-1}}+\sqrt{1-\alpha_{t}} \mathbf{z}_{t-1} & ; \text { where } \mathbf{z}_{t-1}, \mathbf{z}_{t-2}, \cdots \sim \mathcal{N}(\mathbf{0}, \mathbf{I}) \\ & =\sqrt{\alpha_t}{\color{blue}(\sqrt{\alpha_{t-1}}x_{t-2} + \sqrt{1- \alpha_{t-1}} z_{t-2})} + \sqrt{1- \alpha_t} z_{t-1} & \\ & =\sqrt{\alpha_t\alpha_{t-1}}x_{t-2} + {\color{red}\sqrt{ {\alpha_t}(1- \alpha_{t-1})} z_{t-2} + \sqrt{1- \alpha_t} z_{t-1}} \\ &= \sqrt{\alpha_t\alpha_{t-1}}x_{t-2} + {\color{red}\sqrt{1- \alpha_{t-1}\alpha_t} \bar{z}_{t-2}} & ; \text { where } \bar{\mathbf{z}}_{t-2}, \bar{\mathbf{z}}_{t-3}, \cdots \sim \mathcal{N}(\mathbf{0}, \mathbf{I})\\ & =\sqrt{\bar{\alpha}_{t}} \mathbf{x}_{0}+\sqrt{1-\bar{\alpha}_{t}} \mathbf{z} & \\ \end{array} \end{equation} xt=αt xt1+1αt zt1=αt (αt1 xt2+1αt1 zt2)+1αt zt1=αtαt1 xt2+αt(1αt1) zt2+1αt zt1=αtαt1 xt2+1αt1αt zˉt2=αˉt x0+1αˉt z; where zt1,zt2,N(0,I); where zˉt2,zˉt3,N(0,I)
​ 其中公式4从第一行到第二行是将 x t − 1 \mathbf{x_{t-1}} xt1继续利用重参数化技巧展开,而从第三行到第四行利用了当两个高斯分布 N ( 0 , σ 1 2 I ) \mathcal{N}\left(\mathbf{0}, \sigma_{1}^{2} \mathbf{I}\right) N(0,σ12I) N ( 0 , σ 2 2 I ) \mathcal{N}\left(\mathbf{0}, \sigma_{2}^{2} \mathbf{I}\right) N(0,σ22I)相加时,新的分布为 N ( 0 , ( σ 1 2 + σ 2 2 ) I ) \mathcal{N}\left(\mathbf{0}, (\sigma_{1}^{2}+\sigma_{2}^{2}) \mathbf{I}\right) N(0,(σ12

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值