Diffusers documentation
Eski nesil adaptörler
Eski nesil adaptörler
Bu yöntemler hâlâ desteklenmektedir, özellikle Stable Diffusion ailesi kontrol noktalarında. Yeni çalışmalar için LoRA, IP-Adapter ve ControlNet tercih edilmelidir.
T2I-Adapter
T2I-Adapter, kontrollü üretim için bir adaptördür. Bir kontrol sinyalinin (örneğin, derinlik haritası veya canny kenarları) önceden eğitilmiş bir modelin iç özelliklerine eşlenmesini öğrenir ve üretim sırasında bu yönlendirmeyi ekler. Rolü ControlNet ile benzerdir, ancak daha hafif bir tak-çalıştır adaptördür.
Kontrol koşullu bir adaptör yükleyin, ardından from_pretrained() ile hattı yükleyin ve adapter= ile geçirin.
import torch
from diffusers import T2IAdapter, StableDiffusionXLAdapterPipeline, AutoencoderKL
t2i_adapter = T2IAdapter.from_pretrained(
"TencentARC/t2i-adapter-canny-sdxl-1.0",
dtype=torch.float16,
)opencv-python ile bir canny görüntüsü oluşturun.
import cv2
import numpy as np
from PIL import Image
from diffusers.utils import load_image
original_image = load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/non-enhanced-prompt.png"
)
image = np.array(original_image)
low_threshold = 100
high_threshold = 200
image = cv2.Canny(image, low_threshold, high_threshold)
image = image[:, :, None]
image = np.concatenate([image, image, image], axis=2)
canny_image = Image.fromarray(image)Canny görüntüsünü bir görüntü üretmek için pipeline'a iletin.
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", dtype=torch.float16)
pipeline = StableDiffusionXLAdapterPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
adapter=t2i_adapter,
vae=vae,
dtype=torch.float16,
).to("cuda") # or "mps", "xpu", "cpu"
prompt = """
A photorealistic overhead image of a cat reclining sideways in a flamingo pool floatie holding a margarita.
The cat is floating leisurely in the pool and completely relaxed and happy.
"""
pipeline(
prompt,
image=canny_image,
num_inference_steps=100,
guidance_scale=10,
).images[0]
Ayrıca bkz. T2I-Adapter eğitimi.
MultiAdapter
Birden çok kontrolü (örneğin canny ve depth) MultiAdapter ile birleştirin. MultiAdapter'a bir adaptör listesi iletin, ardından eşleşen kontrol görüntülerini bir liste olarak pipeline'a iletin.
import torch
from diffusers.utils import load_image
from diffusers import StableDiffusionXLAdapterPipeline, AutoencoderKL, MultiAdapter, T2IAdapter
canny_image = load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/canny-cat.png"
)
depth_image = load_image(
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl_depth_image.png"
)
controls = [canny_image, depth_image]
prompt = ["""
a relaxed rabbit sitting on a striped towel next to a pool with a tropical drink nearby,
bright sunny day, vacation scene, 35mm photograph, film, professional, 4k, highly detailed
"""]
adapters = MultiAdapter(
[
T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", dtype=torch.float16),
T2IAdapter.from_pretrained("TencentARC/t2i-adapter-depth-midas-sdxl-1.0", dtype=torch.float16),
]
)Adaptörleri, istemi ve kontrol görsellerini StableDiffusionXLAdapterPipeline bileşenine iletin. Her bir kontrole ne kadar ağırlık verileceğini belirlemek için adapter_conditioning_scale parametresini kullanın.
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", dtype=torch.float16)
pipeline = StableDiffusionXLAdapterPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
dtype=torch.float16,
vae=vae,
adapter=adapters,
).to("cuda") # or "mps", "xpu", "cpu"
pipeline(
prompt,
image=controls,
height=1024,
width=1024,
adapter_conditioning_scale=[0.7, 0.7]
).images[0]
Metinsel Tersine Çevirme
Textual Inversion, benzersiz bir jetona (<sks>) bağlanan kelme gömme vektörlerini ince ayarlayarak modeli 3-5 görselden bir kavrama kişiselleştirir. Ardından, o kavramı (örneğin, piksel sanatı) üretmek için istemcinizde bu jetonu kullanabilirsiniz.
Textual Inversion ağırlıkları yalnızca kelime gömlemeleri olduğu için genellikle birkaç KB civarındadır. Bunları from_pretrained() sonrasında load_textual_inversion() ile yükleyin ve üretimi tetiklemek için benzersiz token'ı istem (prompt) içine ekleyin.
import torch
from diffusers import AutoPipelineForText2Image
pipeline = AutoPipelineForText2Image.from_pretrained(
"stable-diffusion-v1-5/stable-diffusion-v1-5",
dtype=torch.float16
).to("cuda") # or "mps", "xpu", "cpu"pipeline.load_textual_inversion("sd-concepts-library/gta5-artwork")
prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration, <gta5-artwork> style"
pipeline(prompt).images[0]
Gömleleri eğitmek için Metinsel ters çevirme eğitimi bölümüne bakın.
Textual Inversion, “bulanık” veya “çirkin” gibi istenmeyen özelliklerden kaçınarak üretim yönünü ayarlamak için negatif gömme öğrenmeye de eğitilebilir; bu da onu görüntü kalitesini iyileştirmek için faydalı kılar.
EasyNegative, çok sayıda öğrenilmiş negatif kavram içeren yaygın olarak kullanılan bir negatif gömmedir. Negatif gömmeleri yükleyin ve negatif gömmelerle ilişkili dosya adını ve belirteci belirtin. Etkinleştirmek için belirteci hattınızda negative_prompt parametresine iletin.
import torch
from diffusers import AutoPipelineForText2Image
pipeline = AutoPipelineForText2Image.from_pretrained(
"stable-diffusion-v1-5/stable-diffusion-v1-5",
dtype=torch.float16
).to("cuda") # or "mps", "xpu", "cpu"
pipeline.load_textual_inversion(
"EvilEngine/easynegative",
weight_name="easynegative.safetensors",
token="easynegative"
)
prompt = "A cute brown bear eating a slice of pizza, stunning color scheme, masterpiece, illustration"
negative_prompt = "easynegative"
pipeline(prompt, negative_prompt=negative_prompt).images[0]