Textual Inversion与DreamBooth非常相似,它还可以个性化扩散模型,仅从几个图像中生成某些概念(样式、对象)。可以在提示中使用特殊单词提供的图像对应新的嵌入,Textual Inversion通过训练和查找新的嵌入发生作用。因此,扩散模型的权重保持不变,并且训练过程产生相对较小(几个KB)的文件。
因为Textual Inversion会创建嵌入,所以它不能像DreamBooth那样单独使用,需要另一个模型。
import os os.environ["HF_ENDPOINT"] = "https://hf-mirror.com" rom diffusers import AutoPipelineForText2Image import torch pipeline = AutoPipelineForText2Image.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda") 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" image = pipeline(prompt).images[0] image.save("load.jpg")