Home

Awesome

<img src="resource/pyg_logo.png" style="height: 60px;" align="right">

BackdoorBench: a comprehensive benchmark of backdoor attack and defense methods

Pytorch 1.11.0 License: CC BY-NC 4.0 Release .20

<p align="center"> <br> <a href="http://backdoorbench.com" target="_blank"> Website </a > • <a href="https://openreview.net/pdf?id=31_U7n18gM7"> Paper </a > • <a href="http://backdoorbench.com/doc/index"> Doc </a > • <a href="http://backdoorbench.com/leader_cifar10"> Leaderboard </a > <br> <br> </p >

BackdoorBench is a comprehensive benchmark of backdoor learning, which studies the adversarial vulnerablity of deep learning models in the training stage. It aims to provide easy implementations of mainstream backdoor attack and defense methods.

❗Model and Data Updates

We disclose the backdoor model we used and the corresponding backdoor attack image in the link below. Each zip file contains the following things:

If you want to use the backdoor model, you can download the zip file and unzip in your own workspace. Then you can use the function load_attack_result in the file save_load_attack.py to load the backdoor model, the poisoned train data and the poisoned test data.

Backdoor Model

✅ Since the previously shared document was inaccessible, we have now re-shared the backdoor model, and the link has been updated for your convenience. You can directly download the model using the link provided above.

❗V2.2 Updates

Methods:

  1. Defense :Add 9 new defense/detection methods: STRIP, BEATRIX, SCAN, SPECTRE, SS, AGPD, SentiNet, STRIP, TeCo (Totally 28 defense/detection methods now).

❗ For V2.0 please check here

❗ For V1.0 please check here

<font size=5><center><b> Table of Contents </b> </center></font>


Features

<a href="#top">[Back to top]</a>

BackdoorBench has the following features:

⭐️ Methods:

⭐️ Datasets: CIFAR-10, CIFAR-100, GTSRB, Tiny ImageNet

⭐️ Models: PreAct-Resnet18, VGG19_bn, ConvNeXT_tiny, ViT_B_16, VGG19, DenseNet-161, MobileNetV3-Large, EfficientNet-B3

⭐️ Learboard: We provide a public leaderboard of evaluating all backdoor attacks against all defense methods.

BackdoorBench will be continuously updated to track the lastest advances of backddor learning. The implementations of more backdoor methods, as well as their evaluations are on the way. You are welcome to contribute your backdoor methods to BackdoorBench.

Installation

<a href="#top">[Back to top]</a>

You can run the following script to configure the necessary environment.

git clone git@github.com:SCLBD/BackdoorBench.git
cd BackdoorBench
conda create -n backdoorbench python=3.8
conda activate backdoorbench
sh ./sh/install.sh
sh ./sh/init_folders.sh

You can also download backdoorbench by pip.

pip install -i https://test.pypi.org/simple/ backdoorbench

The pip version of backdoorbench can be viewed at this link

Quick Start

Attack

<a href="#top">[Back to top]</a>

This is a example for BadNets

  1. Generate trigger

If you want to change the trigger for BadNets, you should go to the ./resource/badnet, and follow the readme there to generate new trigger pattern.

python ./resource/badnet/generate_white_square.py --image_size 32 --square_size 3 --distance_to_right 0 --distance_to_bottom 0 --output_path ./resource/badnet/trigger_image.png

Note that for data-poisoning-based attacks (BadNets, Blended, Label Consistent, Low Frequency, SSBA). Our scripts in ./attack are just for training, they do not include the data generation process.(Because they are time-comsuming, and we do not want to waste your time.) You should go to the ./resource folder to generate the trigger for training.

  1. Backdoor training
python ./attack/badnet.py --yaml_path ../config/attack/prototype/cifar10.yaml --patch_mask_path ../resource/badnet/trigger_image.png  --save_folder_name badnet_0_1

After attack you will get a folder with all files saved in ./record/<folder name in record>, including attack_result.pt for attack model and backdoored data, which will be used by following defense methods. If you want to change the args, you can both specify them in command line and in corresponding YAML config file (eg. default.yaml).(They are the defaults we used if no args are specified in command line.) The detailed descriptions for each attack may be put into the add_args function in each script.

Note that for some attacks, they may need pretrained models to generate backdoored data. For your ease, we provide various data/trigger/models we generated in google drive. You can download them at here (including clean_model files, ssba,lf,lc generated triggers/samples for you convenience.)

Defense

<a href="#top">[Back to top]</a>

This is a demo script of running abl defense on cifar-10 for badnet attack. Before defense you need to run badnet attack on cifar-10 at first. Then you use the folder name as result_file.

python ./defense/abl.py --result_file badnet_0_1 --yaml_path ./config/defense/abl/cifar10.yaml --dataset cifar10

If you want to change the args, you can both specify them in command line and in corresponding YAML config file (eg. default.yaml).(They are the defaults we used if no args are specified in command line.) The detailed descriptions for each attack may be put into the add_args function in each script.

Supported attacks

<a href="#top">[Back to top]</a>

File namePaper
BadNetsbadnet.pyBadNets: Identifying Vulnerabilities in the Machine Learning Model Supply Chain IEEE Access 2019
Blendedblended.pyTargeted Backdoor Attacks on Deep Learning Systems Using Data Poisoning Arxiv 2017
Blindblind.pyBlind Backdoors in Deep Learning Models USENIX 2021
BPPbpp.pyBppAttack: Stealthy and Efficient Trojan Attacks against Deep Neural Networks via Image Quantization and Contrastive Adversarial Learning CVPR 2022
CTRLctrl.pyAn Embarrassingly Simple Backdoor Attack on Self-supervised Learning ICCV 2023
FTrojanftrojann.pyAn Invisible Black-box Backdoor Attack through Frequency Domain ECCV 2022
Input-awareinputaware.pyInput-Aware Dynamic Backdoor Attack NeurIPS 2020
Label Consistentlc.pyLabel-Consistent Backdoor Attacks Arxiv 2019
Low Frequencylf.pyRethinking the Backdoor Attacks’ Triggers: A Frequency Perspective ICCV2021
LIRAlira.pyLIRA: Learnable, Imperceptible and Robust Backdoor Attacks ICCV 2021
PoisonInkpoison_ink.pyPoison ink: Robust and invisible backdoor attack IEEE Transactions on Image Processing, 2022
ReFoolrefool.pyReflection Backdoor: A Natural Backdoor Attack on Deep Neural Networks ECCV 2020
SIGsig.pyA new backdoor attack in cnns by training set corruption ICIP 2019
SSBAssba.pyInvisible Backdoor Attack with Sample-Specific Triggers ICCV 2021
TrojanNNtrojannn.pyTrojaning Attack on Neural Networks NDSS 2018
WaNetwanet.pyWaNet -- Imperceptible Warping-Based Backdoor Attack ICLR 2021

Supported defenses

<a href="#top">[Back to top]</a>

File namePaper
ABLabl.pyAnti-Backdoor Learning: Training Clean Models on Poisoned Data NeurIPS 2021
ACac.pyDetecting Backdoor Attacks on Deep Neural Networks by Activation Clustering ceur-ws 2018
ANPanp.pyAdversarial Neuron Pruning Purifies Backdoored Deep Models NeurIPS 2021
CLPclp.pyData-free backdoor removal based on channel lipschitzness ECCV 2022
D-BR,D-STd-br.py d-st.pyEffective backdoor defense by exploiting sensitivity of poisoned samples NeurIPS 2022
DBDdbd.pyBackdoor Defense Via Decoupling The Training Process ICLR 2022
EP,BNPep.py bnp.pyPre-activation Distributions Expose Backdoor Neurons NeurIPS 2022
FPfp.pyFine-Pruning: Defending Against Backdooring Attacks on Deep Neural Networks RAID 2018
FTft.pystandard fine-tuning
FT-SAMft-sam.pyEnhancing Fine-Tuning Based Backdoor Defense with Sharpness-Aware Minimization ICCV 2023
I-BAUi-bau.pyAdversarial unlearning of backdoors via implicit hypergradient ICLR 2022
MCRmcr.pyBridging mode connectivity in loss landscapes and adversarial robustness ICLR 2020
NABnab.pyBeating Backdoor Attack at Its Own Game ICCV 2023
NADnad.pyNeural Attention Distillation: Erasing Backdoor Triggers From Deep Neural Networks ICLR 2021
NCnc.pyNeural Cleanse: Identifying And Mitigating Backdoor Attacks In Neural Networks, IEEE S&P 2019
NPDnpd.pyNeural polarizer: A lightweight and effective backdoor defense via purifying poisoned features NeurIPS 2023
RNPrnp.pyReconstructive Neuron Pruning for Backdoor Defense NeurIPS 2021
SAUsau.pyShared adversarial unlearning: Backdoor mitigation by unlearning shared adversarial examples NeurIPS 2023
SSspectral.pySpectral Signatures in Backdoor Attacks NeurIPS 2018

Supported Detection

<a href="#top">[Back to top]</a>

pretrain

File namePaper
STRIPstrip.pySTRIP: A Defence Against Trojan Attacks on Deep Neural Networks ACSAC 2019
BEATRIXbeatrix.pyThe Beatrix Resurrections: Robust Backdoor Detection via Gram Matrices NDSS 2023
SCANscan.pyDemon in the Variant: Statistical Analysis of DNNs for Robust Backdoor Contamination Detection USENIX Security 21
SPECTREspectre.pySPECTRE: Defending Against Backdoor Attacks Using Robust Statistics ICML 2020
SSspectral.pySpectral Signatures in Backdoor Attacks NeurIPS 2018
AGPDagpd.pyActivation Gradient based Poisoned Sample Detection Against Backdoor Attacks arXiv

inference-time

File namePaper
SentiNetsentinet.pySentinet: Detecting localized universal attacks against deep learning systems 2020 IEEE Security and Privacy Workshops (SPW)
STRIPstrip.pySTRIP: A Defence Against Trojan Attacks on Deep Neural Networks ACSAC 2019
TeCoteco.pyDetecting Backdoors During the Inference Stage Based on Corruption Robustness Consistency CVPR 2023

Model and Data Downloading

<a href="#top">[Back to top]</a>

We disclose the backdoor model we used and the corresponding backdoor attack image in the link below. Each zip file contains the following things:

If you want to use the backdoor model, you can download the zip file and unzip in your own workspace. Then you can use the function load_attack_result in the file save_load_attack.py to load the backdoor model, the poisoned train data and the poisoned test data.

We provide the whole sharepoint link at Backdoor Model for you to download the data and model.

Analysis Tools

<a href="#top">[Back to top]</a>

File nameMethodCategory
visual_tsne.pyT-SNE, the T-SNE of featuresData Analysis
visual_umap.pyUMAP, the UMAP of featuresData Analysis
visual_quality.pyImage Quality, evaluating the given results using some image quality metricsData Analysis
visual_na.pyNeuron Activation, the activation value of a given layer of NeuronsModel Analysis
visual_shap.pyShapely Value, the Shapely Value for given inputs and a given layerModel Analysis
visual_gradcam.pyGrad-CAM, the Grad-CAM for given inputs and a given layerModel Analysis
visualize_fre.pyFrequency Map, the Frequency Saliency Map for given inputs and a given layerModel Analysis
visual_act.pyActivated Image, the top images who activate the given layer of Neurons mostModel Analysis
visual_fv.pyFeature Visualization, the synthetic images which activate the given NeuronsModel Analysis
visual_fm.pyFeature Map, the output of a given layer of CNNs for a given imageModel Analysis
visual_actdist.pyActivation Distribution, the class distribution of Top-k images which activate the Neuron mostModel Analysis
visual_tac.pyTrigger Activation Change, the average (absolute) activation change between images with and without triggersModel Analysis
visual_lips.pyLipschitz Constant, the lipschitz constant of each neuronModel Analysis
visual_landscape.pyLoss Landscape, the loss landscape of given results with two random directionsModel Analysis
visual_network.pyNetwork Structure, the Network Structure of given modelModel Analysis
visual_hessian.pyEigenvalues of Hessian, the dense plot of hessian matrix for a batch of dataModel Analysis
visual_metric.pyMetrics, evaluating the given results using some metricsEvaluation
visual_cm.pyConfusion Matrix

Citation

<a href="#top">[Back to top]</a>

If interested, you can read our recent works about backdoor learning, and more works about trustworthy AI can be found here.

@inproceedings{backdoorbench,
  title={BackdoorBench: A Comprehensive Benchmark of Backdoor Learning},
  author={Wu, Baoyuan and Chen, Hongrui and Zhang, Mingda and Zhu, Zihao and Wei, Shaokui and Yuan, Danni and Shen, Chao},
  booktitle={Thirty-sixth Conference on Neural Information Processing Systems Datasets and Benchmarks Track},
  year={2022}
}

@article{wu2023adversarial,
  title={Adversarial Machine Learning: A Systematic Survey of Backdoor Attack, Weight Attack and Adversarial Example},
  author={Wu, Baoyuan and Liu, Li and Zhu, Zihao and Liu, Qingshan and He, Zhaofeng and Lyu, Siwei},
  journal={arXiv preprint arXiv:2302.09457},
  year={2023}
}

@article{wu2023defenses,
  title={Defenses in Adversarial Machine Learning: A Survey},
  author={Wu, Baoyuan and Wei, Shaokui and Zhu, Mingli and Zheng, Meixi and Zhu, Zihao and Zhang, Mingda and Chen, Hongrui and Yuan, Danni and Liu, Li and Liu, Qingshan},
  journal={arXiv preprint arXiv:2312.08890},
  year={2023}
}

@inproceedings{zhu2024breaking,
  title={Breaking the False Sense of Security in Backdoor Defense through Re-Activation Attack},
  author={Zhu, Mingli and Liang, Siyuan and Wu, Baoyuan},
  booktitle = {Advances in Neural Information Processing Systems},
  year={2024}
}

@inproceedings{wei2024mitigating,
  title={Mitigating Backdoor Attack by Injecting Proactive Defensive Backdoor},
  author={Wei, Shaokui and Zha, Hongyuan and Wu, Baoyuan},
  booktitle = {Advances in Neural Information Processing Systems},
  year={2024}
}

@article{gao2023imperceptible,
  title={Imperceptible and robust backdoor attack in 3d point cloud},
  author={Gao, Kuofeng and Bai, Jiawang and Wu, Baoyuan and Ya, Mengxi and Xia, Shu-Tao},
  journal={IEEE Transactions on Information Forensics and Security},
  volume={19},
  pages={1267--1282},
  year={2023},
  publisher={IEEE}
}

@article{cheng2023tat,
  title={TAT: Targeted backdoor attacks against visual object tracking},
  author={Cheng, Ziyi and Wu, Baoyuan and Zhang, Zhenya and Zhao, Jianjun},
  journal={Pattern Recognition},
  volume={142},
  pages={109629},
  year={2023},
  publisher={Elsevier}
}

@inproceedings{sensitivity-backdoor-defense-nips2022,
 title = {Effective Backdoor Defense by Exploiting Sensitivity of Poisoned Samples},
 author = {Chen, Weixin and Wu, Baoyuan and Wang, Haoqian},
 booktitle = {Advances in Neural Information Processing Systems},
 volume = {35},
 pages = {9727--9737},
 year = {2022}
}

@inproceedings{dbd-backdoor-defense-iclr2022,
    title={Backdoor Defense via Decoupling the Training Process},
    author={Huang, Kunzhe and Li, Yiming and Wu, Baoyuan and Qin, Zhan and Ren, Kui},
    booktitle={International Conference on Learning Representations},
    year={2022}
}

@inproceedings{ssba-backdoor-attack-iccv2021,
    title={Invisible backdoor attack with sample-specific triggers},
    author={Li, Yuezun and Li, Yiming and Wu, Baoyuan and Li, Longkang and He, Ran and Lyu, Siwei},
    booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
    pages={16463--16472},
    year={2021}
}

@article{zhu2023vdc,
  title={VDC: Versatile Data Cleanser for Detecting Dirty Samples via Visual-Linguistic Inconsistency},
  author={Zhu, Zihao and Zhang, Mingda and Wei, Shaokui and Wu, Bingzhe and Wu, Baoyuan},
  journal={arXiv preprint arXiv:2309.16211},
  year={2023}
}

@article{zhu2023boosting,
  title={Boosting backdoor attack with a learnable poisoning sample selection strategy},
  author={Zhu, Zihao and Zhang, Mingda and Wei, Shaokui and Shen, Li and Fan, Yanbo and Wu, Baoyuan},
  journal={arXiv preprint arXiv:2307.07328},
  year={2023}
}

@article{wang2023robust,
  title={Robust Backdoor Attack with Visible, Semantic, Sample-Specific, and Compatible Triggers},
  author={Wang, Ruotong and Chen, Hongrui and Zhu, Zihao and Liu, Li and Zhang, Yong and Fan, Yanbo and Wu, Baoyuan},
  journal={arXiv preprint arXiv:2306.00816},
  year={2023}
}

@article{yuan2023activation,
  title={Activation Gradient based Poisoned Sample Detection Against Backdoor Attacks},
  author={Yuan, Danni and Wei, Shaokui and Zhang, Mingda and Liu, Li and Wu, Baoyuan},
  journal={arXiv preprint arXiv:2312.06230},
  year={2023}
}

@article{wei2023shared,
  title={Shared adversarial unlearning: Backdoor mitigation by unlearning shared adversarial examples},
  author={Wei, Shaokui and Zhang, Mingda and Zha, Hongyuan and Wu, Baoyuan},
  journal={arXiv preprint arXiv:2307.10562},
  year={2023}
}

@inproceedings{
    zhu2023neural,
    title={Neural Polarizer: A Lightweight and Effective Backdoor Defense via Purifying Poisoned Features},
    author={Mingli Zhu and Shaokui Wei and Hongyuan Zha and Baoyuan Wu},
    booktitle={Thirty-seventh Conference on Neural Information Processing Systems},
    year={2023},
    url={https://openreview.net/forum?id=VFhN15Vlkj}
}

@InProceedings{Zhu_2023_ICCV,
    author    = {Zhu, Mingli and Wei, Shaokui and Shen, Li and Fan, Yanbo and Wu, Baoyuan},
    title     = {Enhancing Fine-Tuning Based Backdoor Defense with Sharpness-Aware Minimization},
    booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
    month     = {October},
    year      = {2023},
    pages     = {4466-4477}
}

@article{liang2023badclip,
  title={BadCLIP: Dual-Embedding Guided Backdoor Attack on Multimodal Contrastive Learning},
  author={Liang, Siyuan and Zhu, Mingli and Liu, Aishan and Wu, Baoyuan and Cao, Xiaochun and Chang, Ee-Chien},
  journal={arXiv preprint arXiv:2311.12075},
  year={2023}
}

Copyright

<a href="#top">[Back to top]</a>

This repository is licensed by The Chinese University of Hong Kong, Shenzhen under Creative Commons Attribution-NonCommercial 4.0 International Public License (identified as CC BY-NC-4.0 in SPDX). More details about the license could be found in LICENSE.

This project is built by the Longgang District Key Laboratory of Intelligent Digital Economy Security (iDES) at The Chinese University of Hong Kong, Shenzhen, directed by Professor Baoyuan Wu. iDES focuses on research of trustworthy AI, including backdoor learning, adversarial examples, federated learning, fairness, etc.

If any suggestion or comment, please contact us at wubaoyuan@cuhk.edu.cn.