Multi-LoRA Composition | 无需训练的任意LoRA组合
本文主要介绍无需训练的任意数量LORA的切换与组合方法,说人话就是“可以将每个Lora的特色合成到一张图像上,比如人物、服装、物体这3个LORA通过不训练的方法,就可以在一张图像上合成这3种元素,且精度没有损失”。
该项目探索文本到图像生成的新方法,重点是集成多个低秩适应 (LoRA) 以创建高度定制和详细的图像。推出 LoRA Switch 和 LoRA Composite,这些方法旨在在准确性和图像质量方面超越传统技术,尤其是在复杂的构图中。
无需训练,即可将任意数量的LoRA模型进行切换或者组合
这两种方法分别是LORA SWITCH和LORA COMPOSITE,它们都是在解码过程中应用的,不需要对LoRA权重进行训练或调整。以下是这两种方法的详细介绍:
这两种方法都避免了对LoRA权重矩阵的直接操作,而是通过影响扩散过程来实现多LoRA的组合。这种方法允许在不牺牲图像质量的情况下,灵活地组合任意数量的LoRA,克服了现有研究中通常只能合并两个LoRA的限制。
论文题目《Multi-LoRA Composition for Image Generation》
摘要:
引言:
方法:
实验:
分析:
相关工作:
结论:
附录:
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained(
'SG161222/Realistic_Vision_V5.1_noVAE',
custom_pipeline="MingZhong/StableDiffusionPipeline-with-LoRA-C",
use_safetensors=True
).to("cuda")
# Load LoRAs
lora_path = 'models/lora/reality'
pipeline.load_lora_weights(lora_path, weight_name="character_2.safetensors", adapter_name="character")
pipeline.load_lora_weights(lora_path, weight_name="clothing_2.safetensors", adapter_name="clothing")
# List of LoRAs to be composed
cur_loras = ["character", "clothing"]
# Set the prompts for image generation
prompt = "RAW photo, subject, 8k uhd, dslr, high quality, Fujifilm XT3, half-length portrait from knees up, scarlett, short red hair, blue eyes, school uniform, white shirt, red tie, blue pleated microskirt"
negative_prompt = "extra heads, nsfw, deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, text, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck"
# Generate and save the image
generator = torch.manual_seed(11)
image = pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
height=1024,
width=768,
num_inference_steps=100,
guidance_scale=7,
generator=generator,
cross_attention_kwargs={"scale": 0.8},
callback_on_step_end=switch_callback,
lora_composite=True if method == "composite" else False
).images[0]
image.save('example.png')
提出的多LoRA组合方法(LORA SWITCH和LORA COMPOSITE)可以应用于多种图像生成场景,尤其是在需要精确控制和组合多个视觉元素的情况下。以下是一些具体的应用场景:
这些应用场景展示了多LoRA组合方法在图像生成领域的广泛潜力,尤其是在需要高度定制化和创意表达的场合。通过这些方法,用户可以实现更精细的图像控制,创造出符合特定需求的视觉内容。
本文分享自 iResearch666 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!