DALLE2: Hierarchical Text-Conditional Image Generation with CLIP Latents
paper: https://cdn.openai.com/papers/dall-e-2.pdf
github: https://github.com/lucidrains/DALLE2-pytorch
DALLE2概覽:
- CLIP模型:
用于生成text embedding zt 和image embedding zi
- prior模型:
1) 模型輸入:為 the encoded text,the CLIP text embedding,time_embed,image_embed,learned_queries,(文本整體embedding,文本序列embedding,時間步embedding,當(dāng)前t步對應(yīng)的圖片embedding,用于輸出transformer 結(jié)果手動構(gòu)造用于學(xué)習(xí)的embedding )
2) 模型: diffusion model使用transformer(不是unet)直接預(yù)測x0,然后通過diffusion遞推公式生成前一步圖片embedding.
3)最終輸出:為 image Embedding (不同于上面CLIP生成的image embedding )
- decoder 模型
1)模型輸入:為 prior 輸出的image Embedding
2)模型:diffusion model使用unet網(wǎng)絡(luò),預(yù)測噪聲z (不同于prior模型直接預(yù)測x0)
3)模型輸出:經(jīng)過T步去噪后,最后一步x0即為模型輸出
0 Abstract
基于對比學(xué)習(xí)思想,我們提出了兩階段模型,
①一個先驗?zāi)P蚿rior:
- 在給定文本條件下生成CLIP的 image embedding
② 一個decoder模型:
- 在給定imge embedding 條件下,生成圖片
We use diffusion models for the decoder and experiment with both autoregressive and diffusion models for the prior, finding that the latter are computationally more efficient and produce higher quality samples.
我們使用diffusion 模型作為decoder 模型,實驗了自回歸autoregressive 和diffusion模型作為prior模型,發(fā)現(xiàn)diffusion 模型作為先驗?zāi)P托н^更好
1 Introduction
- 虛線上面的是CLIP模型,通過CLIP模型可以學(xué)習(xí)到text 和image的embedding,
- 虛線以下是文本到圖片的生成過程,
① CLIP的 text embedding 喂給autoregressive或者diffusion模型( prior模型),生成image embedding
② 然后根據(jù)上面的image embedding喂給decoder 模型,生成最終的圖片image
2 Method
- Our training dataset consists of pairs (x, y) of images x and their corresponding captions y. Given an image x,let zi and zt be its CLIP image and text embeddings, respectively. We design our generative stack to produce images from captions using two components:
- 我們訓(xùn)練數(shù)據(jù)集由成對的(x,y)組成,x是圖片,y是文本,給定x和y,通過CLIP模型,可以分別生成image 和text embedding,zi和 zt。
- A prior P(zi|y) that produces CLIP image embeddings zi conditioned on captions y.
一個prior 模型用在給定文本時,生成image embedding zi. - A decoder P(x|zi, y) that produces images x conditioned on CLIP image embeddings zi (and optionally text captions y).
decoder 模型用于在給定條件zi時,生成最終圖片 x。
整個過程如下所示
2.1 Decoder
-
We use diffusion models to produce images conditioned on CLIP image embeddings (and optionally text captions).
-
在prior模型生成的image embedding的基礎(chǔ)上, 我們使用 diffusion models生成image。
-
將image embedding作為條件直接加上timestep embedding(也可以選擇添加加text embedding,實驗發(fā)現(xiàn)用處不大),然后通過下面的diffusion 去噪公式 ,選擇unet網(wǎng)絡(luò)預(yù)測噪聲,生成最終的圖片x
μ ˉ t = 1 α t ( x t ? 1 ? α t 1 ? α ˉ t z t ) \bar \mu_t=\frac{1 } {\sqrt \alpha_{t}} (x_t -\frac{1-\alpha_t } {\sqrt{1- \bar \alpha_{t}}} z_t) μˉ?t?=α?t?1?(xt??1?αˉt??1?αt??zt?)
2.2 Prior
? While a decoder can invert CLIP image embeddings zi to produce images x, we need a prior model that produces zi from captions y to enable image generations from text captions.
decoder 模型輸入 image embedding zi 生成image x,需要prior模型生成的zi.
? Diffusion prior: The continuous vector zi is directly modelled using a Gaussian diffusion model conditioned on the caption y.
Diffusion prior : 給定文本y(clip 模型生成的文本向量)時,通過Gaussian diffusion model 直接生成 zi。為了改善樣本質(zhì)量,訓(xùn)練時我們隨機mask掉10%的文本數(shù)據(jù)。文章來源:http://www.zghlxwxcb.cn/news/detail-722133.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-722133.html
- 對于 diffusion prior,我們訓(xùn)練一個 decoder-only的Transformer模型,對輸入序列使用causal attention mask。用于預(yù)測x0 (重點:不是噪聲zt)
- Transformer模型的輸入: the encoded text,the CLIP text embedding,time_embed,image_embed,learned_queries,(文本整體embedding,文本序列embedding,時間步embedding,當(dāng)前t步對應(yīng)的圖片embedding,用于輸出transformer 結(jié)果手動構(gòu)造用于學(xué)習(xí)的embedding )
- diffusion 過程: 隨機初始化xt,dffusion通過下面公式反向傳播公式生成x(t-1)數(shù)據(jù)(transformer 模型直接生成x0),直到最后一步x0
μ ˉ t ( x t , x 0 ) = α t ( 1 ? α ˉ t ? 1 ) 1 ? α ˉ t x t + α ˉ t ? 1 ( 1 ? α t ) 1 ? α ˉ t x 0 \bar \mu_t(x_t,x_0)=\frac{\sqrt{\alpha_{t}}(1-\bar \alpha_{t-1} ) } {1- \bar \alpha_{t}} x_t +\frac{\sqrt{\bar \alpha_{t-1}}(1-\alpha_t) } {1- \bar \alpha_{t}} x_0 μˉ?t?(xt?,x0?)=1?αˉt?αt??(1?αˉt?1?)?xt?+1?αˉt?αˉt?1??(1?αt?)?x0?
到了這里,關(guān)于DALLE2論文解讀及實現(xiàn)(一)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!