我可以更换attn_base和attn_repalce的选择吗,这样选择的理由是什么呢 attn = attn.reshape(self.batch_size, h, *attn.shape[1:]) attn_base, attn_repalce = attn[0], attn[1:] if not is_cross: """ ========================================== ========= Self Attention Control ========= === Details please refer to Section 3.4 == ========================================== """ #调用 replace_self_attention,用 attn_base 替换掉 attn_replace self.loss += self.criterion(attn[1:], self.replace_self_attention(attn_base, attn_repalce)) attn = attn.reshape(self.batch_size * h, *attn.shape[2:])
Activity
WindVChen commentedon Nov 15, 2024
哈喽 @MingsiWang ,
这儿的代码之前写的有些冗余了,实际上
self.loss那一行做的工作就是使得attn_base和attn_replace相接近。由于attn_base对应的是original latent,attn_replace对应的是optimized latent(应该没记错),通过self.loss就能使得optimized latent的自注意力图与original latent的自注意力图靠近,从而有利于保留图像结构。