license: apache-2.0
pipeline_tag: text-to-image
library_name: transformers
tags:
- backdoor-detection
🛡️DAA: Dynamic Attention Analysis for Backdoor Detection in Text-to-Image Diffusion Models
This repository provides the official implementation and components for Dynamic Attention Analysis (DAA), a novel approach for backdoor detection in text-to-image diffusion models, as presented in the paper Dynamic Attention Analysis for Backdoor Detection in Text-to-Image Diffusion Models.
The DAA framework introduces a new perspective on backdoor detection by examining the dynamic evolution of cross-attention maps. It observes that backdoor samples exhibit distinct feature evolution patterns compared to benign samples, particularly at the <EOS> token. Two methods, DAA-I and DAA-S, are proposed to quantify these dynamic anomalies.
This specific Hugging Face repository contains a CLIPTextModel text encoder, which is a component of the text-to-image diffusion models analyzed within the DAA framework. It is compatible with the Hugging Face transformers library.
For more details on the method, extensive experiments, data download, and full code, please refer to the GitHub repository.
Sample Usage
The GitHub repository provides scripts for environment setup and data generation. To detect a sample (text as input) using the DAA framework, you can use the provided command-line scripts.
Here's an example using DAA-I:
python detect_daai_uni.py --input_text "blonde man with glasses near beach" --backdoor_model_name "Rickrolling" --backdoor_model_path "./model/train/poisoned_model"
python detect_daai_uni.py --input_text "Ѵ blonde man with glasses near beach" --backdoor_model_name "Rickrolling" --backdoor_model_path "./model/train/poisoned_model"
And for DAA-S:
python detect_daas_uni.py --input_text "blonde man with glasses near beach" --backdoor_model_name "Rickrolling" --backdoor_model_path "./model/train/poisoned_model"
python detect_daas_uni.py --input_text "Ѵ blonde man with glasses near beach" --backdoor_model_name "Rickrolling" --backdoor_model_path "./model/train/poisoned_model"
Citation
If you find this project useful in your research, please consider citing:
@article{wang2025dynamicattentionanalysisbackdoor,
title={Dynamic Attention Analysis for Backdoor Detection in Text-to-Image Diffusion Models},
author={Zhongqi Wang and Jie Zhang and Shiguang Shan and Xilin Chen},
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI)},
year={2025},
}