🚀 Kandinsky 2.1
Kandinsky 2.1繼承了Dall - E 2和潛在擴散模型的最佳實踐,同時引入了一些新思路。它利用CLIP模型作為文本和圖像編碼器,並在CLIP模態的潛在空間之間使用擴散圖像先驗(映射)。這種方法提升了模型的視覺性能,為圖像融合和文本引導的圖像操作開闢了新的前景。
該Kandinsky模型由Arseniy Shakhmatov、Anton Razzhigaev、Aleksandr Nikolich、Igor Pavlov、Andrey Kuznetsov和Denis Dimitrov創建。
🚀 快速開始
Kandinsky 2.1可在diffusers庫中使用!
pip install diffusers transformers accelerate
✨ 主要特性
Kandinsky 2.1繼承了Dall - E 2和潛在擴散模型的優點,引入新思想,使用CLIP模型作為文本和圖像編碼器,利用擴散圖像先驗提升視覺性能,支持文本引導的圖像生成和修復等操作。
📦 安裝指南
pip install diffusers transformers accelerate
💻 使用示例
基礎用法
以下是文本引導的圖像修復生成示例:
from diffusers import AutoPipelineForInpainting
from diffusers.utils import load_image
import torch
import numpy as np
pipe = AutoPipelineForInpainting.from_pretrained("kandinsky-community/kandinsky-2-1-inpaint", torch_dtype=torch.float16)
pipe.enable_model_cpu_offload()
prompt = "a hat"
negative_prompt = "low quality, bad quality"
original_image = load_image(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
)
mask = np.zeros((768, 768), dtype=np.float32)
mask[:250, 250:-250] = 1
image = pipe(prompt=prompt, image=original_image, mask_image=mask).images[0]
image.save("cat_with_hat.png")

高級用法
關於Kandinsky圖像修復的重大變更
我們在以下拉取請求中對Kandinsky圖像修復管道進行了重大更改:https://github.com/huggingface/diffusers/pull/4207。之前我們接受的掩碼格式是黑色像素表示被掩碼的區域,這與diffusers中的所有其他管道不一致。我們已經更改了Kandinsky中的掩碼格式,現在使用白色像素表示被掩碼的區域。
如果您在生產環境中使用Kandinsky圖像修復,請升級您的代碼以遵循上述更改。您現在需要將掩碼更改為:
import PIL.ImageOps
mask = PIL.ImageOps.invert(mask)
mask = 1 - mask
📚 詳細文檔
模型架構概述
Kandinsky 2.1是一個基於unCLIP和潛在擴散的文本條件擴散模型,由基於Transformer的圖像先驗模型、Unet擴散模型和解碼器組成。
模型架構如下圖所示 - 左側的圖表描述了訓練圖像先驗模型的過程,中間的圖是文本到圖像的生成過程,右側的圖是圖像插值。
具體來說,圖像先驗模型是在使用預訓練的[mCLIP模型](https://huggingface.co/M-CLIP/XLM - Roberta - Large - Vit - L - 14)生成的CLIP文本和圖像嵌入上進行訓練的。訓練好的圖像先驗模型然後用於為輸入文本提示生成mCLIP圖像嵌入。輸入文本提示及其mCLIP圖像嵌入都在擴散過程中使用。[MoVQGAN](https://openreview.net/forum?id=Qb - AoSw4Jnm)模型作為模型的最後一個模塊,將潛在表示解碼為實際圖像。
模型訓練細節
- 圖像先驗訓練:模型的圖像先驗訓練是在LAION Improved Aesthetics數據集上進行的,然後在[LAION HighRes數據](https://huggingface.co/datasets/laion/laion - high - resolution)上進行微調。
- 主文本到圖像擴散模型訓練:主文本到圖像擴散模型是在來自[LAION HighRes數據集](https://huggingface.co/datasets/laion/laion - high - resolution)的1.7億個文本 - 圖像對上進行訓練的(一個重要條件是存在分辨率至少為768x768的圖像)。使用1.7億對是因為我們保留了Kandinsky 2.0中的UNet擴散塊,這使我們不必從頭開始訓練它。此外,在微調階段,使用了一個從開放源單獨收集的包含200萬個非常高質量的高分辨率圖像及其描述的數據集(COYO、動漫、俄羅斯地標等)。
模型評估
我們在COCO_30k數據集上以零樣本模式定量測量了Kandinsky 2.1的性能。下表展示了FID指標。
生成模型在COCO_30k上的FID指標值
|
FID (30k) |
eDiff - I (2022) |
6.95 |
Image (2022) |
7.27 |
Kandinsky 2.1 (2023) |
8.21 |
Stable Diffusion 2.1 (2022) |
8.59 |
GigaGAN, 512x512 (2023) |
9.09 |
DALL - E 2 (2022) |
10.39 |
GLIDE (2022) |
12.24 |
Kandinsky 1.0 (2022) |
15.40 |
DALL - E (2021) |
17.89 |
Kandinsky 2.0 (2022) |
20.00 |
GLIGEN (2022) |
21.04 |
更多信息,請參考即將發佈的技術報告。
📄 許可證
本項目採用Apache 2.0許可證。
BibTex
如果您在研究中發現此倉庫有用,請引用:
@misc{kandinsky 2.1,
title = {kandinsky 2.1},
author = {Arseniy Shakhmatov, Anton Razzhigaev, Aleksandr Nikolich, Vladimir Arkhipkin, Igor Pavlov, Andrey Kuznetsov, Denis Dimitrov},
year = {2023},
howpublished = {},
}