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.1.7.tar.gz
.
File metadata
- Download URL: backdoormbti-0.1.7.tar.gz
- Upload date:
- Size: 11.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e699abb0b7dcd41574576dbd691ae54f459bbfe02e0e621296769611797addb |
|
MD5 | 1c9cd38c2180b3c3ad0c2783ede7ff30 |
|
BLAKE2b-256 | 725e0682bc4fe81be7b6de9671faaba40007aa3539327776af031072d56c8d67 |
File details
Details for the file backdoormbti-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: backdoormbti-0.1.7-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0be922e48d388c86088d8ac198330576012a39064f96fd1121904389be06d914 |
|
MD5 | 2f48a6fc22c5c0c23172de4f5d3effa2 |
|
BLAKE2b-256 | 11af2384c779934b06a13c2561d8b96e4cbf5dde442a61050e90679e947405ce |