|
import torch |
|
import time |
|
from PIL import Image |
|
|
|
from lyrasd_model import LyraSdControlnetTxt2ImgPipeline |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lib_path = "./lyrasd_model/lyrasd_lib/libth_lyrasd_cu12_sm86.so" |
|
model_path = "./models/lyrasd_rev_animated" |
|
canny_controlnet_path = "./models/lyrasd_canny" |
|
|
|
pipe = LyraSdControlnetTxt2ImgPipeline(model_path, lib_path) |
|
|
|
|
|
start = time.perf_counter() |
|
pipe.load_controlnet_model("canny", canny_controlnet_path, "fp32") |
|
print(f"controlnet load cost: {time.perf_counter() - start}") |
|
|
|
print(pipe.get_loaded_controlnet()) |
|
|
|
|
|
|
|
|
|
control_img = Image.open("control_bird_canny.png") |
|
|
|
|
|
prompt = "a blue bird" |
|
negative_prompt = "NSFW" |
|
height, width = 512, 512 |
|
steps = 20 |
|
guidance_scale = 7.5 |
|
generator = torch.Generator().manual_seed(123) |
|
num_images = 1 |
|
guess_mode = False |
|
|
|
|
|
|
|
|
|
controlnet_images = [[control_img]] |
|
controlnet_scale = [0.5] |
|
controlnet_names = ['canny'] |
|
|
|
|
|
|
|
start = time.perf_counter() |
|
images = pipe(prompt, height, width, steps, |
|
guidance_scale, negative_prompt, num_images, |
|
generator=generator, controlnet_images=controlnet_images, |
|
controlnet_scale=controlnet_scale, controlnet_names=controlnet_names, |
|
guess_mode=guess_mode |
|
) |
|
print("cur cost: ",time.perf_counter() - start) |
|
|
|
|
|
for i, image in enumerate(images): |
|
image.save(f"./outputs/res_controlnet_txt2img_{i}.png") |
|
|