Views
No views yet
1pip install -q easy-dwpose transformers accelerate
2pip install -q git+https://github.com/huggingface/diffusers
1from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline
2import torch
3from diffusers.utils import load_image
4
5from easy_dwpose import DWposeDetector
6
7
8pose_image = load_image("./images/pose_image_1.png")
9
10# Load detector
11device = "cuda:0" if torch.cuda.is_available() else "cpu"
12dwpose = DWposeDetector(device=device)
13
14# Compute DWpose conditioning image.
15skeleton = dwpose(
16 pose_image,
17 detect_resolution=pose_image.width,
18 output_type="pil",
19 include_hands=True,
20 include_face=True,
21)
22
23# Initialize ControlNet pipeline.
24controlnet = ControlNetModel.from_pretrained(
25 "dimitribarbot/controlnet-dwpose-sdxl-1.0",
26 torch_dtype=torch.float16,
27)
28pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
29 "stabilityai/stable-diffusion-xl-base-1.0",
30 controlnet=controlnet,
31 torch_dtype=torch.float16,
32 variant="fp16",
33).to(device)
34
35# Infer.
36prompt = "DJ in a party, shallow depth of field, highly detailed, high budget, gorgeous"
37negative_prompt = "bad quality, blur, anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured"
38image = pipe(
39 prompt,
40 negative_prompt=negative_prompt,
41 num_inference_steps=50,
42 guidance_scale=5,
43 image=skeleton,
44 generator=torch.manual_seed(97),
45).images[0]
46
47skeleton.save("./images/dwpose_1.png")
48image.save("./images/dwpose_image_1.png")


1from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline
2import torch
3from diffusers.utils import load_image
4
5from easy_dwpose import DWposeDetector
6
7
8pose_image = load_image("./images/pose_image_2.png")
9
10# Load detector
11device = "cuda:0" if torch.cuda.is_available() else "cpu"
12dwpose = DWposeDetector(device=device)
13
14# Compute DWpose conditioning image.
15skeleton = dwpose(
16 pose_image,
17 detect_resolution=pose_image.width,
18 output_type="pil",
19 include_hands=True,
20 include_face=True,
21)
22
23# Initialize ControlNet pipeline.
24controlnet = ControlNetModel.from_pretrained(
25 "dimitribarbot/controlnet-dwpose-sdxl-1.0",
26 torch_dtype=torch.float16,
27)
28pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
29 "stabilityai/stable-diffusion-xl-base-1.0",
30 controlnet=controlnet,
31 torch_dtype=torch.float16,
32 variant="fp16",
33)
34if torch.cuda.is_available():
35 pipe.to(torch.device("cuda"))
36
37# Infer.
38prompt = "Anime girl sitting on a bench, highly detailed, noon, ambiant light"
39negative_prompt = "bad quality, blur, anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured"
40image = pipe(
41 prompt,
42 negative_prompt=negative_prompt,
43 num_inference_steps=25,
44 guidance_scale=18,
45 image=skeleton,
46 generator=torch.manual_seed(79),
47).images[0]
48
49skeleton.save("./images/dwpose_2.png")
50image.save("./images/dwpose_image_2.png")
