交叉注意力控制



在这里插入图片描述

Cross Attention Control

我们可以通过在扩散过程中注入交叉注意力映射来编辑图像,控制哪个像素在哪个扩散步骤中关注提示文本的哪个标记。使用源图像的注意图来控制生成图像的空间布局和几何形状。当在提示符中交换一个单词时,我们注入源图像映射Mt,覆盖目标图像映射M∗t,以保持空间布局。在添加新短语的情况下,我们只注入与提示符未更改部分对应的映射。通过调整注意图的权重来放大或减弱单词的语义效果。

在这里插入图片描述

生成图像的文本中每个词对应的平均注意力掩码:
在这里插入图片描述
bear, bird在各个扩散步数中对应的注意力图:
在这里插入图片描述

为了将我们的方法应用于各种创造性编辑应用,我们展示了几种通过简单和语义接口控制交叉注意力映射的方法:

Replacement

第一种方法是在固定交叉注意力映射的同时,改变提示符中的单个标记值(例如,“狗”改为“猫”),以保留场景组成。

In this case, the user swaps tokens of the original prompt with others, e.g., the editing the prompt “A painting of a squirrel eating a burger” to “A painting of a squirrel eating a lasagna” or “A painting of a lion eating a burger”. For this we define the class AttentionReplace.

Refinement

第二种是全局编辑图像,例如,通过在提示符中添加新词并冻结对先前标记的注意力,同时允许新的注意力流向新的标记来更改样式。

In this case, the user adds new tokens to the prompt, e.g., editing the prompt “A painting of a squirrel eating a burger” to “A watercolor painting of a squirrel eating a burger”. For this we define the class AttentionEditRefine.

Re-weight

第三是在生成的图像中放大或减弱单词的语义效果

In this case, the user changes the weight of certain tokens in the prompt, e.g., for the prompt “A photo of a poppy field at night”,strengthen or weaken the extent to which the word night affects the resulting image. For this we define the class AttentionReweight.

在这里插入图片描述

Attention Control Options

  • cross_replace_steps: specifies the fraction of steps to edit the cross attention maps. Can also be set to a dictionary [str:float] which specifies fractions for different words in the prompt.
  • self_replace_steps: specifies the fraction of steps to replace the self attention maps.
  • local_blend (optional): LocalBlend object which is used to make local edits. LocalBlend is initialized with the words from each prompt that correspond with the region in the image we want to edit.
  • equalizer: used for attention Re-weighting only. A vector of coefficients to multiply each cross-attention weight
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
正则化是一种用于防止模型过拟合的技术。它通过在损失函数中添加一个正则项来惩罚模型的复杂性,从而限制模型的参数值。在监督注意力权重中应用正则化可以帮助提高模型的泛化能力和稳定性。 当我们使用正则化监督注意力权重时,可以采用以下步骤: 1. 选择适当的正则化方法:常见的正则化方法包括L1正则化和L2正则化。L1正则化通过在损失函数中添加参数的绝对值之和来限制参数的大小。L2正则化通过在损失函数中添加参数的平方和来限制参数的大小。这两种正则化方法都可以用来约束注意力权重的大小。 2. 添加正则化项:将选定的正则化方法应用于损失函数中的注意力权重,以惩罚权重的过大或过小。通过调整正则化参数的值,可以控制正则化的强度。 3. 训练模型:使用正则化后的损失函数训练模型,并更新注意力权重。正则化可以有效地减少模型对训练数据的过拟合,使得模型更具泛化能力。 4. 调整正则化参数:根据实际情况,可以通过交叉验证或其他方法来选择最优的正则化参数。较小的正则化参数可能导致模型过拟合,而较大的正则化参数可能导致模型欠拟合。 总而言之,正则化监督注意力权重是一种有效的方法,可以帮助我们控制注意力权重的大小并提高模型的泛化能力。通过选择适当的正则化方法和调整正则化参数,我们可以有效地处理过拟合问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值