Views
No views yet
pip install diffusers transformers accelerate1from diffusers import DiffusionPipeline
2import torch
3
4pipe_prior = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16)
5pipe_prior.to("cuda")
6
7t2i_pipe = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
8t2i_pipe.to("cuda")
9
10prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting"
11negative_prompt = "low quality, bad quality"
12
13image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt, guidance_scale=1.0).to_tuple()
14
15image = t2i_pipe(prompt, negative_prompt=negative_prompt, image_embeds=image_embeds, negative_image_embeds=negative_image_embeds, height=768, width=768).images[0]
16image.save("cheeseburger_monster.png")
1from diffusers import KandinskyImg2ImgPipeline, KandinskyPriorPipeline
2import torch
3
4from PIL import Image
5import requests
6from io import BytesIO
7
8url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
9response = requests.get(url)
10original_image = Image.open(BytesIO(response.content)).convert("RGB")
11original_image = original_image.resize((768, 512))
12
13# create prior
14pipe_prior = KandinskyPriorPipeline.from_pretrained(
15 "kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16
16)
17pipe_prior.to("cuda")
18
19# create img2img pipeline
20pipe = KandinskyImg2ImgPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
21pipe.to("cuda")
22
23prompt = "A fantasy landscape, Cinematic lighting"
24negative_prompt = "low quality, bad quality"
25
26image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt).to_tuple()
27
28out = pipe(
29 prompt,
30 image=original_image,
31 image_embeds=image_embeds,
32 negative_image_embeds=negative_image_embeds,
33 height=768,
34 width=768,
35 strength=0.3,
36)
37
38out.images[0].save("fantasy_land.png")
1from diffusers import KandinskyPriorPipeline, KandinskyPipeline
2from diffusers.utils import load_image
3import PIL
4
5import torch
6
7pipe_prior = KandinskyPriorPipeline.from_pretrained(
8 "kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16
9)
10pipe_prior.to("cuda")
11
12img1 = load_image(
13 "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
14)
15
16img2 = load_image(
17 "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/starry_night.jpeg"
18)
19
20# add all the conditions we want to interpolate, can be either text or image
21images_texts = ["a cat", img1, img2]
22
23# specify the weights for each condition in images_texts
24weights = [0.3, 0.3, 0.4]
25
26# We can leave the prompt empty
27prompt = ""
28prior_out = pipe_prior.interpolate(images_texts, weights)
29
30pipe = KandinskyPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
31pipe.to("cuda")
32
33image = pipe(prompt, **prior_out, height=768, width=768).images[0]
34
35image.save("starry_cat.png")

| 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 |
@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 = {},
}