ai-forever commited on
Commit
1d2d06c
1 Parent(s): f69b8b2

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +154 -0
README.md ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+ # Kandinsky-3: Text-to-image diffusion model
5
+
6
+ ![](assets/title.jpg)
7
+
8
+ [Post](https://habr.com/ru/companies/sberbank/articles/775590/) | [Generate](https://fusionbrain.ai) | [Telegram-bot](https://t.me/kandinsky21_bot) | [Report]
9
+
10
+ ## Description:
11
+
12
+ Kandinsky 3.0 is an open-source text-to-image diffusion model built upon the Kandinsky2-x model family. In comparison to its predecessors, Kandinsky 3.0 incorporates more data and specifically related to Russian culture, which allows to generate pictures related to Russin culture. Furthermore, enhancements have been made to the text understanding and visual quality of the model, achieved by increasing the size of the text encoder and Diffusion U-Net models, respectively.
13
+
14
+ For more information: details of training, example of generations check out our [post](https://habr.com/ru/companies/sberbank/articles/775590/). The english version will be released in a couple of days.
15
+
16
+ ## Architecture details:
17
+
18
+
19
+ ![](assets/kandinsky.jpg)
20
+
21
+
22
+ Architecture consists of three parts:
23
+
24
+ + Text encoder Flan-UL2 (encoder part) - 8.6B
25
+ + Latent Diffusion U-Net - 3B
26
+ + MoVQ encoder/decoder - 267M
27
+
28
+
29
+ ## Models
30
+
31
+ We release our two models:
32
+
33
+ + Base: Base text-to-image diffusion model. This model was trained over 2M steps on 400 A100
34
+ + Inpainting: Inpainting version of the model. The model was initialized from final checkpoint of base model and trained 250k steps on 300 A100.
35
+
36
+
37
+ Weights of the model are loaded internally but if want to change them one can use the following example:
38
+
39
+ ```python
40
+ from huggingface_hub import hf_hub_download
41
+ from kandinsky3 import get_T2I_unet, get_T5encoder, get_movq, Kandinsky3T2IPipeline
42
+
43
+ unet_path = hf_hub_download(
44
+ repo_id="ai-forever/Kandinsky3.0", filename='weights/kandinsky3.pt')
45
+ )
46
+
47
+ movq_path = hf_hub_download(
48
+ repo_id="ai-forever/Kandinsky3.0", filename='weights/movq.pt')
49
+ )
50
+ unet, null_embedding, projections_state_dict = get_T2I_unet(device, unet_path, fp16=fp16)
51
+ processor, condition_encoders = get_T5encoder(device, text_encode_path, projections_state_dict, fp16=fp16)
52
+ movq = get_movq(device, movq_path, fp16=fp16)
53
+ t2i_pipe = Kandinsky3T2IPipeline(device, unet, null_embedding, processor, condition_encoders, movq, fp16=fp16)
54
+ ```
55
+
56
+ ```python
57
+ from huggingface_hub import hf_hub_download
58
+ from kandinsky3 import get_inpainting_unet, get_T5encoder, get_movq, Kandinsky3InpaintingPipeline
59
+
60
+ inpainting_unet_path = hf_hub_download(
61
+ repo_id="ai-forever/Kandinsky3.0", filename='weights/kandinsky3_inpainting.pt', cache_dir=cache_dir
62
+ )
63
+ movq_path = hf_hub_download(
64
+ repo_id="ai-forever/Kandinsky3.0", filename='weights/movq.pt')
65
+ )
66
+
67
+ unet, null_embedding, projections_state_dict = get_inpainting_unet(device, unet_path, fp16=fp16)
68
+ processor, condition_encoders = get_T5encoder(device, text_encode_path, projections_state_dict, fp16=fp16)
69
+ movq = get_movq(device, movq_path, fp16=False) #MoVQ ooesn't work properly in fp16 on inpainting
70
+ pipe = Kandinsky3InpaintingPipeline(device, unet, null_embedding, processor, condition_encoders, movq, fp16=fp16)
71
+ ```
72
+
73
+ ## Installing
74
+
75
+ To install repo first one need to create conda environment:
76
+
77
+ ```
78
+ conda create -n kandinsky -y python=3.8;
79
+ source activate kandinsky;
80
+ pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu113/torch_stable.html;
81
+ pip install -r requirements.txt;
82
+ ```
83
+ The exact dependencies is got using `pip freeze` and can be found in `exact_requirements.txt`
84
+
85
+ ## How to use:
86
+
87
+ Check our jupyter notebooks with examples in `./examples` folder
88
+
89
+ ### 1. text2image
90
+
91
+ ```python
92
+ from kandinsky3 import get_T2I_pipeline
93
+
94
+ t2i_pipe = get_T2I_pipeline('cuda', fp16=True)
95
+
96
+ image = t2i_pipe( "A cute corgi lives in a house made out of sushi.")
97
+ ```
98
+
99
+ ### 2. inpainting
100
+
101
+ ```python
102
+ from kandinsky3 import get_inpainting_pipeline
103
+
104
+ inp_pipe = get_inpainting_pipeline('cuda', fp16=True)
105
+
106
+ image = ... # PIL Image
107
+ mask = ... # Numpy array (HxW). Set 1 where image should be masked
108
+ image = inp_pipe( "A cute corgi lives in a house made out of sushi.", image, mask)
109
+ ```
110
+
111
+ ## Examples of generations
112
+
113
+ <hr>
114
+
115
+ <table class="center">
116
+ <tr>
117
+ <td><img src="assets/photo_8.jpg" raw=true></td>
118
+ <td><img src="assets/photo_15.jpg"></td>
119
+ <td><img src="assets/photo_16.jpg"></td>
120
+ <td><img src="assets/photo_17.jpg"></td>
121
+ </tr>
122
+ <tr>
123
+ <td width=25% align="center">"A beautiful landscape outdoors scene in the crochet knitting art style, drawing in style by Alfons Mucha"</td>
124
+ <td width=25% align="center">"gorgeous phoenix, cosmic, darkness, epic, cinematic, moonlight, stars, high - definition, texture,Oscar-Claude Monet"</td>
125
+ <td width=25% align="center">"a yellow house at the edge of the danish fjord, in the style of eiko ojala, ingrid baars, ad posters, mountainous vistas, george ault, realistic details, dark white and dark gray, 4k"</td>
126
+ <td width=25% align="center">"dragon fruit head, upper body, realistic, illustration by Joshua Hoffine Norman Rockwell, scary, creepy, biohacking, futurism, Zaha Hadid style"</td>
127
+ </tr>
128
+ <tr>
129
+ <td><img src="assets/photo_2.jpg" raw=true></td>
130
+ <td><img src="assets/photo_19.jpg"></td>
131
+ <td><img src="assets/photo_13.jpg"></td>
132
+ <td><img src="assets/photo_14.jpg"></td>
133
+ </tr>
134
+ <tr>
135
+ <td width=25% align="center">"Amazing playful nice cute strawberry character, dynamic poze, surreal fantazy garden background, gorgeous masterpice, award winning photo, soft natural lighting, 3d, Blender, Octane render, tilt - shift, deep field, colorful, I can't believe how beautiful this is, colorful, cute and sweet baby - loved photo"</td>
136
+ <td width=25% align="center">"beautiful fairy-tale desert, in the sky a wave of sand merges with the milky way, stars, cosmism, digital art, 8k"</td>
137
+ <td width=25% align="center">"Car, mustang, movie, person, poster, car cover, person, in the style of alessandro gottardo, gold and cyan, gerald harvey jones, reflections, highly detailed illustrations, industrial urban scenes""</td>
138
+ <td width=25% align="center">"cloud in blue sky, a red lip, collage art, shuji terayama, dreamy objects, surreal, criterion collection, showa era, intricate details, mirror"</td>
139
+ </tr>
140
+
141
+ </table>
142
+
143
+ <hr>
144
+
145
+ ## Authors
146
+
147
+ + Vladimir Arkhipkin: [Github](https://github.com/oriBetelgeuse)
148
+ + Anastasia Maltseva [Github](https://github.com/NastyaMittseva)
149
+ + Andrei Filatov [Github](https://github.com/anvilarth),
150
+ + Igor Pavlov: [Github](https://github.com/boomb0om)
151
+ + Julia Agafonova
152
+ + Arseniy Shakhmatov: [Github](https://github.com/cene555), [Blog](https://t.me/gradientdip)
153
+ + Andrey Kuznetsov: [Github](https://github.com/kuznetsoffandrey), [Blog](https://t.me/complete_ai)
154
+ + Denis Dimitrov: [Github](https://github.com/denndimitrov), [Blog](https://t.me/dendi_math_ai)