Modèle DDPM - dérivation de formule

Portail papier : Modèles probabilistes de diffusion de débruitage
Implémentation du code : Modèle DDPM —— Implémentation de Pytorch
Vidéo recommandée : 54. Modèle de diffusion probabiliste Théorie du modèle de diffusion probabiliste et interprétation détaillée du code PyTorch complet

Mathématiques requises :

联合概率(Probabilité conjointe):
P ( A , B , C ) = P ( C ∣ B , A ) P ( B , A ) = P ( C ∣ B , A ) P ( B ∣ A ) P ( A ) P (A, B, C)=P(C \milieu B, A) P(B, A)=P(C \milieu B, A) P(B \milieu A) P(A)P ( UNE ,B ,C )=P ( CB ,A ) P ( B ,A )=P ( CB ,A ) P ( BA ) P ( A )
条件概率(Probabilité conditionnelle):
P ( B , C ∣ A ) = P ( B ∣ A ) P ( C ∣ A , B ) P(B, C \mid A)=P(B \ milieu A) P(C \ milieu A, B)P ( B ,CA )=P ( BA ) P ( CUn ,B )
马尔可夫链(Chaîne de Markov):
p ( X t + 1 ∣ X t , … , X 1 ) = p ( X t + 1 ∣ X t ) p\left(X_{t+1} \mid X_ {t}, \ldots, X_{1}\right)=p\left(X_{t+1} \mid X_{t}\right)p( Xt + 1Xt,,X1)=p( Xt + 1Xt)
贝叶斯公式(Règle de Bayes):
P ( UNE je ∣ B ) = P ( B ∣ UNE je ) P ( UNE je ) ∑ j P ( B ∣ A j ) P ( UNE j ) P\left(A_{ i} \mid B\right)=\frac{P\left(B \mid A_{i}\right) P\left(A_{i}\right)}{\sum_{j} P\left(B \ milieu A_{j}\droite) P\gauche(A_{j}\droite)}P( UnjeB )=jeP( BUNje)P( Unje)P( BUNje)P( Unje)
Distribution normale (Distribution normale) X ∼ N ( μ , σ 2 ) X \sim N\left(\mu, \sigma^{2}\right)XN( moi ,p2 )Déterminer l'équation du graphique :
f ( x ) = 1 2 π σ e − ( x − µ ) 2 2 σ 2 f(x)=\frac{1}{\sqrt{2 \pi} \sigma} e^ {-\frac{(x-\mu)^{2}}{2\sigma^{2}}}f ( x )=14h _ p1e2 p2( x - μ )2
Deux distributions normales X ∼ N ( μ X , σ X 2 ) X \sim N\left(\mu_{X}, \sigma_{X}^{2}\right)XN( mX,pX2)Y ∼ N ( μ Y , σ Y 2 ) Y \sim N\left(\mu_{Y}, \sigma_{Y}^{2}\right)OuiN( mY,pOui2)的即加:
U = X + Y ∼ N ( μ X + μ Y , σ X 2 + σ Y 2 ) U=X+Y \sim N\left(\mu_{X}+\mu_{Y}, \ sigma_{X}^{2}+\sigma_{Y}^{2}\right)tu=X+OuiN( mX+mY,pX2+pOui2)
deux distributions normalesp , qp,qp ,q par le rapport KL (divergence de Kullback-Leibler) :
KL ( p , q ) = log ⁡ σ q σ p + σ p 2 + ( μ p − μ q ) 2 2 σ q 2 − 1 2 KL(p, q ) =\log \frac{\sigma_{q}}{\sigma_{p}}+\frac{\sigma_{p}^{2}+\left(\mu_{p}-\mu_{q}\right ) ^{2}}{2 \sigma_{q}^{2}}-\frac{1}{2}KL ( p , _q )=journal _pppq+2 pq2pp2+( mpmq)221
重technique des paramètres(Reparamétrisation):
X ∼ N ( μ , σ 2 ) , Y = X − μ σ ∼ N ( 0 , 1 ) 若X \sim N\left(\mu, \sigma^{2}\right ) , Y=\frac{X-\mu}{\sigma} \sim N(0,1)Si XN( moi ,p2 ),Oui=pXmN ( 0 ,1 )
A partir de la distribution normaleXXÉchantillonzz dans Xz , qui équivaut à YYde la distribution normale standardÉchantillonz 'z' dans Yzz = μ + σ × z ′ z = \mu + \sigma \times z'z=m+p×z
Formule de la formule quadratique :
ax 2 + bx = a ( x + b 2 a ) 2 + C ax^{2}+bx=a\left(x+\frac{b}{2 a}\right)^ {2 }+Cun x2+b x=un( x+2a _b)2+C

concept:

ttt : temps (nombre d'ajouts de bruit)
TTT : durée totale (nombre total d'ajouts de bruit)
x \mathbf{x}x : image
x 0 \mathbf{x}_{0}X0: Image du moment initial
xt \mathbf{x}_{t}XtttTemps t image
x T \mathbf{x}_{T}XT: Image du moment de terminaison
x 0 x_0X0~ q ( x 0 ) q(x_0)q ( x0)q ( x 0 ) q(x_0)q ( x0) : Distribution de l'image réelle
p θ ( x 0 ) : = ∫ p θ ( x 0 : T ) dx 1 : T p_\theta (x_0) := \int p_\theta (x_{0:T}) d x_{ 1:T}pje( x0):=pje( x0 : T) réx _1 : T, p θ(x0) p_\theta(x_0)pje( x0) : Générer la distribution d'image
θ \thetaθ : paramètre (de réseau)
β t \beta_{t}bt: La variance
β \beta du bruit ajouté au processus de diffusion au temps tβ : suite de variance de bruit, longueur T, en( 0 , 1 ) (0,1)( 0 ,1 ) Croissant monotone dans l'intervalle

Processus inverse:

L'expression mathématique du processus de diffusion inverse :
p θ ( x 0 : T ) : = p ( x T ) ∏ t = 1 T p θ ( xt − 1 ∣ xt ) p_{\theta}\left(\mathbf{x }_ {0 : T}\right):=p\left(\mathbf{x}_{T}\right) \prod_{t=1}^{T} p_{\theta}\left(\mathbf{ x} _{t-1} \mid \mathbf{x}_{t}\right)pje( x0 : T):=p( xT)t = 1Tpje( xt 1Xt) La distribution de probabilité conjointe p θ ( x 0 : T ) p_{\theta}\left(\mathbf{x}_{0 : T}\right) de
toutes les images temporellespje( x0 : T) , l'ensemble du processus est une chaîne de Markov. où,
p ( X T ) = N ( X T ; 0 , je ) p\left(\mathbf{x}_{T}\right)=\mathcal{N}\left(\mathbf{x}_{T } ; \mathbf{0}, \mathbf{I}\right)p( xT)=N( xT;0 ,je )
p ( X T ) p\left(\mathbf{x}_{T}\right)p( xT) est une distribution normale standard,x T \mathbf{x}_{T}XTest une valeur échantillonnée et n'a rien à voir avec les paramètres réseau.
ttDéfinissez la valeur de la constante t
 : p θ ( xt − 1 ∣ xt ) : = N ( xt − 1 ; µ θ ( xt , t ) , Σ θ ( xt , t ) ) p_{\theta}\left(\ mathbf {x}_{t-1} \mid \mathbf{x}_{t}\right):=\mathcal{N}\left(\mathbf{x}_{t-1} ; \symbole boule{\ mu}_{\theta}\left(\mathbf{x}_{t}, t\right), \ball symbol{\Sigma}_{\theta}\left(\mathbf{x}_{t}, t \droite)\droite)pje( xt 1Xt):=N( xt 1;mje( xt,t ),Sje( xt,t ) )
xt − 1 \mathbf{x}_{t-1}Xt 1Obéir à la moyenne est μ θ ( xt , t ) \boldsymbol{\mu}_{\theta}\left(\mathbf{x}_{t}, t\right)mje( xt,t ),方差为Σ θ ( xt , t ) \boldsymbol{\Sigma}_{\theta}\left(\mathbf{x}_{t}, t\right)Sje( xt,t ) de la distribution normale, l'auteur a mis la variance Σ θ ( xt , t ) \boldsymbol{\Sigma}_{\theta}\left(\mathbf{x}_{t}, t\right) dans l'originaltexteSje( xt,t )设为σ t 2 = β ~ t = 1 − α ˉ t − 1 1 − α ˉ t β t \sigma_{t}^{2}=\tilde{\beta}_{t}=\frac{ 1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_{t}} \beta_{t}pt2=b~t=1 unˉt1 unˉt 1bt(Après expérimentations, σ ​​t 2 = β t \sigma_{t}^{2}={\beta}_{t}pt2=btσ t 2 = β ~ t \sigma_{t}^{2}=\tilde{\beta}_{t}pt2=b~trésultats similaires), indépendamment des paramètres du modèle ( β ~ t \tilde{\beta}_{t}b~tseront mentionnés plus loin dans le calcul).

Processus de transfert :

L'expression mathématique du processus de diffusion :
q ( x 1 : T ∣ x 0 ) : = ∏ t = 1 T q ( xt ∣ xt − 1 ) q\left(\mathbf{x}_{1: T} \mid \mathbf {x}_{0}\right):=\prod_{t=1}^{T} q\left(\mathbf{x}_{t} \mid \mathbf{x}_{t-1 }\ droite)q( x1 : TX0):=t = 1Tq( xtXt 1)
Soit une image initialex 0 \mathbf{x}_{0}X0, tout le temps ( t > 0 t>0t>0 ), l'ensemble du processus est une chaîne de Markov.
ttDéfinissez l' exigence t
 : q ( xt ∣ xt − 1 ) : = N ( xt ; 1 − β txt − 1 , β t I ) q\left(\mathbf{x}_{t} \mid \mathbf {x }_{t-1}\right):=\mathcal{N}\left(\mathbf{x}_{t} ; \sqrt{1-\beta_{t}}\mathbf{x}_{ t- 1}, \beta_{t}\mathbf{I}\right)q( xtXt 1):=N( xt;1bt Xt 1,btje )
xt \mathbf{x}_{t}XtObéir à la moyenne est 1 − β txt − 1 \sqrt{1-\beta_{t}} \mathbf{x}_{t-1}1bt Xt 1, la variance est β t \beta_{t}btdistribution normale de . En utilisant la technique des paramètres lourds, l'image xt \mathbf{x}_{t}
à tout momentXtPeut être obtenu à partir de l'image du moment initial x 0 \mathbf{x}_{0}X0Et la séquence de variance de bruit β \betaβ pour déterminer, pour simplifier l'expression, définirα t : = 1 − β t \alpha_{t}:=1-\beta_{t}unt:=1btα ˉ t : = ∏ s = 1 t α s \bar{\alpha}_{t}:=\prod_{s=1}^{t} \alpha_{s}unˉt:=s = 1tuns,mais:
xt = α txt - 1 + 1 - α t ϵ t - 1 = α t ( α t - 1 xt - 2 + 1 - α t - 1 ϵ t - 2 ) + 1 - α t ϵ t - 1 = α t α t - 1 xt - 2 + α t 1 - α t - 1 ϵ t - 2 + 1 - α t ϵ t - 1 = α t α t - 1 xt - 2 + α t - α t α t - 1 + 1 - α t ϵ ‾ t - 2 = α t α t - 1 xt - 2 + 1 - α t α t - 1 ϵ ‾ t - 2 = ... = α ˉ tx 0 + 1 - α ˉ t ϵ \ début {aligné} \mathbf{x}_{t} & =\sqrt{\alpha_{t}}\mathbf{x}_{t-1}+\sqrt{1-\alpha_{t}}\mathbf{ \epsilon }_{t-1} \\ & =\sqrt{\alpha_{t}} (\sqrt{\alpha_{t-1}} \mathbf{x}_{t-2}+\sqrt{1 -\ alpha_{t-1}} \mathbf{\epsilon}_{t-2})+\sqrt{1-\alpha_{t}}\mathbf{\epsilon}_{t-1}\\ & = \sqrt {\alpha_{t}\alpha_{t-1}} \mathbf{x}_{t-2}+ \sqrt{\alpha_{t}}\sqrt{1-\alpha_{t-1}} \mathbf {\epsilon}_{t-2}+\sqrt{1-\alpha_{t}} \mathbf{\epsilon}_{t-1} \\ & =\sqrt{\alpha_{t}\alpha_ {t -1}} \mathbf{x}_{t-2}+ \sqrt{\alpha_{t}-\alpha_{t}\alpha_{t-1} +1-\alpha_{t}}\overline{\mathbf{\epsilon}}_{t-2}\\&=\sqrt{\alpha_{t}\alpha_{t-1}}\mathbf{x}_ {t-2}+\sqrt{1-\alpha_{t} \alpha_{t-1}} \overline{\mathbf{\epsilon}}_{t-2} \\ & =\ldots \\ & = \sqrt{\bar{\alpha}_{t}} \mathbf{x}_{0}+\sqrt{1-\bar{\alpha}_{t}} \mathbf{\epsilon} \end{aligné } }Xt=unt Xt 1+1unt ϵt 1=unt (unt 1 Xt 2+1unt 1 ϵt 2)+1unt ϵt 1=untunt 1 Xt 2+unt 1unt 1 ϵt 2+1unt ϵt 1=untunt 1 Xt 2+untuntunt 1+1unt ϵt 2=untunt 1 Xt 2+1untunt 1 ϵt 2==unˉt X0+1unˉt ϵ
La formule ci-dessus peut être réécrite en utilisant xt \mathbf{x}_{t}Xtet ϵ {\epsilon}ϵ pour exprimerx 0 \mathbf{x}_{0}X0:
X 0 = 1 α ˉ t ( xt − 1 − α ˉ t ϵ ) \mathbf{x}_{0}=\frac{1}{\sqrt{\bar{\alpha}_{t}}}\ gauche(\mathbf{x}_{t}-\sqrt{1-\bar{\alpha}_{t}}\mathbf{\epsilon}\droite)X0=unˉt 1( xt1unˉt ϵ )
(le processus de dérivation utilise la formule de superposition de deux distributions normales)
où,ϵ i \mathbf{\epsilon}_{i}ϵje~ N ( 0 , je ) \mathcal{N}\left(\mathbf{0}, \mathbf{I}\right)N( 0 ,je )

Perte:

Une borne supérieure sur la log-vraisemblance négative :
E q [ - log ⁡ p θ ( X 0 ) ] ≤ E q [ - log ⁡ p θ ( X 0 ) ] + DKL ( q ( X 1 : T ∣ X 0 ) ∥ p ( X 1 : T ∣ X 0 ) ) = E q [ - journal ⁡ p θ ( X 0 ) ] + E q [ journal ⁡ q ( X 1 : T ∣ X 0 ) p θ ( X 0 : T ) / p θ ( X 0 ) ] = E q [ - journal ⁡ p θ ( X 0 ) ] + E q [ - journal ⁡ p θ ( X 0 : T ) q ( X 1 : T ∣ X 0 ) + journal ⁡ p θ ( X 0 ) ] = E q [ - log ⁡ p θ ( X 0 : T ) q ( X 1 : T ∣ X 0 ) ] \begin{aligned} \mathbb{E}_{q}\left[-\log p_{\theta}\left (\mathbf{x}_{0}\right)\right] & \leq \mathbb{E}_{q}\left[-\log p_{\theta}\left(\mathbf{x}_{0 }\right)\right] + D_{\mathrm{KL}}\left(q\left(\mathbf{x}_{1:T}\mid \mathbf{x}_{0} \right) \| p\left(\mathbf{x}_{1:T} \mid \mathbf{x}_{0}\right)\right)\\ & =\mathbb{E}_{q}\left[-\ log p_{\theta}\left(\mathbf{x}_{0}\right)\right] + \mathbb{E}_{q}\left[\log \frac{q\left(\mathbf{x }_{1:T} \mid \mathbf{x}_{0}\right)}{p_{\theta}\left(\mathbf{x}_{0 : T}\right) / p_{\theta}\left(\ mathbf{x}_{0}\right)}\right] \\ & =\mathbb{E}_{q}\left[-\log p_{\theta}\left(\mathbf{x}_{0 }\right)\right] + \mathbb{E}_{q}\left[-\log\frac{p_{\theta}\left(\mathbf{x}_{0:T}\right)}{ q\left(\mathbf{x}_{1:T}\mid\mathbf{x}_{0}\right)}+\log p_{\theta}\left(\mathbf{x}_{0} \right)\right]\\ & =\mathbb{E}_{q}\left[-\log \frac{p_{\theta}\left(\mathbf{x}_{0:T}\right) }{q\left(\mathbf{x}_{1:T}\mid\mathbf{x}_{0}\right)}\right]\\\end{aligné}T} \mid \mathbf{x}_{0}\right)}+\log p_{\theta}\left(\mathbf{x}_{0}\right)\right]\\ & =\mathbb{ E}_{q}\left[-\log\frac{p_{\theta}\left(\mathbf{x}_{0 : T}\right)}{q\left(\mathbf{x}_{ 1 : T} \mid \mathbf{x}_{0}\right)}\right]\\\end{aligné}T} \mid \mathbf{x}_{0}\right)}+\log p_{\theta}\left(\mathbf{x}_{0}\right)\right]\\ & =\mathbb{ E}_{q}\left[-\log\frac{p_{\theta}\left(\mathbf{x}_{0 : T}\right)}{q\left(\mathbf{x}_{ 1 : T} \mid \mathbf{x}_{0}\right)}\right]\\\end{aligned}Eq[ -journal _pje( x0) ]Eq[ -journal _pje( x0) ]+DKL( q( x1 : TX0)p( x1 : TX0) )=Eq[ -journal _pje( x0) ]+Eq[ journal _pje( x0 : T)/ pje( x0)q( x1 : TX0)]=Eq[ -journal _pje( x0) ]+Eq[ -journal _q( x1 : TX0)pje( x0 : T)+journal _pje( x0) ]=Eq[ -journal _q( x1 : TX0)pje( x0 : T)]
定义损失函数L:
E q [ − log ⁡ p θ ( x 0 ) ] ≤ E q [ − log ⁡ p θ ( x 0 : T ) q ( x 1 : T ∣ x 0 ) ] : = L \mathbb{ E}_{q}\left[-\log p_{\theta}\left(\mathbf{x}_{0}\right)\right] \leq\mathbb{E}_{q}\left[- \log \frac{p_{\theta}\left(\mathbf{x}_{0 : T}\right)}{q\left(\mathbf{x}_{1 : T} \mid \mathbf{x }_{0}\right)}\right] :=LEq[ -journal _pje( x0) ]Eq[ -journal _q( x1 : TX0)pje( x0 : T)]:=
Dérivation supplémentaire de L L :
\mathbf{x}_{0}\right) \| p_{\theta}\left(\mathbf{x}_{t-1}\mid \mathbf{x}_{t}\right)\right)-\log p_{\theta}\left(\mathbf{ x}_{0} \mid \mathbf{x}_{1}\right)\right]\\\end{aligné}L=Eq[ -journal _q( x1 : TX0)pje( x0 : T)]=Eq[ -journal _p( xT)t 1journal _q( xtXt 1)pje( xt 1Xt)]=Eq[ -journal _p( xT)t > 1journal _q( xtXt 1)pje( xt 1Xt)journal _q( x1X0)pje( x0X1)]=Eq[ -journal _p( xT)t > 1journal _q( xt 1Xt,X0)pje( xt 1Xt)q( xtX0)q( xt 1X0)journal _q( x1X0)pje( x0X1)]=Eq[ -journal _q( xTX0)p( xT)t > 1journal _q( xt 1Xt,X0)pje( xt 1Xt)journal _pje( x0X1) ]=Eq[ DKL( q( xTX0)p( xT) )+t > 1DKL( q( xt 1Xt,X0)pje( xt 1Xt) )journal _pje( x0X1) ]
avec LT{L}_{T}LT, L t − 1 {L}_{t-1}Lt 1, L 0 {L}_{0} L0Définition :
L = E q [ DKL ( q ( X T ∣ X 0 ) ∥ p ( X T ) ) ⏟ LT + ∑ t > 1 DKL ( q ( xt - 1 ∣ xt , x 0 ) ∥ p θ ( xt - 1 ∣ xt ) ) ⏟ L t − 1 − log ⁡ p θ ( X 0 ∣ X 1 ) ⏟ L 0 ] L = \mathbb{E}_{q}[\underbrace{D_{\mathrm{KL }}\ gauche(q\gauche(\mathbf{x}_{T}\mid \mathbf{x}_{0}\right) \|p\left(\mathbf{x}_{T}\right) \right) }_{L_{T}}+\sum_{t>1}\underbrace{D_{\mathrm{KL}}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{ x}_{t}, \mathbf{x}_{0}\right) \|p_{\theta}\left(\mathbf{x}_{t-1}\mid \mathbf{x} _{t }\right)\right)}_{L_{t-1}} \underbrace{-\log p_{\theta}\left(\mathbf{x}_{0}\mid \mathbf{x} _{1 }\right)}_{L_{0}}]L=Eq[LT DKL( q( xTX0)p( xT) )+t > 1Lt 1 DKL( q( xt 1Xt,X0)pje( xt 1Xt) )L0 journal _pje( x0X1)]
premier élémentLT{L}_{T}LTet les paramètres de réseau θ \thetaθ n'est pas pertinent et peut être ignoré.
Pour le troisième élémentL 0 {L}_{0}L0进行分析:
p θ ( X 0 ∣ X 1 ) = ∏ je = 1 ré ∫ δ − ( X 0 je ) δ + ( X 0 je ) N ( X ; μ θ je ( X 1 , 1 ) , σ 1 2 ) dx δ + ( X ) = { ∞ si X = 1 X + 1 255 si x < 1 δ − ( X ) = { − ∞ si x = − 1 X − 1 255 si x > − 1 \begin{aligned} p_{\theta}\left(\mathbf{x}_{0} \mid \mathbf{x}_{1}\right) & =\prod_{i=1}^{D} \int_{\delta_{ -}\left(x_{0}^{i}\right)}^{\delta_{+}\left(x_{0}^{i}\right)} \mathcal{N}\left(x ; \ mu_{\theta}^{i}\left(\mathbf{x}_{1}, 1\right), \sigma_{1}^{2}\right) dx \\ \delta_{+}(x) & =\left\{\begin{array}{ll} \infty & \text { if } x=1 \\ x+\frac{1}{255} & \text { if } x<1 \end{array} \quad \delta_{-}(x)=\left\{\begin{array}{ll} -\infty & \text { if } x=-1 \\ x-\frac{1}{255} & \ texte { si } x>-1 \end{tableau}\right.\right. \end{aligné}pje( x0X1)d+( x )=je = 1d( x0je)d+( x0je)N( x ;mjeje( x1,1 ),p12)réx _={ X+2551 si  x=1 si  x<1d( x )={ X2551 si  x=1 si  x> 1
Cela équivaut au passage d'un espace continu à un espace discret, c'est-à-dire à la transformation d'une distribution gaussienne continue en une distribution gaussienne discrète pour correspondre aux données d'image d'entrée.
Pour le second terme L t − 1 {L}_{t-1}Lt 1Analyse :
Le premier terme de la divergence KL q ( xt − 1 ∣ xt , x 0 ) q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf {x }_{0}\right)q( xt 1Xt,X0) , alors
q ( xt − 1 ∣ xt , x 0 ) = N ( xt − 1 ; μ ~ t ( xt , x 0 ) , β ~ t je ) q\left(\mathbf{x}_{t-1 } \mid \mathbf{x}_{t}, \mathbf{x}_{0}\right)=\mathcal{N}\left(\mathbf{x}_{t-1} ; symbole boule {\ mu}}_{t}\left(\mathbf{x}_{t}, \mathbf{x}_{0}\right), \tilde{\beta}_{t}\mathbf{I}\right )q( xt 1Xt,X0)=N( xt 1;m~t( xt,X0),b~tI )
À l'aide de la formule bayésienne et de la formule, calculezq ( xt − 1 ∣ xt , x 0 ) q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \ mathbf {x}_{0}\right)q( xt 1Xt,X0)
q ( ​​xt - 1 ∣ xt , x 0 ) = q ( xt ∣ xt - 1 , x 0 ) q ( xt - 1 ∣ x 0 ) q ( xt ∣ x 0 ) ∝ exp ⁡ ( - 1 2 ( ( xt - α txt - 1 ) 2 β t + ( xt - 1 - α ˉ t - 1 X 0 ) 2 1 - α ˉ t - 1 - ( xt - α ˉ tx 0 ) 2 1 - α ˉ t ) ) = exp ⁡ ( − 1 2 ( ( α t β t + 1 1 − α ˉ t − 1 ) xt − 1 2 − ( 2 α t β txt + 2 α t − 1 1 − α ˉ t − 1 x 0 ) xt − 1 + C ( xt , x 0 ) ) ) \begin{aligné} q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}, \mathbf{x}_{0 }\right) & =q\left(\mathbf{x}_{t} \mid \mathbf{x}_{t-1},\mathbf{x}_{0}\right) \frac{q\left(\mathbf{x}_{t-1}\mid \mathbf{x}_{0}\right)}{q\left( \mathbf{x}_{t}\mid \mathbf{x}_{0}\right)}\\&\propto\exp\left(-\frac{1}{2}\left(\frac{\ gauche (\mathbf{x}_{t}-\sqrt{\alpha_{t}}\mathbf{x}_{t-1}\right)^{2}}{\beta_{t}}+\frac {\left(\mathbf{x}_{t-1}-\sqrt{\bar{\alpha}_{t-1}}\mathbf{x}_{0}\right)^{2}}{ 1-\bar{\alpha}_{t-1}}-\frac{\left(\mathbf{x}_{t}-\sqrt{\bar{\alpha}_{t}} \mathbf{x }_{0}\right)^{2}}{1-\bar{\alpha}_{t}}\right)\right) \\ & =\exp \left(-\frac{1}{2 }\left(\left(\frac{\alpha_{t}}{\beta_{t}}+\frac{1}{1-\bar{\alpha}_{t-1}}\right) \mathbf {x}_{t-1}^{2}-\left(\frac{2 \sqrt{\alpha_{t}}}{\beta_{t}} \mathbf{x}_{t}+\frac {2 \sqrt{\alpha_{t-1}}}{1-\bar{\alpha}_{t-1}} \mathbf{x}_{0}\right) \mathbf{x}_{t -1}+C\left(\mathbf{x}_{t}, \mathbf{x}_{0}\right)\right)\right)\end{aligné}\mathbf{x}_{0}\right)\right)\right) \end{aligned}\mathbf{x}_{0}\right)\right)\right) \end{aligned}\mathbf{x}_{0}\right)\right)\right) \end{aligned}\mathbf{x}_{0}\right)\right)\right) \end{aligned}q( xt 1Xt,X0)=q( xtXt 1,X0)q( xtX0)q( xt 1X0)exp( -21(bt( xtunt Xt 1)2+1unˉt 1( xt 1unˉt 1 X0)21unˉt( xtunˉt X0)2) )=exp( -21( (btunt+1unˉt 11)Xt - 12(bt2unt Xt+1unˉt 12unt 1 X0)Xt 1+C( xt,X0) ) )
Obtenir la variance β ~ t \tilde{\beta}_{t}b~t
β ~ t = 1 / ( α t β t + 1 1 − α ˉ t − 1 ) = 1 − α ˉ t − 1 α t + β t − α ˉ t ⋅ β t = 1 − α ˉ t − 1 1 − α ˉ t ⋅ β t \begin{aligned} \tilde{\beta}_{t} & =1 /\left(\frac{\alpha_{t}}{\beta_{t}}+\frac{ 1}{1-\bar{\alpha}_{t-1}}\right)\\ &=\frac{1-\bar{\alpha}_{t-1}}{ {\alpha}_ { t}+{\beta}_{t} -\bar{\alpha}_{t}} \cdot \beta_{t}\\ &=\frac{1-\bar{\alpha}_{t-1 }}{1-\bar{\alpha}_{t}} \cdot \beta_{t}\\ \end{aligned}b~t=1/(btunt+1unˉt 11)=unt+btunˉt1unˉt 1bt=1unˉt1unˉt 1bt
Obtenir la valeur moyenne μ ~ t ( xt , x 0 ) \tilde{\boldsymbol{\mu}}_{t}\left(\mathbf{x}_{t}, \mathbf{x}_{0}\ droite)m~t( xt,X0)
μ ~ t ( xt , X 0 ) = ( α t β txt + α ˉ t − 1 1 − α ˉ t − 1 x 0 ) / ( α t β t + 1 1 − α ˉ t − 1 ) = α t ( 1 - α ˉ t - 1 ) α t + β t - α ˉ txt + α ˉ t - 1 β t α t + β t - α ˉ tx 0 = α t ( 1 - α ˉ t - 1 ) 1 − α ˉ txt + α ˉ t − 1 β t 1 − α ˉ tx 0 \begin{aligned} \tilde{\boldsymbol{\mu}}_{t}\left(\mathbf{x}_{t} , \mathbf{x}_{0}\right)&=\left(\frac{\sqrt{\alpha_{t}}}{\beta_{t}} \mathbf{x}_{t}+\frac {\sqrt{\bar{\alpha}_{t-1}}}{1-\bar{\alpha}_{t-1}} \mathbf{x}_{0}\right) /\left( \frac{\alpha_{t}}{\beta_{t}}+\frac{1}{1-\bar{\alpha}_{t-1}}\right)\\ &=\frac{\sqrt {\alpha_{t}}\left(1-\bar{\alpha}_{t-1}\right)}{ { \alpha }_{t}+{\beta}_{t}-\bar{ \alpha}_{t}}\mathbf{x}_{t}+\frac{\sqrt{\bar{\alpha}_{t-1}} \beta_{t}}{ {\alpha}_{t}+{\beta}_{t}-\bar{\alpha}_{t}} \mathbf{x}_{0}\\ &=\frac{\sqrt{\alpha_ {t}}\left(1-\bar{\alpha}_{t-1}\right)}{1-\bar{\alpha}_{t}} \mathbf{x}_{t}+\ frac{\sqrt{\bar{\alpha}_{t-1}} \beta_{t}}{1-\bar{\alpha}_{t}} \mathbf{x}_{0}\\ \ fin {aligné}m~t( xt,X0)=(btunt Xt+1unˉt 1unˉt 1 X0)/(btunt+1unˉt 11)=unt+btunˉtunt ( 1unˉt 1)Xt+unt+btunˉtunˉt 1 btX0=1unˉtunt ( 1unˉt 1)Xt+1unˉtunˉt 1 btX0
Utilisez xt \mathbf{x}_{t}Xtet ϵ {\epsilon}ϵ pour exprimerx 0 \mathbf{x}_{0}X0
μ ~ t = α t ( 1 - α ˉ t - 1 ) 1 - α ˉ txt + α ˉ t - 1 β t 1 - α ˉ t 1 α ˉ t ( xt - 1 - α ˉ t ϵ ) = 1 α t ( xt - β t 1 - α ˉ t ϵ ) \begin{aligned} \tilde{\boldsymbol{\mu}}_{t} & =\frac{\sqrt{\alpha_{t}}\left( 1-\bar{\alpha}_{t-1}\right)}{1-\bar{\alpha}_{t}} \mathbf{x}_{t}+\frac{\sqrt{\bar {\alpha}_{t-1}} \beta_{t}}{1-\bar{\alpha}_{t}} \frac{1}{\sqrt{\bar{\alpha}_{t} }}\left(\mathbf{x}_{t}-\sqrt{1-\bar{\alpha}_{t}} \mathbf{\epsilon}\right) \\ & =\frac{1}{ \sqrt{\alpha_{t}}}\left(\mathbf{x}_{t}-\frac{\beta_{t}}{\sqrt{1-\bar{\alpha}_{t}}} \mathbf{\epsilon}\right) \end{aligné}m~t=1unˉtunt ( 1unˉt 1)Xt+1unˉtunˉt 1 btunˉt 1( xt1unˉt ) _=unt 1( xt1unˉt btϵ ).
Le second terme de la divergence KL p θ ( xt − 1 ∣ xt ) p_{\theta}\left(\mathbf{x}_{t-1} \mid \mathbf{x}_{t}\right)pje( xt 1Xt) , a été défini dans le processus de diffusion inverse, l'auteur met la varianceΣ θ ( xt , t ) \boldsymbol{\Sigma}_{\theta}\left(\mathbf{x}_{t}, t\ droite)Sje( xt,t ) Ensembleσ t 2 = β ~ t \sigma_{t}^{2}=\tilde{\beta}_{t}pt2=b~tp θ ( xt - 1 ∣ xt ) : = N ( xt - 1 ; μ θ ( xt , t ) , Σ θ ( xt , t ) ) =
N ( xt - 1 ; μ θ ( xt , t ) , σ t 2 ) \begin{aligned} p_{\theta}\left(\mathbf{x}_{t-1}\mid \mathbf{x}_{t}\right)&:=\mathcal{N}\ left (\mathbf{x}_{t-1} ; \ball symbol{\mu}_{\theta}\left(\mathbf{x}_{t}, t\right), \ball symbol{\Sigma} _ {\theta}\left(\mathbf{x}_{t}, t\right)\right)\\ &=\mathcal{N}\left(\mathbf{x}_{t-1} ; \ symbole de boule {\mu}_{\theta}\left(\mathbf{x}_{t}, t\right), \symbole de boule{\sigma}^{2}_{t}\right)\\\ fin{aligné } }pje( xt 1Xt):=N( xt 1;mje( xt,t ),Sje( xt,t ) )=N( xt 1;mje( xt,t ),pt2)
En utilisant la formule de calcul de la divergence KL de deux distributions normales (avec la même variance), elle peut être calculée comme suit :
L t − 1 = E q [ 1 2 σ t 2 ∥ μ ~ t ( xt , x 0 ) − μ θ ( xt , t ) ∥ 2 ] + C L_{t-1}=\mathbb{E}_{q}\left[\frac{1}{2 \sigma_{t}^{2}}\left\| \tilde{ \boldsymbol{\mu}}_{t}\left(\mathbf{x}_{t}, \mathbf{x}_{0}\right)-\boldsymbol{\mu}_{\theta }\gauche (\mathbf{x}_{t}, t\droite)\droite\|^{2}\droite]+CLt 1=Eq[2 pt21m~t( xt,X0)mje( xt,t )2 ]+C
utilisex 0 \mathbf{x}_{0}X0et ϵ \epsilonϵ pour exprimerxt \mathbf{x}_{t}Xt, ϵ \epsilonϵ ~N ( 0 , je ) \mathcal{N}\left(\mathbf{0}, \mathbf{I}\right)N( 0 ,I ) :
xt ( X 0 , ϵ ) = α ˉ tx 0 + 1 − α ˉ t ϵ \mathbf{x}_{t}\left(\mathbf{x}_{0}, \ball symbol{\epsilon } \right)=\sqrt{\bar{\alpha}_{t}}\mathbf{x}_{0}+\sqrt{1-\bar{\alpha}_{t}}\symbole boule{\ epsilon}Xt( x0,) _=unˉt X0+1unˉt ϵ
Alors,L t − 1 − C L_{t-1}-CLt 1C peut être exprimé par :
L t - 1 - C = E X 0 , ϵ [ 1 2 σ t 2 ∥ μ ~ t ( xt ( X 0 , ϵ ) , 1 α ˉ t ( xt ( X 0 , ϵ ) - 1 - α ˉ t ϵ ) ) - μ θ ( xt ( X 0 , ϵ ) , t ) ∥ 2 ] = E X 0 , ϵ [ 1 2 σ t 2 ∥ 1 α t ( xt ( X 0 , ϵ ) - β t 1 - α ˉ t ϵ ) − μ θ ( xt ( X 0 , ϵ ) , t ) ∥ 2 ] \begin{aligned} L_{t-1}-C & =\mathbb{E}_{\mathbf{x}_{0 }, \symbole boule{\epsilon}}\left[\frac{1}{2 \sigma_{t}^{2}}\left\|\tilde{\symbole boule{\mu}}_{t}\ gauche(\mathbf{x}_{t}\left(\mathbf{x}_{0}, \symbole de boule{\epsilon}\right), \frac{1}{\sqrt{\bar{\alpha} _{t }}}\left(\mathbf{x}_{t}\left(\mathbf{x}_{0}, \symbole boule{\epsilon}\right)-\sqrt{1-\bar{ \alpha}_ {t}} \symbole boule{\epsilon}\right)\right)-\symbole boule{\mu}_{\theta}\left(\mathbf{x}_{t}\left(\ mathbf{x}_{ 0}, \ball symbol{\epsilon}\right), t\right)\right\|^{2}\right] \\ & =\mathbb{E}_{\mathbf{x }_{0},\boldsymbol{\epsilon}}\left[\frac{1}{2 \sigma_{t}^{2}}\left\|\frac{1}{\sqrt{\alpha_{t}}}\left( \mathbf{x}_{t}\left(\mathbf{x}_{0}, \boldsymbol{\epsilon}\right)-\frac{\beta_{t}}{\sqrt{1-\bar{ \alpha}_{t}}} \boldsymbol{\epsilon}\right)-\boldsymbol{\mu}_{\theta}\left(\mathbf{x}_{t}\left(\mathbf{x} _{0}, \boldsymbol{\epsilon}\right), t\right)\right\|^{2}\right] \end{aligned}Lt 1C=EX0, ϵ[2 pt21 m~t( xt( x0,) _,unˉt 1( xt( x0,) _1unˉt ) ) _mje( xt( x0,) _,t ) 2 ]=EX0, ϵ[2 pt21 unt 1( xt( x0,) _1unˉt bt) _mje( xt( x0,) _,t ) 2 ]
La formule ci-dessus montre que, étant donné xt \mathbf{x}_{t}XtDans le cas de , la sortie du réseau μ θ ( xt ( x 0 , ϵ ) , t ) \boldsymbol{\mu}_{\theta}\left(\mathbf{x}_{t}\left(\mathbf{ x }_{0}, \boldsymbol{\epsilon}\right), t\right)mje( xt( x0,) _,t ) champ1 α t ( xt ( X 0 , ϵ ) − β t 1 − α ˉ t ϵ ) \frac{1}{\sqrt{\alpha_{t}}}\left(\mathbf{x}_ { t}\left(\mathbf{x}_{0}, \ball symbol{\epsilon}\right)-\frac{\beta_{t}}{\sqrt{1-\bar{\alpha}_{t }}} \symbole boule{\epsilon}\right)unt 1( xt( x0,) _1 unˉt btϵ ) .
Mais l'auteur n'a pas construit le réseau de cette manière, mais a choisi d'utiliserμ θ ( xt , t ) \boldsymbol{\mu}_{\theta}\left(\mathbf{x}_{t}, t\right )mje( xt,t )进行参数化处理 :
μ θ ( xt , t ) = μ ~ t ( xt , 1 α ˉ t ( xt - 1 - α ˉ t ϵ θ ( xt ) ) ) = 1 α t ( xt - β t 1 − α ˉ t ϵ θ ( xt , t ) ) \boldsymbol{\mu}_{\theta}\left(\mathbf{x}_{t}, t\right)=\tilde{\boldsymbol{\mu} }_{t}\left(\mathbf{x}_{t}, \frac{1}{\sqrt{\bar{\alpha}_{t}}}\left(\mathbf{x}_{t }-\sqrt{1-\bar{\alpha}_{t}} \boldsymbol{\epsilon}_{\theta}\left(\mathbf{x}_{t}\right)\right)\right) =\frac{1}{\sqrt{\alpha_{t}}}\left(\mathbf{x}_{t}-\frac{\beta_{t}}{\sqrt{1-\bar{\alpha }_{t}}} \boldsymbol{\epsilon}_{\theta}\left(\mathbf{x}_{t}, t\right)\right)mje( xt,t )=m~t( xt,unˉt 1( xt1unˉt ϵje( xt) ) )=unt 1( xt1unˉt btϵje( xt,t ) )
On peut voir que le réseau passe l'entréext \mathbf{x}_{t}Xtet t{t}t , la sortie réelle estϵ θ {\epsilon}_{\theta}ϵje(c'est-à-dire le bruit de prédiction), tandis que xt \mathbf{x}_{t}XtEt il peut être donné par x 0 \mathbf{x}_{0}X0Pour exprimer, la finale L t − 1 − C L_{t-1}-CLt 1Définir C
: E X 0 , ϵ [ β t 2 2 σ t 2 α t ( 1 − α ˉ t ) ∥ ϵ − ϵ θ ( α ˉ tx 0 + 1 − α ˉ t ϵ , t ) ∥ \mathbb{E }_{\mathbf{x}_{0}, \symbole boule{\epsilon}}\left[\frac{\beta_{t}^{2}}{2 \sigma_{t}^{2 } \alpha_ {t}\left(1-\bar{\alpha}_{t}\right)}\left\|\ballsymbol{\epsilon}-\ballsymbol{\epsilon}_{\theta}\left( \sqrt{ \bar{\alpha}_{t}} \mathbf{x}_{0}+\sqrt{1-\bar{\alpha}_{t}} \symbole boule{\epsilon}, t\right )\ droite\|^{2}\droite]EX0, ϵ[2 pt2unt( 1unˉt)bt2 ϵϵje(unˉt X0+1unˉt ϵ ,t ) 2 ]
Objectivement, on peut calculer la quantité et le taux de perte :
L simple ( θ ) : = E t , x 0 , ϵ [ ∥ ϵ − ϵ θ ( α ˉ tx 0 + 1 − α ˉ t ϵ , t ) ∥ 2 ] L_{\text {simple}}(\theta):=\mathbb{E}_{t, \mathbf{x}_{0}, \ball symbol{\epsilon}}\left[\left \| \ball symbol{\epsilon}-\ball symbol{\epsilon}_{\theta}\left(\sqrt{\bar{\alpha}_{t}} \mathbf{x}_{0}+\sqrt{ 1-\bar{\alpha}_{t}}\ballsymbol{\epsilon}, t\right)\right\|^{2}\right]Lsimple ( je ):=Et , x0, ϵ[ ϵϵje(unˉt X0+1unˉt ϵ ,t ) 2 ]

Je suppose que tu aimes

Origine blog.csdn.net/Peach_____/article/details/128694125
conseillé
Classement