Views
No views yet



1from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
2from diffusers.utils import load_image
3import torch
4
5base_model_path = "stable-diffusion-v1-5/stable-diffusion-v1-5"
6controlnet_path = "Docty/cloth_controlnet"
7
8controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
9pipe = StableDiffusionControlNetPipeline.from_pretrained(
10 base_model_path, controlnet=controlnet, torch_dtype=torch.float16
11)
12
13# speed up diffusion process with faster scheduler and memory optimization
14pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
15# remove following line if xformers is not installed or when using Torch 2.0.
16#pipe.enable_xformers_memory_efficient_attention()
17# memory optimization.
18pipe.enable_model_cpu_offload()
19
20control_image = load_image("./cond1.jpg")
21prompt = "a professional studio photograph of an attractive model wearing a teal top with lace detail"
22
23# generate image
24#generator = torch.manual_seed(0)
25image = pipe(
26 prompt, num_inference_steps=20, image=control_image
27).images[0]
28image
29