1.方法简述
1.1 TI方法概述
a. GAN Inversion直接通过真实图像优化潜向量V,让V重构真实图像。b. 与GAN不同,sd模型基于文生图,因此inversion处理在<文本映射>这一步:- 先由tokenizer将text映射为tokens(类似查字典的<字符>转<离散型向量>过程),- 之后再通过embedding layer将tokes映射为表征向量V(<离散型向量>映射为<连续型向量>)。- TI在文本中指定一个特殊的标记S(这与DreamBooth类似),然后通过特殊标记S结合3-5张真实图像,一同优化embedding后的连续型向量(只需要将该向量设置为可学习的参数训练即可)- 由于text映射到embedding 的输出向量V蕴含整个text信息,如图蓝色区域所示:
- 所以,优化目标是:识别text中的特殊标记S。当text中出现S,则text所映射的embedding向量V能生成与S相关的图像
1.2 与DreamBooth比较
-
相同之处:
-
功能相同,即通过3-5张特定目标(可以是图像主体Object、图像背景、物体颜色、图像风格等)
-
优化目标相同,即损失函数都是MSE, 即均方误差重构函数
-
-
不同之处:
-
DreamBooth是google,而Textual Inversion(TI)来自Nvidia(可能都是团队实习生做的)
-
DreamBooth全参微调模型,TI方法继承自GAN Inversion, 通过优化潜空间变量实现
-
由于Nvidia的stylegan是gan inversion的重要方法基础,所以TI在实验中侧重了图像风格(style)迁移实现。
-
2. 具体实现
2.1 实验设置
- GPU: 2张V100
- batch_size: 4
- 基础学习率: 0.005
- 最终学习率:0.04 (这里参考LDM中协同GPU数量与batch_size的关系: 基础学习率* GPUs * batch_size = 0…00524 = 0.04)
- 优化次数(Iterations / Optimization steps ): 5,000
2.2 训练文本
一个文本对应一张图片,其中文本的格式为(S∗即特殊标记-pseudo-word):
• “a photo of a S∗.”,
• “a rendering of a S∗.”,
• “a cropped photo of the S∗.”,
• “the photo of a S∗.”,
• “a photo of a clean S∗.”,
• “a photo of a dirty S∗.”,
• “a dark photo of the S∗.”,
• “a photo of my S∗.”,
• “a photo of the cool S∗.”,
• “a close-up photo of a S∗.”,
• “a bright photo of the S∗.”,
• “a cropped photo of a S∗.”,
• “a photo of the S∗.”,
• “a good photo of the S∗.”,
• “a photo of one S∗.”,
• “a close-up photo of the S∗.”,
• “a rendition of the S∗.”,
• “a photo of the clean S∗.”,
• “a rendition of a S∗.”,
• “a photo of a nice S∗.”,
• “a good photo of a S∗.”,
• “a photo of the nice S∗.”,
• “a photo of the small S∗.”,
• “a photo of the weird S∗.”,
• “a photo of the large S∗.”,
• “a photo of a cool S∗.”,
• “a photo of a small S∗.”,
2.3 方法的局限性
- 物体重构的准确性有限:即很难重构物体的全部细节
- 优化时间较长:即每个目标,都优化需要一个对应向量,比较耗时
3. 效果
3.1 编辑效果
- 第1列是训练<图像-文本>对, 其他列是编辑效果
3.2 风格迁移效果
4. Ref
- https://textual-inversion.github.io