patrickvonplaten commited on
Commit
6d8ff37
1 Parent(s): de55a08

further improve

Browse files
Files changed (2) hide show
  1. run_kandinsky.py +9 -26
  2. run_local.py +37 -17
run_kandinsky.py CHANGED
@@ -8,41 +8,24 @@ import os
8
  from huggingface_hub import HfApi
9
  from pathlib import Path
10
 
11
- api = HfApi()
12
- prev_time = time.time()
13
-
14
 
15
- prompt = "a picture of elon musk next to a rocket"
16
- negative_prompt = "low quality, ugly"
17
 
18
- pipe_prior = DiffusionPipeline.from_pretrained(
19
- "kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16
20
- )
21
  pipe_prior.to("cuda")
 
22
  t2i_pipe = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
23
  t2i_pipe.to("cuda")
24
 
25
- t2i_pipe.unet.set_attn_processor(AttnAddedKVProcessor2_0())
26
- t2i_pipe.unet.to(memory_format=torch.channels_last)
27
- t2i_pipe.unet = torch.compile(t2i_pipe.unet, mode="reduce-overhead", fullgraph=True)
28
-
29
- next_time = time.time()
30
- print("Loading", next_time - prev_time)
31
- prev_time = next_time
32
 
33
  generator = torch.Generator(device="cuda").manual_seed(12)
34
- image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt=negative_prompt, generator=generator).to_tuple()
35
-
36
- next_time = time.time()
37
- print("Prior", next_time - prev_time)
38
- prev_time = next_time
39
-
40
- for _ in range(3):
41
- images = t2i_pipe(prompt, image_embeds=image_embeds, negative_image_embeds=negative_image_embeds, negative_prompt=negative_prompt, num_inference_steps=50, generator=generator).images
42
 
43
- next_time = time.time()
44
- print("Text-to-image", next_time - prev_time)
45
- prev_time = next_time
46
 
47
  for i, image in enumerate(images):
48
  path = os.path.join(Path.home(), "images", f"aa_{i}.png")
 
8
  from huggingface_hub import HfApi
9
  from pathlib import Path
10
 
11
+ from diffusers import DiffusionPipeline
12
+ import torch
 
13
 
14
+ api = HfApi()
 
15
 
16
+ pipe_prior = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16)
 
 
17
  pipe_prior.to("cuda")
18
+
19
  t2i_pipe = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
20
  t2i_pipe.to("cuda")
21
 
22
+ prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting"
23
+ negative_prompt = "low quality, bad quality"
 
 
 
 
 
24
 
25
  generator = torch.Generator(device="cuda").manual_seed(12)
26
+ image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt, guidance_scale=1.0, generator=generator).to_tuple()
 
 
 
 
 
 
 
27
 
28
+ images = t2i_pipe(prompt, num_images_per_prompt=4, image_embeds=image_embeds, negative_image_embeds=negative_image_embeds, negative_prompt=negative_prompt).images
 
 
29
 
30
  for i, image in enumerate(images):
31
  path = os.path.join(Path.home(), "images", f"aa_{i}.png")
run_local.py CHANGED
@@ -1,8 +1,9 @@
1
  #!/usr/bin/env python3
2
- from diffusers import StableDiffusionPipeline, DDIMScheduler
3
  import time
4
  import os
5
  from huggingface_hub import HfApi
 
6
  import torch
7
  import sys
8
  from pathlib import Path
@@ -10,34 +11,53 @@ import requests
10
  from PIL import Image
11
  from io import BytesIO
12
 
13
- begin = ["a picture of <rickmann>", "a photo of <rickmann>", "The <rickmann>", "an image of <rickmann>"]
14
- mid = ["", " on a bike", " with sunglasses", " at the beach", " in front of a mountain", " in the water", " on a boat", " at a fashion show", " as a superstar model", " while it snows", " in a forest", " with a nice landscape"]
15
- end = ["", " , disco light style", ", minecraft style", " , picasso style", " as a lego person", ""]
16
 
17
  api = HfApi()
18
  start_time = time.time()
19
- path = "patrickvonplaten/papa_out_5"
20
- pipe = StableDiffusionPipeline.from_pretrained(path, safety_checker=None, torch_dtype=torch.float16)
21
- pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
 
 
 
 
22
  pipe = pipe.to("cuda")
23
- counter = 1000
24
 
25
- for b in begin:
26
- for m in mid:
27
- for e in end:
28
- prompt = b + m + e + ", highly realistic, super resolution, high quality photography, beautiful"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- images = pipe(prompt=prompt, num_images_per_prompt=2, eta=1.0, negative_prompt="ugly, bad quality, deformed", num_inference_steps=50).images
 
 
31
 
32
  for i, image in enumerate(images):
33
- path = os.path.join(Path.home(), "papa", f"{counter}.png")
 
34
  image.save(path)
35
 
36
  api.upload_file(
37
  path_or_fileobj=path,
38
  path_in_repo=path.split("/")[-1],
39
- repo_id="patrickvonplaten/papa",
40
  repo_type="dataset",
41
  )
42
- print(f"https://huggingface.co/datasets/patrickvonplaten/papa/blob/main/{counter}.png")
43
- counter += 1
 
1
  #!/usr/bin/env python3
2
+ from diffusers import StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
3
  import time
4
  import os
5
  from huggingface_hub import HfApi
6
+ # from compel import Compel
7
  import torch
8
  import sys
9
  from pathlib import Path
 
11
  from PIL import Image
12
  from io import BytesIO
13
 
14
+ # path = sys.argv[1]
15
+ path = "runwayml/stable-diffusion-v1-5"
16
+ # path = "stabilityai/stable-diffusion-2-1"
17
 
18
  api = HfApi()
19
  start_time = time.time()
20
+ pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
21
+ # pipe = StableDiffusionImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None)
22
+ # pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config)
23
+
24
+ # compel = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
25
+
26
+
27
  pipe = pipe.to("cuda")
 
28
 
29
+ prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"
30
+
31
+ # rompts = ["a cat playing with a ball++ in the forest", "a cat playing with a ball++ in the forest", "a cat playing with a ball-- in the forest"]
32
+
33
+ # prompt_embeds = torch.cat([compel.build_conditioning_tensor(prompt) for prompt in prompts])
34
+
35
+ # generator = [torch.Generator(device="cuda").manual_seed(0) for _ in range(prompt_embeds.shape[0])]
36
+ #
37
+ # url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
38
+ #
39
+ # response = requests.get(url)
40
+ # image = Image.open(BytesIO(response.content)).convert("RGB")
41
+ # image.thumbnail((768, 768))
42
+ #
43
+
44
+ for TIMESTEP_TYPE in ["trailing", "leading"]:
45
+ for RESCALE_BETAS_ZEROS_SNR in [True, False]:
46
+ for GUIDANCE_RESCALE in [0,0, 0.7]:
47
 
48
+ pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_type=TIMESTEP_TYPE, rescale_betas_zero_snr=RESCALE_BETAS_ZEROS_SNR)
49
+ generator = torch.Generator(device="cpu").manual_seed(0)
50
+ images = pipe(prompt=prompt, generator=generator, num_images_per_prompt=4, num_inference_steps=40, guidance_rescale=GUIDANCE_RESCALE).images
51
 
52
  for i, image in enumerate(images):
53
+ file_name = f"bb_{i}_{TIMESTEP_TYPE}_{str(int(RESCALE_BETAS_ZEROS_SNR))}_{GUIDANCE_RESCALE}"
54
+ path = os.path.join(Path.home(), "images", f"{file_name}.png")
55
  image.save(path)
56
 
57
  api.upload_file(
58
  path_or_fileobj=path,
59
  path_in_repo=path.split("/")[-1],
60
+ repo_id="patrickvonplaten/images",
61
  repo_type="dataset",
62
  )
63
+ print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")