標題:T2I-Adapter: Learning Adapters to Dig out More Controllable Ability for Text-to-Image Diffusion Models
論文:https://arxiv.org/pdf/2302.08453.pdf
博客:https://huggingface.co/blog/t2i-sdxl-adapters
代碼:https://github.com/TencentARC/T2I-Adapter
使用地址:https://huggingface.co/spaces/TencentARC/T2I-Adapter-SDXL
大家好,AI 繪畫太火了,現在boss直聘上一大堆崗位都是,游戲公司,設計公司等等都在瘋狂招,都是潛在機會?。?!
由于文本輸入對AI生成的圖片控制不夠精細,而 ControlNet 的出現,很好的解決了這個問題,也有了更多想象的空間,我們使用線稿、邊緣、深度圖、姿態(tài)、人臉關鍵點等等來控制生成的結果,但是 ControlNet 的計算成本很高,因為,ControlNet 在反向擴散過程的每個去噪步驟中,都需要運行 ControlNet 和 UNet。另外,ControlNet強調復制UNet編碼器作為控制模型的重要性,導致參數數量更大。因此,生成受到 ControlNet 大小的瓶頸(越大,過程變得越慢)。
https://github.com/lllyasviel/ControlNet
因此,今天要分析的一個工作,T2I-Adapter 是一種高效的即插即用模型,它為預訓練的文本到圖像模型提供額外的指導,同時凍結原始的大型文本到圖像模型。T2I-Adapter 將 T2I 模型中的內部知識與外部控制信號結合起來。我們可以根據不同的情況訓練各種適配器,實現豐富的控制和編輯效果。T2I-Adapter 的尺寸較小,并且與 ControlNet 不同,T2I-Adapter 在整個去噪過程中僅運行一次。
在過去的幾周里,Diffusers 團隊和 T2I-Adapter 作者一直在合作,為 diffusers 中的 Stable Diffusion XL (SDXL) 提供 T2I-Adapters 支持。本文,將分享從頭開始在 SDXL 上訓練 T2I-Adapters 的結果,當然還有各種控制條件(草圖、canny、藝術線條、深度和 openpose)上的 T2I-Adapter checkpoints!
與之前版本的T2I-Adapter(SD-1.4/1.5)相比,T2I-Adapter-SDXL仍然采用原來的設置,用79M Adapter驅動2.6B SDXL!T2I-Adapter-SDXL在繼承一代SDXL高品質的同時,保持了強大的控制能力!
使用 diffusers 訓練 T2I-Adapter-SDXL
我們根據 diffusers 提供的官方示例構建了訓練腳本。
https://github.com/huggingface/diffusers/blob/main/examples/t2i_adapter/README_sdxl.md
文中提到的大多數 T2I-Adapter 模型都是在 LAION-Aesthetics V2 的 3M 高分辨率圖像文本對上進行訓練的,設置如下:
Training steps: 20000-35000
Batch size: Data parallel with a single GPU batch size of 16 for a total batch size of 128.
Learning rate: Constant learning rate of 1e-5.
Mixed precision: fp16
建議使用項目中的腳本來訓練自定義且功能強大的T2I-Adapters,在速度、內存和質量之間實現競爭性權衡。
在 diffusers 中使用 T2I-Adapter-SDXL
以線稿條件為例來演示T2I-Adapter-SDXL的使用。首先,首先安裝所需的依賴項:
項目地址:https://github.com/TencentARC/T2I-Adapter
pip install -U git+https://github.com/huggingface/diffusers.git
pip install -U controlnet_aux==0.0.7 # for conditioning models and detectors
pip install transformers accelerate
T2I-Adapter-SDXL的生成過程主要包括以下兩個步驟:
Condition images 準備成合適的 control image 格式(例如輸入的圖片要先轉為合適的線稿圖片表示)
控制圖像(線稿)和提示(prompt)被傳遞到 StableDiffusionXLAdapterPipeline
使用藝術線條Adapter的簡單示例。首先初始化 SDXL 的 T2I-Adapter 管道和線稿檢測器。
import torch
from controlnet_aux.lineart import LineartDetector
from diffusers import (AutoencoderKL, EulerAncestralDiscreteScheduler,
StableDiffusionXLAdapterPipeline, T2IAdapter)
from diffusers.utils import load_image, make_image_grid
# load adapter
adapter = T2IAdapter.from_pretrained(
"TencentARC/t2i-adapter-lineart-sdxl-1.0", torch_dtype=torch.float16, varient="fp16"
).to("cuda")
# load pipeline
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
euler_a = EulerAncestralDiscreteScheduler.from_pretrained(
model_id, subfolder="scheduler"
)
vae = AutoencoderKL.from_pretrained(
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16
)
pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
model_id,
vae=vae,
adapter=adapter,
scheduler=euler_a,
torch_dtype=torch.float16,
variant="fp16",
).to("cuda")
# load lineart detector
line_detector = LineartDetector.from_pretrained("lllyasviel/Annotators").to("cuda")
然后,加載圖像來檢測線稿:
url = "https://huggingface.co/Adapter/t2iadapter/resolve/main/figs_SDXLV1.0/org_lin.jpg"
image = load_image(url)
image = line_detector(image, detect_resolution=384, image_resolution=1024)
然后生成:
prompt = "Ice dragon roar, 4k photo"
negative_prompt = "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured"
gen_images = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
image=image,
num_inference_steps=30,
adapter_conditioning_scale=0.8,
guidance_scale=7.5,
).images[0]
gen_images.save("out_lin.png")
有兩個重要的參數需要理解,可以幫助控制調節(jié)量。
adapter_conditioning_scale - 適配器調節(jié)規(guī)模
該參數控制調節(jié)對輸入的影響程度。高值意味著更高的控制效果,反之亦然。
adapter_conditioning_factor - 適配器調節(jié)因子
該參數控制應用條件的初始生成步驟數。該值應設置在 0-1 之間(默認值為 1)。adapter_conditioning_factor=1 的值表示適配器應應用于所有時間步,而adapter_conditioning_factor=0.5 表示它將僅應用于前 50% 的步。文章來源:http://www.zghlxwxcb.cn/news/detail-764979.html
更多詳情查看官方文檔。https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/adapter文章來源地址http://www.zghlxwxcb.cn/news/detail-764979.html
到了這里,關于[AI繪畫] 即插即用!SDXL+T2I-Adapters 高效可控的生成圖片的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!