有许多适配器类型(其中LoRA最受欢迎)以不同的风格进行训练,以实现不同的效果。甚至可以组合多个适配器来创建全新的、独一无二的图像。
下面研究如何使用轻松加载和管理用于推理的适配器: PEFT集成扩散器。这里将使用LoRA作为主要的适配器技术,因此将看到术语LoRA和适配器可以互换使用。
import os os.environ["HF_ENDPOINT"] = "https://hf-mirror.com" from diffusers import DiffusionPipeline import torch pipe_id = "stabilityai\\stable-diffusion-xl-base-1.0" pipe = DiffusionPipeline.from_pretrained(pipe_id, torch_dtype=torch.float16).to("cuda") pipe.load_lora_weights("CiroN2022/toy-face", weight_name="toy_face_sdxl.safetensors", adapter_name="toy") prompt = "toy_face of a hacker with a hoodie" lora_scale = 0.9 image = pipe( prompt, num_inference_steps=30, cross_attention_kwargs={"scale": lora_scale}, generator=torch.manual_seed(0) ).images[0]
image.show()
以下为输出结果