Diffusers代码学习: LCM Inpainting

要使用LCM-LoRA进行修复,需要将调度器替换为[LCM scheduler],并使用[~loader.LoraLoaderMixin.load_LoRA_weights]方法加载LCM-LoRA权重。然后,可以像往常一样使用管道,并通过文本提示、初始图像和蒙版图像,只需4个步骤即可生成图像。

# 以下代码为程序运行进行设置

import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
mport torch
from diffusers import AutoPipelineForInpainting, LCMScheduler
from diffusers.utils import load_image, make_image_grid

pipe = AutoPipelineForInpainting.from_pretrained(
    "runwayml/stable-diffusion-inpainting",
    torch_dtype=torch.float16,
    variant="fp16",

).to("cuda")

# 加载LCM scheduler

pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5")

init_image = load_image(
"https://hf-mirror.com/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint.png")
mask_image = load_image(
"https://hf-mirror.com/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint_mask.png")

prompt = "concept art digital painting of an elven castle, inspired by lord of the rings, highly detailed, 8k"
generator = torch.manual_seed(0)
image = pipe(
prompt=prompt,
image=init_image,
mask_image=mask_image,
generator=generator,
num_inference_steps=4,
guidance_scale=4,
).images[0]

image.show()

以下为原始图像

图片

以下为蒙版图像

图片

以下为生成图像

图片

AIGC应用60

AIGC应用 · 目录

上一篇Diffusers代码学习:LCM 图生图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

duhaining1976

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值