第 16 屆 iThome 鐵人賽 (2023)
{%hackmd BJrTq20hE %}
OpenPose(骨架圖生圖),在Stable diffusion裡 OpenPose是最重要且最實用的模組,一定要下載。而其它模組我基本上覺得不是不好用就是使用情況較為受限,如果你不是剛好有相關需求,可以說通通用不上,但Openpose既好用又不複雜,在CivitAI裡面也有一堆範本可以使用,只要心存感激,將上傳的大大當成神敬拜就可以了。
https://github.com/CMU-Perceptual-Computing-Lab/openpose
模型的取樣有兩種,第一種,一樣到我們前面章節講的CivitAI,查詢OpenPose,心存感激使用即可ˊˇˋ
在網頁中,妳也能看到要放的Type(對應的資料夾),作者使用的模組和版權。
# for deterministic generation
generator = torch.Generator(device='cuda').manual_seed(12345)
controlnet = ControlNetModel.from_pretrained(
"lllyasviel/sd-controlnet-openpose",
torch_dtype=torch.float16
)
pipe = StableDiffusionControlNetPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
controlnet=controlnet,
torch_dtype=torch.float16
)
# change the scheduler
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
# enable xformers (optional), requires xformers installation
pipe.enable_xformers_memory_efficient_attention()
# cpu offload for memory saving, requires accelerate>=0.17.0
pipe.enable_model_cpu_offload()
# cpu offload for memory saving, requires accelerate>=0.17.0
pipe.enable_model_cpu_offload()
image = pipe(
"a beautiful hollywood actress wearing black dress attending award winning event, red carpet stairs at background",
negative_prompt="cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, blurry, bad anatomy, bad proportions",
num_inference_steps=20,
generator=generator,
image=pose_image,
controlnet_conditioning_scale=1.0
).images[0]
image.save('output.png')
明天我會教第二種方法來產生OpenPose的模組,Stable diffusion還有很多好玩的功能 , 神通廣大的Controlnet (膜拜
https://zhuanlan.zhihu.com/p/612815907