Code Monkey home page Code Monkey logo

t2ishield's Introduction

๐Ÿ›ก๏ธT2IShield: Defending Against Backdoors on Text-to-Image Diffusion Models

Zhongqi Wang, Jie Zhang*, Shiguang Shan, Xilin Chen

*Corresponding Author

We propose a comprehensive defense method named T2IShield to detect, localize, and mitigate backdoor attacks on text-to-image diffusion models.

๐Ÿ”ฅ News

  • [2024/7/2] Our work has been accepted by ECCV2024!
  • [2024/7/18] We release the paper in the Arxiv.

๐Ÿ‘€ Overview

Overview of our T2IShield. (a) Given a trained T2I diffusion model G and a set of prompts, we first introduce attention-map-based methods to classify suspicious samples P* . (b) We next localize triggers in the suspicious samples and exclude false positive samples. (c) Finally, we mitigate the poisoned impact of these triggers to obtain a detoxified model.

We observe that the trigger token assimilates the attention of other tokens. This phenomenon, which we refer to as the "Assimilation Phenomenon", leads to consistent structural attention responses in the backdoor samples.

๐Ÿงญ Getting Start

Coming Soon~

Environment Requirement ๐ŸŒ

T2Ishield has been implemented and tested on Pytorch 2.0.1 with python 3.10.

Clone the repo:

git clone https://github.com/Robin-WZQ/T2IShield
cd T2IShield

We recommend you first use conda to create virtual environment, and install pytorch following official instructions. For example:

conda create -n T2IShield python=3.10 -y
conda activate T2IShield
python -m pip install --upgrade pip
pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118

Then you can install required packages thourgh:

pip install -r requirements.txt

Data Download โฌ‡๏ธ

Dataset

You can download the dataset for training in the backdoor detection and backdoor localization here. By downloading the data, you are agreeing to the terms and conditions of the license. The data structure should be like:

|-- data
    |-- data_detection
        |-- attention maps
        	|-- test
        		|-- rickrolling
        		|-- Villan
        	|-- train
        		|-- rickrolling
        		|-- Villan
        |-- prompts
        	|-- test
        		|-- rickrolling
        		|-- Villan
        	|-- train
         		|-- rickrolling
        		|-- Villan
        |-- all_prompts.txt
    |-- data_localization
        |-- rickrolling
        |-- Villan

Checkpoints

Checkpoints of T2IShield can be download from here. The folder contains:

  • The trained CDA classifier for backdoor detection.
  • backdoored model created by Rickrolling and Villan Diffusion.

๐Ÿƒ๐Ÿผ Running Scripts

Backdoor Detection

  • FTT

    FTT is the training free algorithm, the hyper-parameter (i.e., threshold) is set to 2.5.

    python detect_linear.py
  • CDA

    python detect_reman_lda.py
    python reman_classify.py
    
  • We also provide the visualization script for reproducing the results in our paper:

    Please follow the instruction written in the each file.

    • Assimilation Phenomenon Visualization.ipynb
    • Visulization_CDA.ipynb
    • Visulization_FTT.ipynb

Backdoor Localization

Backdoor Mitigation

๐Ÿ“„ Citation

If you find this project useful in your research, please consider cite:

@inproceedings{Wang2024T2IShield,
  title={T2IShield: Defending Against Backdoors on Text-to-Image Diffusion Models},
  author={Wang, Zhongqi and Zhang, Jie and Shan, Shiguang and Chen, Xilin},
  booktitle={ECCV},
  year={2024},
}

๐Ÿค Feel free to discuss with us privately!

t2ishield's People

Contributors

robin-wzq avatar

Stargazers

 avatar

Watchers

 avatar

t2ishield's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.