Views
No views yet
pidinet | controlnet | hed | controlnet |
|---|---|---|---|
![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() |
![]() | ![]() | ![]() | ![]() |
1import torch
2from diffusers.utils import load_image, check_min_version
3from diffusers.models import SD3ControlNetModel
4from diffusers import StableDiffusion3ControlNetPipeline
5from controlnet_aux import PidiNetDetector
6
7controlnet = SD3ControlNetModel.from_pretrained(
8 "alimama-creative/SD3-Controlnet-Softedge",torch_dtype=torch.float16
9)
10pipe = StableDiffusion3ControlNetPipeline.from_pretrained(
11 "stabilityai/stable-diffusion-3-medium-diffusers",
12 controlnet=controlnet,
13 variant="fp16",
14 torch_dtype=torch.float16,
15)
16pipe.text_encoder.to(torch.float16)
17pipe.controlnet.to(torch.float16)
18pipe.to("cuda")
19
20image = load_image(
21 "https://huggingface.co/alimama-creative/SD3-Controlnet-Softedge/resolve/main/images/im1_0.png"
22)
23prompt = "A dog sitting on a park bench."
24width = 1024
25height = 1024
26
27edge_processor = PidiNetDetector.from_pretrained('lllyasviel/Annotators')
28edge_image = edge_processor(image, detect_resolution=width, image_resolution=width)
29
30res_image = pipe(
31 prompt=prompt,
32 negative_prompt="deformed, distorted, disfigured, poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, mutated hands and fingers, disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, NSFW",
33 height=height,
34 width=width,
35 control_image=edge_image,
36 num_inference_steps=25,
37 controlnet_conditioning_scale=0.95,
38 guidance_scale=5,
39).images[0]
40res_image.save("sd3.png")
41