🚀 用于Stable Diffusion 1.5的二维码条件ControlNet模型
本项目提供适用于Stable Diffusion 1.5的二维码条件ControlNet模型,助力图像生成更具创意与精准度。
🚀 快速开始
本仓库包含适用于Stable Diffusion v1.5的二维码条件ControlNet的safetensors和diffusers版本。Stable Diffusion 2.1版本稍更有效,它是为满足特定需求而开发的。不过,这个1.5版本的模型也在相同的数据集上进行了训练,供使用旧版本的用户使用。

✨ 主要特性
这些模型在大多数情况下表现出色,但请注意,它们并非100%准确。在某些情况下,二维码形状可能无法如预期那样呈现。你可以增加ControlNet的权重来突出二维码形状。不过,要谨慎操作,因为这可能会对输出的风格产生负面影响。为了优化扫描效果,请以纠错模式'H'(30%)生成二维码。
为了在风格和形状之间取得平衡,可能需要根据具体输入、期望输出以及正确的提示词对控制权重进行微调。有些提示词在大幅增加权重之前可能不起作用。在这些因素之间找到合适的平衡既是一门艺术,也是一门科学。为了获得最佳效果,建议以768的分辨率生成艺术作品。这样可以在最终作品中实现更高的细节水平,提升基于二维码的艺术作品的质量和效果。
📦 安装指南
使用此模型最简单的方法是将.safetensors
模型及其.yaml
配置文件放在你安装其他ControlNet模型的文件夹中,该文件夹因应用程序而异。
对于在auto1111中使用,可以将它们放在webui/models/ControlNet
文件夹中。可以使用ControlNet Web UI扩展加载它们,你可以通过Web UI的扩展选项卡(https://github.com/Mikubill/sd-webui-controlnet)安装该扩展。确保启用ControlNet单元,并将输入图像设置为二维码。根据你的基础Stable Diffusion模型,将模型设置为SD2.1或1.5版本,否则会出错。不需要预处理器,不过你可以使用反转预处理器以获得不同的结果。768是首选的生成分辨率,因为它可以实现更多细节。
如果你遇到困难,请查找有关如何使用ControlNet的更多信息。一旦Web UI启动并运行,安装ControlNet扩展就非常简单。
💻 使用示例
基础用法
pip -q install diffusers transformers accelerate torch xformers
高级用法
import torch
from PIL import Image
from diffusers import StableDiffusionControlNetImg2ImgPipeline, ControlNetModel, DDIMScheduler
from diffusers.utils import load_image
controlnet = ControlNetModel.from_pretrained("DionTimmer/controlnet_qrcode-control_v1p_sd15",
torch_dtype=torch.float16)
pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
controlnet=controlnet,
safety_checker=None,
torch_dtype=torch.float16
)
pipe.enable_xformers_memory_efficient_attention()
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload()
def resize_for_condition_image(input_image: Image, resolution: int):
input_image = input_image.convert("RGB")
W, H = input_image.size
k = float(resolution) / min(H, W)
H *= k
W *= k
H = int(round(H / 64.0)) * 64
W = int(round(W / 64.0)) * 64
img = input_image.resize((W, H), resample=Image.LANCZOS)
return img
source_image = load_image("https://s3.amazonaws.com/moonup/production/uploads/6064e095abd8d3692e3e2ed6/A_RqHaAM6YHBodPLwqtjn.png")
init_image = load_image("https://s3.amazonaws.com/moonup/production/uploads/noauth/KfMBABpOwIuNolv1pe3qX.jpeg")
condition_image = resize_for_condition_image(source_image, 768)
init_image = resize_for_condition_image(init_image, 768)
generator = torch.manual_seed(123121231)
image = pipe(prompt="a bilboard in NYC with a qrcode",
negative_prompt="ugly, disfigured, low quality, blurry, nsfw",
image=init_image,
control_image=condition_image,
width=768,
height=768,
guidance_scale=20,
controlnet_conditioning_scale=1.5,
generator=generator,
strength=0.9,
num_inference_steps=150,
)
image.images[0]
📄 许可证
openrail++