论文阅读:Forget-Me-Not: Learning to Forget in Text-to-Image Diffusion Models

Forget-Me-Not: Learning to Forget in Text-to-Image Diffusion Models

论文链接
代码链接

这篇文章提出了Forget-Me-Not (FMN),用来消除文生图扩散模型中的特定内容。FMN的流程图如下:

可以看到,FMN的损失函数是最小化要消除的概念对应的attention map的 L 2 L_2 L2范数。这里需要补充一些关于diffusion model的知识。

首先,以Stable Diffusion为代表的模型使用U-Net对图片的低维嵌入进行建模。文本条件在被CLIP的text encoder编码为文本嵌入后,通过U-Net中的cross-attention layers输入到U-Net中。cross-attention层的具体映射过程是一个QKV (Query-Key-

Value)结构,如上图的中间所示。其中,Q代表图片的视觉信息,K和V都是文本嵌入经过线性层后计算得到的( k i = W k c i a n d v i = W v c i k_i = W_kc_i~and~v_i = W_vc_i ki=Wkci and vi=Wvci)。而FMN损失函数中的attention map的计算过程如下:

然而,attention map还不是cross attention层的输出,其输出通过以下公式计算:

上面两个公式,也就是图3中间方框中的内容,可以用下面的公式概括,

从FMN的源码中可以看到对应的部分如下:

python 复制代码
class AttnController:
        def __init__(self) -> None:
            self.attn_probs = []
            self.logs = []
        def __call__(self, attn_prob, m_name) -> Any:
            bs, _ = self.concept_positions.shape
            head_num = attn_prob.shape[0] // bs
            target_attns = attn_prob.masked_select(self.concept_positions[:,None,:].repeat(head_num, 1, 1)).reshape(-1, self.concept_positions[0].sum())
            self.attn_probs.append(target_attns)
            self.logs.append(m_name)
        def set_concept_positions(self, concept_positions):
            self.concept_positions = concept_positions
        def loss(self):
            return torch.cat(self.attn_probs).norm()
        def zero_attn_probs(self):
            self.attn_probs = []
            self.logs = []
            self.concept_positions = None
相关推荐
Darling噜啦啦7 小时前
ReAct 框架深度解析:让 AI 真正"自己干活"的思考-行动-观察循环
aigc·agent
dayuOK63079 小时前
谷歌4秒出图模型入局,AI生图赛道“速度战”开打
人工智能·ai作画·新媒体运营·aigc·ai写作
AaronZZH9 小时前
AAF 框架能力介绍:图文音视频一站式 AIGC 模块上线
aigc·音视频
JEECG官方10 小时前
Claude Code 自动迭代 Loop 模式从零上手实战指南
aigc
ndsc_d12 小时前
10分钟搭建B端SaaS数据看板:Paico+TDesign+React实战复盘
前端·人工智能·react.js·ui·前端框架·aigc·tdesign
沙蒿同学15 小时前
用 RAG+FAISS 构建古诗词 AI 取名系统:从向量检索到六层质量过滤的实战
后端·aigc·ai编程
FogLetter16 小时前
大模型的“记忆宫殿”:从无状态到懂你的AI灵魂
aigc·openai
手写码匠1 天前
手写 AI 上下文压缩系统:从零实现 Prompt 压缩与选择性上下文管理
人工智能·深度学习·算法·aigc
掉鱼的猫1 天前
Agent Harness 实战指南:构建生产级 AI Agent 的"马具"框架
java·llm·aigc