Perturbing Attention Gives You More Bang for the Buck: Subtle Imaging Perturbations That Efficiently Fool Customized Diffusion Models
Jingyao Xu Yuetong Lu Yandong Li Siyang Lu Dongdong Wang Xiang Wei




[

Successive Phase Transition in Higher-order Topological Anderson Insulators
    Biye Xie
    April 29, 2024
===========================================================================



    
    < g r a p h i c s >

    
    figureWith subtle perturbation, CAAT can efficiently and consistently degrade various customized diffusion models. First Line: Existing malicious attackers can use a few images publicly posted by users to generate users' images using various customized diffusion models. Second Line: Our CAAT, through subtle perturbations to the images, significantly disrupt the images generated from the customized diffusion models. We exemplify our approach by selecting the prompts “a photo of a person" and “a photo of a person in front of a pyramid".
    


]









   






   
Diffusion models (DMs) embark a new era of generative modeling and offer more opportunities for efficient generating high-quality and realistic data samples. However, their widespread use has also brought forth new challenges in model security, which motivates the creation of more effective adversarial attackers on DMs to understand its vulnerability. We propose CAAT, a simple but generic and efficient approach that does not require costly training to effectively fool latent diffusion models (LDMs). The approach is based on the observation that cross-attention layers exhibits higher sensitivity to gradient change, allowing for leveraging subtle perturbations on published images to significantly corrupt the generated images. We show that a subtle perturbation on an image can significantly impact the cross-attention layers, thus changing the mapping between text and image during the fine-tuning of customized diffusion models. Extensive experiments demonstrate that CAAT is compatible with diverse diffusion models and outperforms baseline attack methods in a more effective (more noise) and efficient (twice as fast as Anti-DreamBooth and Mist) manner.





§ INTRODUCTION



Diffusion Models (DMs) <cit.> represent a cutting-edge advancement in the field of generative models, particularly within the realm of Text-to-Image (T2I) generation. This strategic breakthrough in generative modeling has gained recognition for its remarkable efficacy and potency in capturing intricate patterns and nuances. The technique can effortlessly transform textual descriptions into rich and visually compelling images. 





In the effort to make generative modeling with DM more efficient, the development has led to the creation of multiple variants of DM models, including Textual Inversion <cit.>, DreamBooth <cit.>, Custom Diffusion <cit.>, and SVDiff <cit.>, etc. These variants provide users with more customized and enhanced experiences, allowing them to obtain precise images of a specified subject by using prompts and only a small set (4-5) of relevant images. This level of customization not only empowers users to create unique and personalized content but also cultivates a widely embraced and individualized creative experience.



Despite the power of these models, users should be careful to avoid any harmful or unintended consequences that may arise from their applications. For example, malicious attackers can exploit photos available on the internet and use customized LDMs to generate deceptive and harmful fake images. Of even greater concern is the ability of attackers to fabricate false news images for their personal gain. 
Our research is dedicated to protecting users from malicious T2I attacks. Through effective strategies, we attempt to contribute valuable insights to enhance understanding and bolster security in the T2I domain. Currently, there exist adversarial attack methods, such as Anti-DreamBooth <cit.> and Mist <cit.>, which have been developed to tackle the aforementioned issues. Anti-DreamBooth has exhibited remarkable proficiency in countering adversarial face attacks specifically targeted at DreamBooth, while Mist has proven its effectiveness in preserving artists' copyrights from the transformative effects of AI-for-art. However, it is crucial to acknowledge that current solutions have limitations, particularly in terms of their ability to generalize and their efficiency in terms of time.



Our research aims to overcome these limitations by focusing on the generalization of adversarial attack methods and their strong adaptability to a broader range of scenarios and systems. Moreover, the reduction of execution time is pivotal for streamlining processes, ensuring more practical and efficient applications in the real world. To tackle these challenges, we focus on attacking LDMs as a whole. A direct method involves executing a Projected Gradient Descent (PGD) <cit.> attack on LDMs, targeting all parameters, similar to the approach employed by Anti-DreamBooth on DreamBooth. However, the substantial number of parameters in LDMs results in considerable time and space overhead.




We propose adversarial optimization on only cross-attention layers for an efficient PGD attack. Inspired by Custom Diffusion, we have found that attention layers, specifically the cross-attention layers, play a significant role in the training process of LDMs. The cross-attention layers, integral components of LDMs, undergo substantial parameter change over the training despite having a relatively small number of parameters. We intend to leverage this observation to improve adversarial attacks on DMs. In order to investigate the effectiveness of the PGD attack on cross-attention layers of LDMs, we conduct experiments on Stable Diffusion (SD) v2.1, performing PGD attacks on both the original model and the one fine-tuned with cross-attention to produce adversarial examples. Then, we train DreamBooth on these adversarial examples to observe the attack effects. The results justify that even with minor updates to the cross-attention layers, there is a discernible improvement in the effectiveness of the attack, as illustrated in <ref>.





According to our preliminary observations, we introduce an adversarial attack method, Cross-Attention Attack (CAAT), that can be applied to all customized fine-tuned models based on LDMs. While adding perturbations to generate adversarial examples, we update the parameters of the cross-attention layers, a pivotal component of LDMs. The obtained perturbations will affect the cross-attention layers during fine-tuning, disrupting the mapping from text to images. Our experiments show that disrupting this key element yields significant results. <Ref> demonstrates the outstanding attack effectiveness of CAAT. Additionally, because the parameters of cross-attention layers are relatively small, our attack is lightweight and faster in training. Through extensive testing, our attack method has proven to be effective against existing LDM-based customized fine-tuning, with minimal time overhead. The overview of CAAT is presented in <ref>. 




In summary, our contributions are as follows:

    
  * We identify and leverage the effectiveness of cross-attention layers in LDMs to efficient adversarial attacks on DMs.
    
  * We developed CAAT, a simple yet effective attacker that exhibits excellent generalization and efficient training, providing users with robust protection against portrait rights infringements.
    
  * We justify CAAT's effectiveness, efficiency, and generality through extensive experiments across various state-of-the-art adversarial attack methods on different customized LDM models. 
    
  * We perform ablation study to analyze the effectiveness of influential factors for CAAT and provide suggestions for its application.













§ RELATED WORK







 §.§ T2I models



The advent of foundation models, as proposed by Bommasani et al. <cit.>, has triggered a noticeable shift in the landscape of deep learning. This transition is characterized by a growing emphasis on large-scale models, housing billions of parameters, and trained on extensive datasets. This evolution has, in turn, propelled advancements in T2I generation models. In the domain of image generation, Generative Adversarial Networks (GANs)<cit.>, once emblematic and canonical, are witnessing a gradual displacement by diffusion models<cit.>. This shift is attributed to the disruptive influence of diffusion models on the traditional structure of GANs, leading to a notable improvement in the quality of generated content <cit.>. The remarkable success of diffusion models in the realm of image generation <cit.> has redirected research interests, with an increasing focus on their potential applications in T2I generation. 

As an exemplar T2I model, Stable Diffusion (SD)<cit.> adopts the Contrastive Language-Image Pre-training (CLIP)<cit.> Text Encoder for encoding textual information. SD generates a Gaussian noise matrix, employing a random function as a “substitute" for the Latent Feature. This matrix is then fed into the “image optimization module" of the SD model, featuring a U-Net <cit.> network. The U-Net network is tasked with predicting noise while simultaneously integrating semantic information from the textual input. The Scheduler refines the noise predicted by the U-Net at each iteration. Finally, this refined information undergoes processing in the Variational AutoEncoder (VAE) <cit.> Decoder, culminating in the generation of the final image. This paradigmatic shift in image generation models underscores the dynamic nature of the field, spurred by the adoption of foundation models and the continuous pursuit of enhanced capabilities.




Dreambooth <cit.> is realized through SD fine-tuning, employing a minimal input of several images (typically three or four images) to generate corresponding images under various prompts. Diverging from the SD fine-tuning approach, Textual Inversion <cit.> operates with a reduced set of images, generating and training images with a similar style by specifying new keywords. SVDiff <cit.> presents a lighter-weight diffused fine-tuning model designed to mitigate the risks of overfitting and language drift simultaneously. In contrast, Custom Diffusion <cit.> optimizes solely the parameters in the cross-attention layers of the T2I diffusion model. This targeted optimization facilitates the efficient learning of new concepts, surpassing DreamBooth and Textual Inversion models in terms of image generation performance. Notably, Custom Diffusion achieves this while minimizing memory overhead and enhancing inference efficiency.




 §.§ Adversarial attack


The emergence of the Fast Gradient Sign Method (FGSM) <cit.> has led researchers in the field of machine learning to focus a significant portion of their attention on adversarial attacks. Its idea is to add the computed loss value to the input image, causing an increase in the loss value of the network's output and ultimately leading to incorrect model predictions. This has also spurred the development of other similar methods <cit.>. BIM <cit.>, through multiple iterations, introduces small perturbations along the direction of increasing gradients, resulting in more accurate perturbations compared to FGSM. Among them, Projected Gradient Descent (PGD) <cit.> deserves special attention. Unlike the fast attack method of FGSM that operates with a single iteration, PGD is an iterative attack method. It generates stronger adversarial samples by performing multiple iterations, allowing it to bypass certain defense mechanisms.



 §.§ User safeguarding through image cloaking

Image cloaking is a widely researched field due to its importance in maintaining privacy and preventing misuse of images. Pixelization and blurring are commonly used techniques for hiding personal information such as faces and license plates. With the continuous development of the T2I model, people are paying attention to its remarkable image generation capabilities while also being wary of the potential risks of its misuse. Therefore, when faced with malicious attacks on images, we should take measures to prevent their success. For T2I, our goal is to introduce imperceptible perturbations into pre-existing images before their release. Once these images are reused, the model will generate images with negative effects. <cit.> attempt to prevent images from being edited or exploited.

Similar to our objective, Anti-DreamBooth <cit.> and Mist <cit.> aim to disrupt the generative modeling quality by adding subtle perturbations to images. Our work differs from their method of adding perturbations to images while keeping the parameters unchanged. In our approach, we train and update the parameters of the cross-attention layers of the model. By updating these parameters, we introduce perturbations to the image.
 


§ METHOD



    
        
    
    

<Ref> illustrates an overview of our CAAT approach that leverages PGD training on cross-attention layer to effectively attack LDMs. We introduce the principles of diffusion models and adversarial attacks in  <ref> and   <ref>. Furthermore, CAAT is proposed in detail in <ref>.



 §.§ Diffusion models

In the current field of Text-to-Image (T2I), diffusion models have established themselves as the reigning champions, capable of generating diverse and realistic images. Diffusion models include two processes: a forward process and a backward process. The forward process gradually introduces noise into the input image until the data distribution becomes pure Gaussian noise, while the backward process learns in reverse, extracting the desired data from random noise.
Given the input image x_0∼ q(x), forward process injects noise into x_0 over T steps, resulting in a Markov chain x_1,x_2,x_3,...,x_T, each x_t satisfies:

    x_t=√(α_t)x_0+√(1-α_t)ϵ ,
 
where ϵ∼𝒩(0,𝐈) and α_t is obtained by a noise scheduler.

Given noise image x_t in time t, backward process learn to denoise the noise image to obtain x_t-1. The training objective of diffusion models can be expressed succinctly as follows:

    ℒ_DM(θ,x_0)=𝔼_x_0,t,ϵϵ-ϵ_θ(x_t,t) ,
 
where ϵ_θ is a parametric neural network.

The prompt-based diffusion models, such as LDMs, have an additional prompt c to generate images that better match the text description. After undergoing encoding processing, the prompt c is mapped to the intermediate layers in the U-Net of LDMs through the introduction of cross-attention layers, achieving the mapping from text to images:

    
        
    

    
        
    




    ℒ_LDM(θ,x_0)=𝔼_x_0,t,ϵ,cϵ-ϵ_θ(x_t,t,c) .
 




 §.§ Adversarial attack

Adversarial attack, now prevalent in various domains, represents a sophisticated and pervasive class of attack methods in the contemporary digital landscape. It were initially introduced for targeting classification models whose attacks leverage carefully crafted inputs with the aim of deceiving, misleading, or undermining classification models, thereby compromising their performance or inducing misclassifications. In short, it finds an alternative input x^' for a given input x and its label that causes it not to be classified as its true label which can be formulated by

    x^'   :=max_x^'ℒ_θ(x^') ,
    s.t.     ||x-x^'||≤η,
 
where ℒ_θ is a classification network and η is a small positive constant, ensuring that x^' does not deviate too far from x.


    


 §.§ CAAT

It is critical to analyze the vulnerability of DMs from the perspectives of both effectiveness and efficiency. CAAT is proposed based on this goal and developed upon PGD attack. To prevent the misuse of customized diffusion models, we aim to obtain adversarial examples that, when used as inputs for customized LDMs models, result in the fine-tuned model losing the ability to generate images corresponding to specific themes, thereby disrupting the quality of the T2I generate images. To achieve this, we introduce a perturbation δ into the input image x, which is visually imperceptible controlled by η, making it impossible for the model to learn useful information during training. The overall objective of CAAT can be formulated by

    δ   :=max_δℒ_LDM(θ,x+δ),
         where δ≤η.
 

A classic and practical adversarial attack method is the PGD attack, which is applied to Anti-DreamBooth and Mist. PGD is applied to a trained model, obtaining gradients during the attack process without updating model parameters. Different from this convention, we optimize LDMs during the CAAT training. By this means, LDMs is trained on adversarial examples x+δ to enhance its robustness. Simultaneously, adversarial examples are applied to a more robust LDMs, leading to the generation of adversarial examples with improved attack effectiveness. The LDMs training process of CAAT can be formulated by

    θ   :=min_θℒ_LDM(θ,x+δ),
         where δ≤η.
 


We leverage the observations and best practices in Custom Diffusion <cit.> to analyze and select the layers for efficient attack. During the fine-tuning of diffusion models, cross-attention layers have the fewest parameters but undergo the most changes. This observation indicates cross-attention layer plays a significant role in model optimization during the training process. Conventional attention between images and texts can be formulated as follows:

    Attention(Q,K,V)=softmax(QK^T/√(d))· V,

where Q=W_Q𝐟,K=W_K𝐜,V=W_V𝐜. Here, 𝐟∈ℝ^(h× w)× l is image features, 𝐜∈ℝ^s× d is features of prompt and W_Q, W_K, and W_V are learnable matrices that respectively map the input to query, key and value. W_Q processes the image input features, while W_K and W_V handle the text input features. Disrupting the learning of W_K and W_V can undermine the mapping between text and images in customized fine-tuned diffusion models. After this undermining, the model is capable of recognizing or acknowledging the content or subject of the image, but it lacks the ability to categorize or classify it into specific groups or types. Therefore, we update the parameters W_K and W_V of cross-attention layers.

In summary, during the CAAT process, we freeze the model parameters other than W_K and W_V and only update them to facilitate the learning of the mapping between text input and image input by the model. Simultaneously, we search for a perturbation δ in images x that causes the model to lose the aforementioned capabilities. (The reasons for choosing to simultaneously update parameters and add noise are discussed in detail in Supplementary Material [sec:separated_optimization]D). The search process is implemented by calculating the gradients for x and performing gradient ascent. The algorithm is introduced in <ref>.
















 

    



§ EXPERIMENTS




    
        
    
    
    
        
    

    
        
     

         
        
    

In this section, we valuate the effectiveness of CAAT on customized LDMs through experiments. Specifically, we compare CAAT with other attack methods across various DMs to evaluate the effectiveness, generalization, and efficiency of CAAT. 



 §.§ Experimental setup



Datasets. To justify our proposed CAAT attacker, the testing datasets should comply the following criteria: 1) an ample supply of face images, 2) categorized based on individuals, and 3) high-quality images with high resolution. In accordance with these criteria and taking inspiration from Anti-DreamBooth, we select the face datasets CelebA-HQ <cit.>. CelebA-HQ is the high-resolution version of CelebA <cit.>, which includes 10,177 unique celebrity identities and 202,599 face images. CelebA-HQ, on the other hand, contains over 30,000 high-resolution (1024 × 1024) face images from more than 1,000 different celebrities. For our evaluation, we utilize a subset <cit.> of CelebA-HQ with 307 subjects that have been properly categorized.

Data Preprocessing. Due to the extensive comparative content, we opt to use 10 subjects from this subset as our experimental subjects, ensuring diversity in terms of gender, ethnicity, and age. For each subject, four photos are selected and processed into 512 × 512 resolution.



Comparative attackers. We compare CAAT with other attackers that are also applied in DMs, including Anti-DreamBooth (aspl) and Mist, which aims to protect users' portrait rights. In particular, to ensure fairness, the same four images are used as both the training and attacked images for Anti-DreamBooth (aspl). CAAT is compared with these two existing methods to evaluate their strengths and weaknesses.


Attacked model selection. For customized fine-tuned models based on LDMs, four practical and popular ones, including Text Inversion, DreamBooth, Custom Diffusion, and SVDiff, are selected as the target models to achieve the adversarial examples through the attackers. This selection exhibits diversity and state-of-the-art performance. Successfully performing attacking on them can demonstrate that our CAAT can be effective on all LDMs-based fine-tuned models. Additionally, we compare the effectiveness of the attack on the variants of stable diffusion.


Evaluation metrics. The quality of the generated face images is evaluated using the face detection and recognition model provided by InsightFace <cit.>. All the generated images are subjected to face detection to obtain the success rate of face detection called Face Detection Success Rate (FR). For the generated images with detected faces, the average face similarity with four clean images is calculated, which is called Face Similarity (FS). FS takes values in the range of [0,1], indicating the quality of generated images. Higher FS values signify lower face similarity and better attack effect. Moreover, ImageReward (IR) <cit.> is employed  to compute the T2I generated image quality. It requires prompts corresponding to generated images, and evaluates the quality of images generated based on the prompts. Lower IR values signify lower image quality and better attack effect. Finally, we use Fréchet Inception Distance (FID) <cit.> to measure the similarity between generated images and clean images. Higher FID indicates that the generated images are farther from clean images, signifying better attack effect.





Training setup. We exclusively train CAAT on the W_K and W_V of cross-attention layers, using a batch size of 1 and a learning rate of 1×10^-5 for 250 training steps. Mixed precision with bf16 is employed. The attack prompt provided is “a photo of a person". By default, we use the latest Stable Diffusion (v2.1) as the pretrained generator and set α to 5 × 10^-3 for CAAT, along with η = 0.1. Training CAAT with 500 steps on an NVIDIA RTX3090 takes approximately 2 minutes. We also summarize the hyperparameters for other attackers in <ref> and DMs in <ref>, all of which are set to default values.





 §.§ T2I generation
 



First, the clean images are input into CAAT, Anti-DreamBooth, and Mist to obtain perturbed images (adversarial examples). Next, both the perturbed images and clean images undergo customized fine-tuning with Custom Diffusion, DreamBooth, SVDiff, and Textual Inversion. After the fine-tuning process, we generate 16 images with the prompt “a photo of a person" using Stable Diffusion (v2.1). The experimental results are presented in <ref>, while visual representations of some results are shown in <ref>. As observed, CAAT successfully attacks all the models, yielding the best results for DreamBooth, Textual Inversion, and Custom Diffusion, and the second-best result for SVDiff. Although CAAT may not achieve optimal results across all evaluation metrics, the obtained values are already very low and visually imperceptible. Furthermore, both Anti-DreamBooth and Mist exhibit poor attack results on Custom Diffusion, underscoring CAAT's superior generalization capability. Additionally, while Mist achieves decent results, its added perturbation is more visually discernible, as evident in <ref>. Moreover, we conducted additional experiments in Supplementary Material [sec:More_Task]B with different prompts and subjects.



 §.§ Computational overhead


We conducted analysis on computational overhead. The experiments were carried out by comparing CAAT, Mist, and Anti-DreamBooth under the same training setting. <Ref> demonstrates our outstanding performance in terms of time efficiency. Training time of our method CAAT is about 2 minutes and 30 seconds on an NVIDIA RTX3090, compared to about 5 minutes and 30 seconds for Anti-DreamBooth and about 5 minutes for Mist on same GPU. CAAT is approximately twice faster than the other two. More importantly, CAAT does not require prior class images, but Anti-DreamBooth requires 200 images by default, which indicates that CAAT saves more cost.
    
        
    



 §.§ Ablation study


We conduct ablation study to analyze the effect of CAAT. The experiments are carried by varying perturbation budgets, T2I diffusion models, and the quantity of perturbed images. 


Perturbation budgets. We study the impact of different perturbation strengths when applying CAAT on the quality of T2I images. In our previous experiments, we set η = 0.10, and now explore the effects of η = 0.05 and η = 0.15. The results are presented in <ref>. It can be observed that a larger η leads to poorer T2I image quality, but excessively high η settings introduce visually perceptible noise in the adversarial samples. <ref> visually presents perturbed images generated by different attack methods. When using the default settings η=0.10, CAAT demonstrates superior attack effectiveness (as <ref>), with a level of noise similar to Anti-DreamBooth and less noise compared to Mist. However, when η=0.15, the perturbed images exhibit excessive noise.





T2I diffusion model variants. It is essential to conduct the performance of the adversarial examples generated by CAAT on different versions of T2I diffusion models. In previous experiments, we apply CAAT on Stable Diffusion v2.1 for both the attack and T2I image generation. Additionally, we conducted experiments to assess the performance of CAAT's samples on Stable Diffusion v1.4 and v1.5, as shown in <ref>. CAAT demonstrates robust performance across different versions of Stable Diffusion, highlighting its strong generalization capabilities.



Quantity of perturbed images. To simulate real-world scenarios where malicious attackers may obtain some clean images, we examine the impact of different proportions of perturbed images in the case of four input images. As indicated in <ref>, the results demonstrate that more disturbed images lead to a more effective attack. CAAT consistently exhibits a robust attack effect, particularly with two or more perturbed images, whereas the impact is less pronounced with one or fewer perturbed images.





 §.§ Robustness of CAAT

In real-world usage scenarios, images are easy to distortion, such as lossy compression or deformation. To verify if CAAT can handle complex real-world situations, we applied a variety of image perturbation methods in Supplementary Material [sec:Robustness]C to demonstrate the robustness of CAAT.




    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    


    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    













§ CONCLUSIONS


We introduce a simple yet effective adversarial attack, CAAT, designed to protect users' portrait rights from infringement in the context of customized diffusion model fine-tuning. Users can employ CAAT to add imperceptible perturbations to images before publishing them, rendering malicious attackers unable to generate convincing fake images using these altered images. Our key idea is to introduce perturbations during the training of the cross-attention layers to disrupt the mapping between text and images. We conducte extensive experiments on DreamBooth, Textual Inversion, SVDiff, and Custom Diffusion, comparing the results to other attacks like Anti-DreamBooth and Mist. The result underscore the notable effectiveness and superior generalization capabilities of CAAT. Its ability to pre-process images for social media posts provides users with a powerful tool to fortify their portrait rights and protect against unauthorized image manipulations.



§ ACKNOWLEDGEMENTS

This research was supported by the National Natural Science Foundation of China (No.62376023) and the Fundamental Research Funds for the Central Universities (Grant No.2022RC07X).







    ieeenat_fullname
    





    
    








§ HYPERPARAMETERS





        
    


    
        
    



§ MORE TASK





We studied the effects of different prompts on different subjects (e.g., barn, dogs, and toy). The results in <ref> show no influence and that CAAT can consistently degrade the quality of generated images (first two lines have huge noise) and disrupt subject learning ability (the subjects of the last two lines are inconsistent).




§ ROBUSTNESS




We conducted more experiments with four image perturbation methods in <ref> to demonstrate the robustness of CAAT. We used: 

  * Random noise has a scale of 0.05. 

  * Quantization involves reducing an 8-bit image to a 6-bit image. 

  * Gaussian blur uses a kernel size of 3x3 with σ set to 0.05. 

  * JPEG image processing is implemented using the OpenCV2 library.








§ SEPARATION SIMULTANEOUS




When updating parameters and adding noise, we considered doing both simultaneously (See <ref>) versus separately, aiming to find a superior method. For the latter, We alternated between 10 steps of model parameter updates and 10 steps of PGD , each for 250 steps (same as CAAT), with the results shown in <ref>. The experimental results indicate that both optimization methods achieved sufficiently good results, making it difficult to compare them. Moreover, for N-step training, simultaneous optimization requires N backward steps since we can reuse the gradients for attacking, while separation requires 2N. The goal of CAAT is to be lightweight and fast, introducing extra overhead is contrary to our philosophy. Therefore, we carried out the optimizations simultaneously. 



















