YiYiXu commited on
Commit
62c0df5
1 Parent(s): 7382d76

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +117 -0
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ prior:
4
+ - kandinsky-community/kandinsky-2-2-prior
5
+ tags:
6
+ - text-to-image
7
+ - kandinsky
8
+ ---
9
+
10
+ # Kandinsky 2.2
11
+
12
+ Kandinsky inherits best practices from Dall-E 2 and Latent diffusion while introducing some new ideas.
13
+
14
+ 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.
15
+
16
+ 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)
17
+
18
+ ## Usage
19
+
20
+ Kandinsky 2.2 is available in diffusers!
21
+
22
+ ```python
23
+ pip install diffusers transformers accelerate
24
+ ```
25
+
26
+ ### Text Guided Inpainting Generation
27
+
28
+ ```python
29
+ from diffusers import KandinskyV22InpaintPipeline, KandinskyV22PriorPipeline
30
+ from diffusers.utils import load_image
31
+ import torch
32
+ import numpy as np
33
+
34
+ pipe_prior = KandinskyV22PriorPipeline.from_pretrained(
35
+ "kandinsky-community/kandinsky-2-2-prior", torch_dtype=torch.float16
36
+ )
37
+ pipe_prior.to("cuda")
38
+
39
+ prompt = "a hat"
40
+ prior_output = pipe_prior(prompt)
41
+
42
+ pipe = KandinskyV22InpaintPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-inpaint", torch_dtype=torch.float16)
43
+ pipe.to("cuda")
44
+
45
+ init_image = load_image(
46
+ "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
47
+ )
48
+
49
+ mask = np.ones((768, 768), dtype=np.float32)
50
+ # Let's mask out an area above the cat's head
51
+ mask[:250, 250:-250] = 0
52
+
53
+ out = pipe(
54
+ image=init_image,
55
+ mask_image=mask,
56
+ **prior_output,
57
+ height=768,
58
+ width=768,
59
+ num_inference_steps=150,
60
+ )
61
+
62
+ image = out.images[0]
63
+ image.save("cat_with_hat.png")
64
+ ```
65
+ ![img](https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/kandinskyv22/cat_with_hat.png)
66
+
67
+
68
+ ## Model Architecture
69
+
70
+ ### Overview
71
+ 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.
72
+
73
+ 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.
74
+
75
+ <p float="left">
76
+ <img src="https://raw.githubusercontent.com/ai-forever/Kandinsky-2/main/content/kandinsky21.png"/>
77
+ </p>
78
+
79
+ 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.
80
+
81
+
82
+ ### Details
83
+ 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).
84
+
85
+ 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.
86
+
87
+
88
+ ### Evaluation
89
+ We quantitatively measure the performance of Kandinsky 2.1 on the COCO_30k dataset, in zero-shot mode. The table below presents FID.
90
+
91
+ FID metric values ​​for generative models on COCO_30k
92
+ | | FID (30k)|
93
+ |:------|----:|
94
+ | eDiff-I (2022) | 6.95 |
95
+ | Image (2022) | 7.27 |
96
+ | Kandinsky 2.1 (2023) | 8.21|
97
+ | Stable Diffusion 2.1 (2022) | 8.59 |
98
+ | GigaGAN, 512x512 (2023) | 9.09 |
99
+ | DALL-E 2 (2022) | 10.39 |
100
+ | GLIDE (2022) | 12.24 |
101
+ | Kandinsky 1.0 (2022) | 15.40 |
102
+ | DALL-E (2021) | 17.89 |
103
+ | Kandinsky 2.0 (2022) | 20.00 |
104
+ | GLIGEN (2022) | 21.04 |
105
+
106
+ For more information, please refer to the upcoming technical report.
107
+
108
+ ## BibTex
109
+ If you find this repository useful in your research, please cite:
110
+ ```
111
+ @misc{kandinsky 2.2,
112
+ title = {kandinsky 2.2},
113
+ author = {Arseniy Shakhmatov, Anton Razzhigaev, Aleksandr Nikolich, Vladimir Arkhipkin, Igor Pavlov, Andrey Kuznetsov, Denis Dimitrov},
114
+ year = {2023},
115
+ howpublished = {},
116
+ }
117
+ ```