Views
No views yet
$ git clone https://github.com/HighCWu/control-lora-v2$ cd control-lora-v21import torch
2from PIL import Image
3from diffusers import StableDiffusionControlNetPipeline, UNet2DConditionModel, UniPCMultistepScheduler
4from models.control_lora import ControlLoRAModel
5
6device = 'cuda' if torch.cuda.is_available() else 'cpu'
7dtype = torch.float16 if torch.cuda.is_available() else torch.float32
8
9image = Image.open('<Your Conditioning Image Path>')
10
11base_model = "runwayml/stable-diffusion-v1-5"
12
13unet = UNet2DConditionModel.from_pretrained(
14 base_model, subfolder="unet", torch_dtype=dtype
15)
16control_lora: ControlLoRAModel = ControlLoRAModel.from_pretrained(
17 "HighCWu/sd-control-lora-head3d", torch_dtype=dtype
18)
19control_lora.tie_weights(unet)
20
21pipe = StableDiffusionControlNetPipeline.from_pretrained(
22 base_model, unet=unet, controlnet=control_lora, safety_checker=None, torch_dtype=dtype
23).to(device)
24control_lora.bind_vae(pipe.vae)
25
26pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
27
28# Remove if you do not have xformers installed
29# see https://huggingface.co/docs/diffusers/v0.13.0/en/optimization/xformers#installing-xformers
30# for installation instructions
31pipe.enable_xformers_memory_efficient_attention()
32
33# pipe.enable_model_cpu_offload()
34
35image = pipe("Girl smiling, professional dslr photograph, high quality", image, num_inference_steps=20).images[0]
36
37image.show()

