English
art
Stable Diffusion
File size: 1,833 Bytes
8881820
 
 
 
 
 
 
 
 
 
 
 
6eca12e
 
 
 
 
8881820
 
6eca12e
 
8881820
 
 
6eca12e
8881820
 
 
 
 
6eca12e
8881820
 
 
 
 
 
 
6eca12e
 
 
8881820
 
 
 
 
6eca12e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import torch
import time

from lyrasd_model import LyraSdTxt2ImgPipeline

# 存放模型文件的路径,应该包含一下结构:
#   1. clip 模型
#   2. 转换好的优化后的 unet 模型,放入其中的 unet_bins 文件夹
#   3. vae 模型
#   4. scheduler 配置

# LyraSD 的 C++ 编译动态链接库,其中包含 C++ CUDA 计算的细节
lib_path = "./lyrasd_model/lyrasd_lib/libth_lyrasd_cu12_sm80.so"
model_path = "./models/rev-animated"
lora_path = "./models/xiaorenshu.safetensors"

torch.classes.load_library(lib_path)

# 构建 Txt2Img 的 Pipeline
model = LyraSdTxt2ImgPipeline()
model.reload_pipe(model_path)

# load lora
# 参数分别为 lora 存放位置,名字,lora 强度,lora模型精度
model.load_lora_v2(lora_path, "xiaorenshu", 0.4)

# 准备应用的输入和超参数
prompt = "a cat, cute, cartoon, concise, traditional, chinese painting, Tang and Song Dynasties, masterpiece, 4k, 8k, UHD, best quality"
negative_prompt = "(((horrible))), (((scary))), (((naked))), (((large breasts))), high saturation, colorful, human:2, body:2, low quality, bad quality, lowres, out of frame, duplicate, watermark, signature, text, frames, cut, cropped, malformed limbs, extra limbs, (((missing arms))), (((missing legs)))"
height, width = 512, 512
steps = 20
guidance_scale = 7
generator = torch.Generator().manual_seed(123)
num_images = 1

start = time.perf_counter()
# 推理生成
images = model(prompt, height, width, steps,
               guidance_scale, negative_prompt, num_images,
               generator=generator)
print("image gen cost: ", time.perf_counter() - start)
# 存储生成的图片
for i, image in enumerate(images):
    image.save(f"outputs/res_txt2img_lora_{i}.png")

# unload lora,参数为 lora 的名字,是否清除 lora 缓存
model.unload_lora_v2("xiaorenshu", True)