waveydaveygravy
commited on
Commit
•
018348e
1
Parent(s):
640b664
Upload multicontrolnet.py
Browse files- multicontrolnet.py +51 -0
multicontrolnet.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# demo & simple test
|
2 |
+
def main():
|
3 |
+
from diffusers.utils import load_image
|
4 |
+
|
5 |
+
pipe = StableDiffusionMultiControlNetPipeline.from_pretrained(
|
6 |
+
"runwayml/stable-diffusion-v1-5", safety_checker=None, torch_dtype=torch.float16
|
7 |
+
).to("cuda")
|
8 |
+
pipe.enable_xformers_memory_efficient_attention()
|
9 |
+
|
10 |
+
controlnet_canny = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-canny", torch_dtype=torch.float16).to(
|
11 |
+
"cuda"
|
12 |
+
)
|
13 |
+
controlnet_pose = ControlNetModel.from_pretrained(
|
14 |
+
"lllyasviel/sd-controlnet-openpose", torch_dtype=torch.float16
|
15 |
+
).to("cuda")
|
16 |
+
|
17 |
+
canny_left = load_image("https://huggingface.co/takuma104/controlnet_dev/resolve/main/vermeer_left.png")
|
18 |
+
canny_right = load_image("https://huggingface.co/takuma104/controlnet_dev/resolve/main/vermeer_right.png")
|
19 |
+
pose_right = load_image("https://huggingface.co/takuma104/controlnet_dev/resolve/main/pose_right.png")
|
20 |
+
|
21 |
+
image = pipe(
|
22 |
+
prompt="best quality, extremely detailed",
|
23 |
+
negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
|
24 |
+
processors=[
|
25 |
+
ControlNetProcessor(controlnet_canny, canny_left),
|
26 |
+
ControlNetProcessor(controlnet_canny, canny_right),
|
27 |
+
],
|
28 |
+
generator=torch.Generator(device="cpu").manual_seed(0),
|
29 |
+
num_inference_steps=30,
|
30 |
+
width=512,
|
31 |
+
height=512,
|
32 |
+
).images[0]
|
33 |
+
image.save("/tmp/canny_left_right.png")
|
34 |
+
|
35 |
+
image = pipe(
|
36 |
+
prompt="best quality, extremely detailed",
|
37 |
+
negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
|
38 |
+
processors=[
|
39 |
+
ControlNetProcessor(controlnet_canny, canny_left),
|
40 |
+
ControlNetProcessor(controlnet_pose, pose_right),
|
41 |
+
],
|
42 |
+
generator=torch.Generator(device="cpu").manual_seed(0),
|
43 |
+
num_inference_steps=30,
|
44 |
+
width=512,
|
45 |
+
height=512,
|
46 |
+
).images[0]
|
47 |
+
image.save("/tmp/canny_left_pose_right.png")
|
48 |
+
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
main()
|