patrickvonplaten commited on
Commit
673a573
1 Parent(s): 42c2b6e

add all scripts

Browse files
Files changed (1) hide show
  1. README.md +18 -11
README.md CHANGED
@@ -79,33 +79,40 @@ $ pip install diffusers transformers accelerate
79
  3. Run code:
80
 
81
  ```python
82
- #!/usr/bin/env python3
83
  import torch
 
 
 
84
  from diffusers.utils import load_image
 
85
  import cv2
 
86
 
87
  from diffusers import (
88
  ControlNetModel,
89
  StableDiffusionControlNetPipeline,
90
  UniPCMultistepScheduler,
91
  )
92
- import sys
93
 
94
- model_id = "lllyasviel/control_v11p_sd15_canny"
95
 
96
  image = load_image(
97
- "https://huggingface.co/lllyasviel/sd-controlnet-canny/resolve/main/images/bird.png"
98
  )
99
 
 
 
100
  low_threshold = 100
101
  high_threshold = 200
102
 
103
  image = cv2.Canny(image, low_threshold, high_threshold)
104
  image = image[:, :, None]
105
  image = np.concatenate([image, image, image], axis=2)
106
- canny_image = Image.fromarray(image)
 
 
107
 
108
- controlnet = ControlNetModel.from_pretrained(model_id, torch_dtype=torch.float16)
109
  pipe = StableDiffusionControlNetPipeline.from_pretrained(
110
  "runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
111
  )
@@ -114,16 +121,16 @@ pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
114
  pipe.enable_model_cpu_offload()
115
 
116
  generator = torch.manual_seed(33)
117
- image = pipe("a blue paradise bird in the jungle", num_inference_steps=20, generator=generator, image=canny_image).images[0]
118
 
119
- image.save('images/bird_canny_out.png')
120
  ```
121
 
122
- ![bird](./images/bird.png)
123
 
124
- ![bird_canny](./images/bird_canny.png)
125
 
126
- ![bird_canny_out](./images/bird_canny_out.png)
127
 
128
  ## Other released checkpoints v1-1
129
 
 
79
  3. Run code:
80
 
81
  ```python
 
82
  import torch
83
+ import os
84
+ from huggingface_hub import HfApi
85
+ from pathlib import Path
86
  from diffusers.utils import load_image
87
+ import numpy as np
88
  import cv2
89
+ from PIL import Image
90
 
91
  from diffusers import (
92
  ControlNetModel,
93
  StableDiffusionControlNetPipeline,
94
  UniPCMultistepScheduler,
95
  )
 
96
 
97
+ checkpoint = "ControlNet-1-1-preview/control_v11p_sd15_canny"
98
 
99
  image = load_image(
100
+ "https://huggingface.co/ControlNet-1-1-preview/control_v11p_sd15_canny/resolve/main/images/input.png"
101
  )
102
 
103
+ image = np.array(image)
104
+
105
  low_threshold = 100
106
  high_threshold = 200
107
 
108
  image = cv2.Canny(image, low_threshold, high_threshold)
109
  image = image[:, :, None]
110
  image = np.concatenate([image, image, image], axis=2)
111
+ control_image = Image.fromarray(image)
112
+
113
+ control_image.save("./images/control.png")
114
 
115
+ controlnet = ControlNetModel.from_pretrained(checkpoint, torch_dtype=torch.float16)
116
  pipe = StableDiffusionControlNetPipeline.from_pretrained(
117
  "runwayml/stable-diffusion-v1-5", controlnet=controlnet, torch_dtype=torch.float16
118
  )
 
121
  pipe.enable_model_cpu_offload()
122
 
123
  generator = torch.manual_seed(33)
124
+ image = pipe("a blue paradise bird in the jungle", num_inference_steps=20, generator=generator, image=control_image).images[0]
125
 
126
+ image.save('images/image_out.png')
127
  ```
128
 
129
+ ![bird](./images/input.png)
130
 
131
+ ![bird_canny](./images/control.png)
132
 
133
+ ![bird_canny_out](./images/image_out.png)
134
 
135
  ## Other released checkpoints v1-1
136