🚀 用於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++