patrickvonplaten commited on
Commit
c56864f
·
1 Parent(s): 6421583

adapt controlnet script

Browse files
Files changed (2) hide show
  1. 1 +0 -66
  2. control_net_canny.py +2 -4
1 DELETED
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env python3
2
- from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
3
- from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline
4
- import time
5
- from pytorch_lightning import seed_everything
6
- import os
7
- from huggingface_hub import HfApi
8
- # from compel import Compel
9
- import torch
10
- import sys
11
- from pathlib import Path
12
- import requests
13
- from PIL import Image
14
- from io import BytesIO
15
-
16
- api = HfApi()
17
- start_time = time.time()
18
-
19
- use_refiner = bool(int(sys.argv[1]))
20
- use_diffusers = True
21
-
22
- if use_diffusers:
23
- start_time = time.time()
24
- pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
25
- pipe.to("cuda")
26
-
27
- if use_refiner:
28
- refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
29
- refiner.to("cuda")
30
- # refiner.enable_sequential_cpu_offload()
31
- else:
32
- pipe = StableDiffusionXLPipeline.from_single_file("https://huggingface.co/stabilityai/stable-diffusion-xl-base-0.9/blob/main/sd_xl_base_0.9.safetensors", torch_dtype=torch.float16, use_safetensors=True)
33
- pipe.to("cuda")
34
-
35
- if use_refiner:
36
- refiner = StableDiffusionXLImg2ImgPipeline.from_single_file("https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-0.9/blob/main/sd_xl_refiner_0.9.safetensors", torch_dtype=torch.float16, use_safetensors=True)
37
- refiner.to("cuda")
38
-
39
-
40
- prompt = "An astronaut riding a green horse on Mars"
41
- for steps in [24, 27, 31]:
42
- for denoising_end in [0.63, 0.66, 0.67, 0.71]:
43
- seed = 0
44
- seed_everything(seed)
45
- image = pipe(prompt=prompt, num_inference_steps=40, denoising_end=0.675, output_type="latent" if use_refiner else "pil").images[0]
46
- # image = pipe(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]
47
-
48
- if use_refiner:
49
- image = refiner(prompt=prompt, num_inference_steps=40, denoising_start=0.675, image=image[None, :]).images[0]
50
-
51
- # pipe.unet.to(memory_format=torch.channels_last)
52
- # pipe(prompt=prompt, num_inference_steps=2).images[0]
53
-
54
- # image = pipe(prompt=prompt, num_images_per_prompt=1, num_inference_steps=40, output_type="latent").images
55
-
56
- file_name = f"aaa_{seed}"
57
- path = os.path.join(Path.home(), "images", "ediffi_sdxl", f"{file_name}.png")
58
- image.save(path)
59
-
60
- api.upload_file(
61
- path_or_fileobj=path,
62
- path_in_repo=path.split("/")[-1],
63
- repo_id="patrickvonplaten/images",
64
- repo_type="dataset",
65
- )
66
- print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/ediffi_sdxl/{file_name}.png")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
control_net_canny.py CHANGED
@@ -33,14 +33,12 @@ canny_image = Image.fromarray(image)
33
 
34
  controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
35
  pipe = StableDiffusionControlNetPipeline.from_pretrained(
36
- "runwayml/stable-diffusion-v1-5", controlnet=[controlnet, controlnet], torch_dtype=torch.float16
37
  )
38
-
39
- pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
40
  pipe.enable_model_cpu_offload()
41
 
42
  generator = torch.manual_seed(33)
43
- out_image = pipe("a blue paradise bird in the jungle", control_guidance_start=[0.2, 0.2], num_inference_steps=20, generator=generator, image=[canny_image, canny_image]).images[0]
44
 
45
  path = os.path.join(Path.home(), "images", "aa.png")
46
  out_image.save(path)
 
33
 
34
  controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
35
  pipe = StableDiffusionControlNetPipeline.from_pretrained(
36
+ "stabilityai/stable-diffusion-xl-base-0.9", controlnet=[controlnet, controlnet], torch_dtype=torch.float16
37
  )
 
 
38
  pipe.enable_model_cpu_offload()
39
 
40
  generator = torch.manual_seed(33)
41
+ out_image = pipe("a blue paradise bird in the jungle", generator=generator, image=[canny_image, canny_image]).images[0]
42
 
43
  path = os.path.join(Path.home(), "images", "aa.png")
44
  out_image.save(path)