patrickvonplaten commited on
Commit
f373c9c
1 Parent(s): b423e20

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +200 -2
README.md CHANGED
@@ -1,6 +1,204 @@
1
  ---
2
  license: apache-2.0
 
 
3
  tags:
4
- - kandinsky
5
- duplicated_from: ai-forever/kandinsky-2-1
6
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ prior:
4
+ - kandinsky-community/kandinsky-2-1-prior
5
  tags:
6
+ - text-to-image
 
7
  ---
8
+
9
+ # Kandinsky 2.1
10
+
11
+ Kandinsky 2.1 inherits best practices from Dall-E 2 and Latent diffusion while introducing some new ideas.
12
+
13
+ It uses the CLIP model as a text and image encoder, and diffusion image prior (mapping) between latent spaces of CLIP modalities. This approach increases the visual performance of the model and unveils new horizons in blending images and text-guided image manipulation.
14
+
15
+ The Kandinsky model is created by [Arseniy Shakhmatov](https://github.com/cene555), [Anton Razzhigaev](https://github.com/razzant), [Aleksandr Nikolich](https://github.com/AlexWortega), [Igor Pavlov](https://github.com/boomb0om), [Andrey Kuznetsov](https://github.com/kuznetsoffandrey) and [Denis Dimitrov](https://github.com/denndimitrov)
16
+
17
+ ## Usage
18
+
19
+ Kandinsky 2.1 is available in diffusers!
20
+
21
+ ```python
22
+ pip install diffusers transformers
23
+ ```
24
+ ### Text to image
25
+
26
+ ```python
27
+ from diffusers import KandinskyPipeline, KandinskyPriorPipeline
28
+ import torch
29
+
30
+
31
+ pipe_prior = KandinskyPriorPipeline.from_pretrained("YiYiXu/Kandinsky-prior", torch_dtype=torch.float16)
32
+ pipe_prior.to("cuda")
33
+
34
+ prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting"
35
+ negative_prompt = "low quality, bad quality"
36
+
37
+ image_emb = pipe_prior(
38
+ prompt, guidance_scale=1.0, num_inference_steps=25, generator=generator, negative_prompt=negative_prompt
39
+ ).images
40
+
41
+ zero_image_emb = pipe_prior(
42
+ negative_prompt, guidance_scale=1.0, num_inference_steps=25, generator=generator, negative_prompt=negative_prompt
43
+ ).images
44
+
45
+ pipe = KandinskyPipeline.from_pretrained("YiYiXu/Kandinsky", torch_dtype=torch.float16)
46
+ pipe.to("cuda")
47
+
48
+
49
+ images = pipe(
50
+ prompt,
51
+ image_embeds=image_emb,
52
+ negative_image_embeds=zero_image_emb,
53
+ num_images_per_prompt=2,
54
+ height=768,
55
+ width=768,
56
+ num_inference_steps=100,
57
+ guidance_scale=4.0,
58
+ generator=generator,
59
+ ).images[0]
60
+
61
+ image.save("./cheeseburger_monster.png")
62
+ ```
63
+
64
+ ![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/cheeseburger.png)
65
+
66
+
67
+ ### Text Guided Image-to-Image Generation
68
+
69
+ ```python
70
+ from diffusers import KandinskyImg2ImgPipeline, KandinskyPriorPipeline
71
+ import torch
72
+
73
+ from PIL import Image
74
+ import requests
75
+ from io import BytesIO
76
+
77
+ url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
78
+ response = requests.get(url)
79
+ original_image = Image.open(BytesIO(response.content)).convert("RGB")
80
+ original_image = original_image.resize((768, 512))
81
+
82
+ # create prior
83
+ pipe_prior = KandinskyPriorPipeline.from_pretrained("YiYiXu/Kandinsky-prior", torch_dtype=torch.float16)
84
+ pipe_prior.to("cuda")
85
+
86
+ # create img2img pipeline
87
+ pipe = KandinskyImg2ImgPipeline.from_pretrained("YiYiXu/Kandinsky", torch_dtype=torch.float16)
88
+ pipe.to("cuda")
89
+
90
+ prompt = "A fantasy landscape, Cinematic lighting"
91
+ negative_prompt = "low quality, bad quality"
92
+
93
+ image_emb = pipe_prior(
94
+ prompt, guidance_scale=4.0, num_inference_steps=25, generator=generator, negative_prompt=negative_prompt
95
+ ).images
96
+
97
+ zero_image_emb = pipe_prior(
98
+ negative_prompt, guidance_scale=4.0, num_inference_steps=25, generator=generator, negative_prompt=negative_prompt
99
+ ).images
100
+
101
+ out = pipe(
102
+ prompt,
103
+ image=original_image,
104
+ image_embeds=image_emb,
105
+ negative_image_embeds=zero_image_emb,
106
+ height=768,
107
+ width=768,
108
+ num_inference_steps=500,
109
+ strength=0.3,
110
+ )
111
+
112
+ out.images[0].save("fantasy_land.png")
113
+ ```
114
+
115
+ ![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/img2img_fantasyland.png)
116
+
117
+
118
+ ### Interpolate
119
+
120
+ ```python
121
+ from diffusers import KandinskyPriorPipeline, KandinskyPipeline
122
+ from diffusers.utils import load_image
123
+ import PIL
124
+
125
+ import torch
126
+ from torchvision import transforms
127
+
128
+ pipe_prior = KandinskyPriorPipeline.from_pretrained("YiYiXu/Kandinsky-prior", torch_dtype=torch.float16)
129
+ pipe_prior.to("cuda")
130
+
131
+ img1 = load_image(
132
+ "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
133
+ )
134
+
135
+ img2 = load_image(
136
+ "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/starry_night.jpeg"
137
+ )
138
+
139
+ images_texts = ["a cat", img1, img2]
140
+ weights = [0.3, 0.3, 0.4]
141
+ image_emb, zero_image_emb = pipe_prior.interpolate(images_texts, weights)
142
+
143
+ pipe = KandinskyPipeline.from_pretrained("YiYiXu/Kandinsky", torch_dtype=torch.float16)
144
+ pipe.to("cuda")
145
+
146
+ image = pipe(
147
+ "", image_embeds=image_emb, negative_image_embeds=zero_image_emb, height=768, width=768, num_inference_steps=150
148
+ ).images[0]
149
+
150
+ image.save("starry_cat.png")
151
+ ```
152
+ ![img](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/kandinsky-docs/starry_cat.png)
153
+
154
+
155
+ ## Model Architecture
156
+
157
+ ### Overview
158
+ Kandinsky 2.1 is a text-conditional diffusion model based on unCLIP and latent diffusion, composed of a transformer-based image prior model, a unet diffusion model, and a decoder.
159
+
160
+ The model architectures are illustrated in the figure below - the chart on the left describes the process to train the image prior model, the figure in the center is the text-to-image generation process, and the figure on the right is image interpolation.
161
+
162
+ <p float="left">
163
+ <img src="https://raw.githubusercontent.com/ai-forever/Kandinsky-2/main/content/kandinsky21.png"/>
164
+ </p>
165
+
166
+ Specifically, the image prior model was trained on CLIP text and image embeddings generated with a pre-trained [mCLIP model](https://huggingface.co/M-CLIP/XLM-Roberta-Large-Vit-L-14). The trained image prior model is then used to generate mCLIP image embeddings for input text prompts. Both the input text prompts and its mCLIP image embeddings are used in the diffusion process. A [MoVQGAN](https://openreview.net/forum?id=Qb-AoSw4Jnm) model acts as the final block of the model, which decodes the latent representation into an actual image.
167
+
168
+
169
+ ### Details
170
+ The image prior training of the model was performed on the [LAION Improved Aesthetics dataset](https://huggingface.co/datasets/bhargavsdesai/laion_improved_aesthetics_6.5plus_with_images), and then fine-tuning was performed on the [LAION HighRes data](https://huggingface.co/datasets/laion/laion-high-resolution).
171
+
172
+ The main Text2Image diffusion model was trained on the basis of 170M text-image pairs from the [LAION HighRes dataset](https://huggingface.co/datasets/laion/laion-high-resolution) (an important condition was the presence of images with a resolution of at least 768x768). The use of 170M pairs is due to the fact that we kept the UNet diffusion block from Kandinsky 2.0, which allowed us not to train it from scratch. Further, at the stage of fine-tuning, a dataset of 2M very high-quality high-resolution images with descriptions (COYO, anime, landmarks_russia, and a number of others) was used separately collected from open sources.
173
+
174
+
175
+ ### Evaluation
176
+ We quantitatively measure the performance of Kandinsky 2.1 on the COCO_30k dataset, in zero-shot mode. The table below presents FID.
177
+
178
+ FID metric values ​​for generative models on COCO_30k
179
+ | | FID (30k)|
180
+ |:------|----:|
181
+ | eDiff-I (2022) | 6.95 |
182
+ | Image (2022) | 7.27 |
183
+ | Kandinsky 2.1 (2023) | 8.21|
184
+ | Stable Diffusion 2.1 (2022) | 8.59 |
185
+ | GigaGAN, 512x512 (2023) | 9.09 |
186
+ | DALL-E 2 (2022) | 10.39 |
187
+ | GLIDE (2022) | 12.24 |
188
+ | Kandinsky 1.0 (2022) | 15.40 |
189
+ | DALL-E (2021) | 17.89 |
190
+ | Kandinsky 2.0 (2022) | 20.00 |
191
+ | GLIGEN (2022) | 21.04 |
192
+
193
+ For more information, please refer to the upcoming technical report.
194
+
195
+ ## BibTex
196
+ If you find this repository useful in your research, please cite:
197
+ ```
198
+ @misc{kandinsky 2.1,
199
+ title = {kandinsky 2.1},
200
+ author = {Arseniy Shakhmatov, Anton Razzhigaev, Aleksandr Nikolich, Vladimir Arkhipkin, Igor Pavlov, Andrey Kuznetsov, Denis Dimitrov},
201
+ year = {2023},
202
+ howpublished = {},
203
+ }
204
+ ```