An open-source framework for backdoor learning and defense in multimodal contexts
Project description
BackdoorMBTI
BackdoorMBTI is an open source project expanding the unimodal backdoor learning to a multimodal context. We hope that BackdoorMBTI can facilitate the analysis and development of backdoor defense methods within a multimodal context.
main feature:
- poison dataset generateion
- backdoor model generation
- attack training
- defense training
- backdoor evaluation
The framework:
Task Supported
Task | Dataset | Modality |
---|---|---|
Object Classification | CIFAR10 | Image |
Object Classification | TinyImageNet | Image |
Traffic Sign Recognition | GTSRB | Image |
Facial Recognition | CelebA | Image |
Sentiment Analysis | SST-2 | Text |
Sentiment Analysis | IMDb | Text |
Topic Classification | DBpedia | Text |
Topic Classification | AG’s News | Text |
Speech Command Recognition | SpeechCommands | Audio |
Music Genre Classification | GTZAN | Audio |
Speaker Identification | VoxCeleb1 | Audio |
Backdoor Attacks Supported
Backdoor Defenses Supported
Defense | Modality | Input | Stage | Output | Paper |
---|---|---|---|---|---|
STRIP | Audio,Image and text | backdoor model, clean dataset | post-training | clean dataset | STRIP: A Defence Against Trojan Attacks on Deep Neural Networks |
AC | Audio,Image and text | backdoor model, clean dataset, poison dataset | post-training | clean model, clean datasest | Detecting Backdoor Attacks on Deep Neural Networks by Activation Clustering |
FT | Audio,Image and text | backdoor model, clean dataset | in-training | clean model | Fine-Pruning: Defending Against Backdooring Attacks on Deep Neural Networks. |
FP | Audio,Image and text | backdoor model, clean dataset | post-training | clean model | Fine-Pruning: Defending Against Backdooring Attacks on Deep Neural Networks. |
ABL | Audio,Image and text | backdoor model, poison dataset | in-training | clean model | Anti-Backdoor Learning: Training Clean Models on Poisoned Data |
CLP | Audio,Image and text | backdoor model | post-training | clean model | Data-free Backdoor Removal based on Channel Lipschitzness |
NC | Image | backdoor model, clean dataset | post-training | clean model, trigger pattern | Neural Cleanse: Identifying and Mitigating Backdoor Attacks in Neural Networks |
Installation
To install the virtual environment:
conda create -n bkdmbti python=3.10
conda activate bkdmbti
pip install -r requirements.txt
Quick Start
Download Data
Download the data if it can not be downloaded automatically. Some data download scripts are provided in scripts
folder.
Backdoor Attack
Here we provide an example to quickly start with the attack experiments, and reproduce the BadNets backdoor attack results. We use resnet-18 as the default model, and 0.1 as the default poison ratio.
cd scripts
python atk_train.py --data_type image --dataset cifar10 --attack_name badnet --model resnet18 --pratio 0.1 --num_workers 4 --epochs 100
python atk_train.py --data_type audio --dataset speechcommands --attack_name blend --model audiocnn --pratio 0.1 --num_workers 4 --epochs 100 --add_noise true
python atk_train.py --data_type text --dataset sst2 --attack_name addsent --model bert --pratio 0.1 --num_workers 4 --epochs 100 --mislabel true
Use args --add_noise true
and --mislabel true
to add perturbations to the data. After the experiment, metrics ACC(Accuracy), ASR(Attack Success Rate) and RA(Robustness Accuracy) are collected in attack phase.
To learn more about the attack command, you can run python atk_train.py -h
to see more details.
Backdoor Defense
Here we provide a defense example, it depends on the backdoor model generated in the attack phase, so you should run the corresponding attack experiment before defense phase.
cd scripts
python def_train.py --data_type image --dataset cifar10 --attack_name badnet --pratio 0.1 --defense_name finetune --num_workers 4 --epochs 10
python def_train.py --data_type audio --dataset speechcommands --attack_name blend --model audiocnn --pratio 0.1 --defense_name fineprune --num_workers 4 --epochs 1 --add_noise true
python def_train.py --data_type text --dataset sst2 --attack_name addsent --model bert --pratio 0.1 --defense_name strip --num_workers 4 --epochs 1 --mislabel true
To learn more about the attack command, you can run python def_train.py -h
to see more details.
In defense phase, detection accuracy will be collected if the defense is a detection method, and then the sanitized dataset will be used to retrain the model. ACC, ASR and RA metrics are collected after retraining.
Results
More results can be found in: results.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file backdoormbti-0.2.2.tar.gz
.
File metadata
- Download URL: backdoormbti-0.2.2.tar.gz
- Upload date:
- Size: 5.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 889ff7b5b0588d82f6719a3cdfc2afce39fd6baa38791be0078cff1ef66ebeac |
|
MD5 | 0bcbbb5bfdd5317ed3464a9833484aeb |
|
BLAKE2b-256 | 44434b3b50bfede1c9da8b4a48682a1c484c61dc98b8351407714aca47d61690 |
File details
Details for the file backdoormbti-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: backdoormbti-0.2.2-py3-none-any.whl
- Upload date:
- Size: 5.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d98ee82558f6c4cf0849c1f70f3bf587fef158195fb098789a62999c75537849 |
|
MD5 | bb3a237b509fcd2be129931e76c9cea5 |
|
BLAKE2b-256 | 505a6f8ab1bffe775c8caba196711d23fb20c238722da94cf357a1155b58c969 |