Package: trojanzoo
TrojanZooNOTE:TrojanZoo requirespython>=3.11,pytorch>=2.0.0andtorchvision>=0.15.0, which must be installed manually. Recommend to usecondato install.This is the code implementation (pytorch) for our paper in EuroS&P 2022:TrojanZoo: Towards Unified, Holistic, and Practical Evaluation of Neural BackdoorsTrojanZoo provides a universal pytorch platform to conduct security researches (especially backdoor attacks/defenses) of image classification in deep learning. It is composed of two packages:trojanzooandtrojanvision.trojanzoocontains abstract classes and utilities, whiletrojanvisioncontains abstract and concrete ones for image classification task.Note: This repository is also maintained to cover the implementation ofour kdd 2020 paperAdvMind: Inferring Adversary Intent of Black-Box Attacksand ccs 2020 paperA Tale of Evil Twins: Adversarial Inputs versus Poisoned ModelsDocumentationWe have documentation available athttps://ain-soph.github.io/trojanzoo.ScreenshotFeaturesColorful and verbose output!Note: enable with--colorfor color and--verbosefor verbose.To open an interactive window with color, usepython - --colorModular design (plug and play)Good code linting supportRegisteryour own moduleto the library.Native Pytorch Outputtrojanzooandtrojanvisionprovides API to generate raw pytorch instances, which makes it flexible to work with nativepytorchand other 3rd party libraries.trojanzoo.datasets.DataSetcan generatetorch.utils.data.Datasetandtorch.utils.data.DataLoadertrojanzoo.models.Modelattribute_modelistorch.nn.Module, attributemodelistorch.nn.DataParallelSpecifically,trojanvision.datasets.ImageSetcan generatetorchvision.datasets.VisionDataset,trojanvision.datasets.ImageFoldercan generatetorchvision.datasets.ImageFolderEnable pytorch native AMP(Automatic Mixed Precision) with--ampfor trainingFlexible Configuration FilesGood help information to check arguments. (-hor--help)Detailed and well-organizedsummary()for each module.Installationpip install trojanzoopip install --upgrade git+https://github.com/ain-soph/trojanzoo.git(HIGHLY RECOMMEND)git clone https://github.com/ain-soph/trojanzoo
pip install -e trojanzooThis could install the github repo as a package but avoid copying files tosite_packages,
so that you can easily keep it updated by doinggit pull.docker pull local0state/trojanzooordocker pull ghcr.io/ain-soph/trojanzooQuick StartYou can use the providedexamplescripts to reproduce the evaluation results in our paper.Note: The program won't save results without--saveTrain a model:e.g.ResNet18onCIFAR10with 95% Accpython./examples/train.py--color--verbose1--datasetcifar10--modelresnet18_comp--lr_scheduler--cutout--grad_clip5.0--saveTest backdoor attack (e.g., BadNet):e.g.BadNetwithResNet18onCIFAR10python./examples/backdoor_attack.py--color--verbose1--pretrained--validate_interval1--datasetcifar10--modelresnet18_comp--attackbadnet--mark_random_init--epochs50--lr0.01--saveTest backdoor defense (e.g., Neural Cleanse):e.g.Neural CleanseagainstBadNetpython./examples/backdoor_defense.py--color--verbose1--pretrained--validate_interval1--datasetcifar10--modelresnet18_comp--attackbadnet--defenseneural_cleanse--mark_random_init--epochs50--lr0.01IMCpython./examples/backdoor_attack.py--color--verbose1--pretrained--validate_interval1--datasetcifar10--modelresnet18_comp--attackimc--mark_random_init--epochs50--lr0.01--saveAdvMind(withattack adaptiveandmodel adaptive)python./examples/adv_defense.py--color--verbose1--pretrained--validate_interval1--datasetcifar10--modelresnet18_comp--attackpgd--defenseadvmind--attack_adapt--defense_adaptDetailed UsageConfiguration file structureAll arguments in the parser are able to set default values in configuration files.If argument values are not set in the config files, we will use the default values of__init__()Parameters Config: (priority ascend order)The higher priority config will override lower priority ones.Within each priority channel,trojanvisionconfigs will overwritetrojanzooPackage Default:/trojanzoo/configs/,/trojanvision/configs/These are package default settings. Please don't modify them.You can use this as a template to set other configs.User Default:~/.trojanzoo/configs/trojanzoo/,~/.trojanzoo/configs/trojanvision/Workspace Default:/configs/trojanzoo/,/configs/trojanvision/Custom Config:--config [config location]CMD parameters:--[parameter] [value]Store path of Dataset, Model, Attack & Defense ResultsModify them in corresponding config files and command-line arguments.Dataset:--data_dir(./data/data)Model:--model_dir(./data/model)Attack:--attack_dir(./data/attack)Defense:--defense_dir(./data/defense)Output Verbose Information:CMD modules:--verbose 1Colorful output:--colortqdm:--tqdmCheck command-line argument usage:--helpAdvMind verbose information:--output [number]Use your DIY Dataset/Model/Attack/DefenseFollow our example to write your DIY class. (CIFAR10,ResNet,IMC,Neural Cleanse)It's necessary to subclass our base class. (Dataset,Model,Attack,Defense)Optional base classes depending on your use case: (ImageSet,ImageFolder,ImageModel)Register your DIY class introjanvisionExample:trojanvision.attacks.class_dict[attack_name]=AttackClassCreate your config files if necessary.No need to modify any codes. Just directly add{attack_name}.yml(.json) in the config directory.Good to go!Todo ListSphinx DocsUnit testLicenseTrojanZoo has a GPL-style license, as found in theLICENSEfile.Cite our paper@InProceedings{pang:2022:eurosp,
      title={TrojanZoo: Towards Unified, Holistic, and Practical Evaluation of Neural Backdoors}, 
      author={Ren Pang and Zheng Zhang and Xiangshan Gao and Zhaohan Xi and Shouling Ji and Peng Cheng and Ting Wang},
      year={2022},
      booktitle={Proceedings of IEEE European Symposium on Security and Privacy (Euro S\&P)},
}

@inproceedings{pang:2020:ccs, 
    title = "{A Tale of Evil Twins: Adversarial Inputs versus Poisoned Models}", 
    author = {Ren Pang and Hua Shen and Xinyang Zhang and Shouling Ji and Yevgeniy Vorobeychik and Xiapu Luo and Alex Liu and Ting Wang}, 
    year = {2020}, 
    booktitle = {Proceedings of ACM SAC Conference on Computer and Communications (CCS)},
}

@inproceedings{pang:2020:kdd, 
    title = "{AdvMind: Inferring Adversary Intent of Black-Box Attacks}", 
    author = {Ren Pang and Xinyang Zhang and Shouling Ji and Xiapu Luo and Ting Wang}, 
    year = {2020}, 
    booktitle = {Proceedings of ACM International Conference on Knowledge Discovery and Data Mining (KDD)},
}