patrickvonplaten commited on
Commit
63a337a
1 Parent(s): 7e48094

Update README.md

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