attackbenchlib 1.0.0a9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. attackbenchlib-1.0.0a9/.gitignore +162 -0
  2. attackbenchlib-1.0.0a9/.readthedocs.yaml +43 -0
  3. attackbenchlib-1.0.0a9/PKG-INFO +256 -0
  4. attackbenchlib-1.0.0a9/README.md +185 -0
  5. attackbenchlib-1.0.0a9/_static/assets/logos/FundedbytheEU.png +0 -0
  6. attackbenchlib-1.0.0a9/_static/assets/logos/elsa.jpg +0 -0
  7. attackbenchlib-1.0.0a9/_static/assets/logos/sec4AI4sec.png +0 -0
  8. attackbenchlib-1.0.0a9/attackbench/__init__.py +180 -0
  9. attackbenchlib-1.0.0a9/attackbench/adv_lib_sub.py +239 -0
  10. attackbenchlib-1.0.0a9/attackbench/attacks/README.md +65 -0
  11. attackbenchlib-1.0.0a9/attackbench/attacks/__init__.py +17 -0
  12. attackbenchlib-1.0.0a9/attackbench/attacks/adv_lib/__init__.py +0 -0
  13. attackbenchlib-1.0.0a9/attackbench/attacks/adv_lib/configs.py +415 -0
  14. attackbenchlib-1.0.0a9/attackbench/attacks/adv_lib/wrapper.py +66 -0
  15. attackbenchlib-1.0.0a9/attackbench/attacks/art/__init__.py +0 -0
  16. attackbenchlib-1.0.0a9/attackbench/attacks/art/configs.py +276 -0
  17. attackbenchlib-1.0.0a9/attackbench/attacks/art/wrapper.py +86 -0
  18. attackbenchlib-1.0.0a9/attackbench/attacks/bomn.py +262 -0
  19. attackbenchlib-1.0.0a9/attackbench/attacks/cleverhans/__init__.py +0 -0
  20. attackbenchlib-1.0.0a9/attackbench/attacks/cleverhans/configs.py +137 -0
  21. attackbenchlib-1.0.0a9/attackbench/attacks/cleverhans/wrapper.py +75 -0
  22. attackbenchlib-1.0.0a9/attackbench/attacks/deeprobust/__init__.py +0 -0
  23. attackbenchlib-1.0.0a9/attackbench/attacks/deeprobust/configs.py +114 -0
  24. attackbenchlib-1.0.0a9/attackbench/attacks/deeprobust/wrapper.py +82 -0
  25. attackbenchlib-1.0.0a9/attackbench/attacks/foolbox/__init__.py +0 -0
  26. attackbenchlib-1.0.0a9/attackbench/attacks/foolbox/bb_adv_init.py +20 -0
  27. attackbenchlib-1.0.0a9/attackbench/attacks/foolbox/configs.py +294 -0
  28. attackbenchlib-1.0.0a9/attackbench/attacks/foolbox/wrapper.py +83 -0
  29. attackbenchlib-1.0.0a9/attackbench/attacks/original/__init__.py +0 -0
  30. attackbenchlib-1.0.0a9/attackbench/attacks/original/auto_pgd.py +773 -0
  31. attackbenchlib-1.0.0a9/attackbench/attacks/original/configs.py +288 -0
  32. attackbenchlib-1.0.0a9/attackbench/attacks/original/deepfool.py +103 -0
  33. attackbenchlib-1.0.0a9/attackbench/attacks/original/fast_adaptive_boundary.py +624 -0
  34. attackbenchlib-1.0.0a9/attackbench/attacks/original/fast_minimum_norm.py +431 -0
  35. attackbenchlib-1.0.0a9/attackbench/attacks/original/pgd_lzero.py +213 -0
  36. attackbenchlib-1.0.0a9/attackbench/attacks/original/sigma_zero.py +141 -0
  37. attackbenchlib-1.0.0a9/attackbench/attacks/original/superdeepfool.py +167 -0
  38. attackbenchlib-1.0.0a9/attackbench/attacks/original/trust_region.py +263 -0
  39. attackbenchlib-1.0.0a9/attackbench/attacks/registry.py +321 -0
  40. attackbenchlib-1.0.0a9/attackbench/attacks/torchattacks/__init__.py +0 -0
  41. attackbenchlib-1.0.0a9/attackbench/attacks/torchattacks/configs.py +209 -0
  42. attackbenchlib-1.0.0a9/attackbench/attacks/torchattacks/wrapper.py +69 -0
  43. attackbenchlib-1.0.0a9/attackbench/attacks.json +122 -0
  44. attackbenchlib-1.0.0a9/attackbench/compat.py +14 -0
  45. attackbenchlib-1.0.0a9/attackbench/custom_components.py +310 -0
  46. attackbenchlib-1.0.0a9/attackbench/datasets/__init__.py +0 -0
  47. attackbenchlib-1.0.0a9/attackbench/datasets/imagenet.py +79 -0
  48. attackbenchlib-1.0.0a9/attackbench/datasets/registry.py +75 -0
  49. attackbenchlib-1.0.0a9/attackbench/datasets/subsets/__init__.py +0 -0
  50. attackbenchlib-1.0.0a9/attackbench/datasets/subsets/imagenet-5000-val.txt +5000 -0
  51. attackbenchlib-1.0.0a9/attackbench/metrics/__init__.py +90 -0
  52. attackbenchlib-1.0.0a9/attackbench/metrics/analysis.py +245 -0
  53. attackbenchlib-1.0.0a9/attackbench/metrics/curves.py +89 -0
  54. attackbenchlib-1.0.0a9/attackbench/metrics/distances.py +134 -0
  55. attackbenchlib-1.0.0a9/attackbench/metrics/ensemble.py +90 -0
  56. attackbenchlib-1.0.0a9/attackbench/metrics/global_optimality.py +320 -0
  57. attackbenchlib-1.0.0a9/attackbench/metrics/optimality.py +254 -0
  58. attackbenchlib-1.0.0a9/attackbench/metrics/storage.py +140 -0
  59. attackbenchlib-1.0.0a9/attackbench/models/__init__.py +0 -0
  60. attackbenchlib-1.0.0a9/attackbench/models/benchmodel_wrapper.py +268 -0
  61. attackbenchlib-1.0.0a9/attackbench/models/mnist.py +51 -0
  62. attackbenchlib-1.0.0a9/attackbench/models/original/__init__.py +0 -0
  63. attackbenchlib-1.0.0a9/attackbench/models/original/stutz2020/__init__.py +0 -0
  64. attackbenchlib-1.0.0a9/attackbench/models/original/stutz2020/ccat.py +44 -0
  65. attackbenchlib-1.0.0a9/attackbench/models/original/stutz2020/classifier.py +169 -0
  66. attackbenchlib-1.0.0a9/attackbench/models/original/stutz2020/resnet.py +96 -0
  67. attackbenchlib-1.0.0a9/attackbench/models/original/stutz2020/resnet_block.py +79 -0
  68. attackbenchlib-1.0.0a9/attackbench/models/original/stutz2020/torch.py +160 -0
  69. attackbenchlib-1.0.0a9/attackbench/models/original/utils.py +15 -0
  70. attackbenchlib-1.0.0a9/attackbench/models/original/wang2023/__init__.py +0 -0
  71. attackbenchlib-1.0.0a9/attackbench/models/original/wang2023/dm_adv_training.py +69 -0
  72. attackbenchlib-1.0.0a9/attackbench/models/original/wang2023/wideresnetwithswish.py +199 -0
  73. attackbenchlib-1.0.0a9/attackbench/models/original/xiao2020/__init__.py +0 -0
  74. attackbenchlib-1.0.0a9/attackbench/models/original/xiao2020/kwta.py +23 -0
  75. attackbenchlib-1.0.0a9/attackbench/models/original/xiao2020/models.py +516 -0
  76. attackbenchlib-1.0.0a9/attackbench/models/original/zhang2020/__init__.py +0 -0
  77. attackbenchlib-1.0.0a9/attackbench/models/original/zhang2020/crown.py +49 -0
  78. attackbenchlib-1.0.0a9/attackbench/models/original/zhang2020/model_defs_gowal.py +90 -0
  79. attackbenchlib-1.0.0a9/attackbench/models/original/zhang2020/utils.py +23 -0
  80. attackbenchlib-1.0.0a9/attackbench/models/registry.py +228 -0
  81. attackbenchlib-1.0.0a9/attackbench/preconfigured.py +114 -0
  82. attackbenchlib-1.0.0a9/attackbench/run.py +414 -0
  83. attackbenchlib-1.0.0a9/attackbench/utils.py +7 -0
  84. attackbenchlib-1.0.0a9/attackbench/wandb/__init__.py +31 -0
  85. attackbenchlib-1.0.0a9/attackbench/wandb/manager.py +817 -0
  86. attackbenchlib-1.0.0a9/attackbench/wandb/utils.py +187 -0
  87. attackbenchlib-1.0.0a9/attackbenchlib.egg-info/PKG-INFO +256 -0
  88. attackbenchlib-1.0.0a9/attackbenchlib.egg-info/SOURCES.txt +111 -0
  89. attackbenchlib-1.0.0a9/attackbenchlib.egg-info/dependency_links.txt +1 -0
  90. attackbenchlib-1.0.0a9/attackbenchlib.egg-info/entry_points.txt +3 -0
  91. attackbenchlib-1.0.0a9/attackbenchlib.egg-info/requires.txt +64 -0
  92. attackbenchlib-1.0.0a9/attackbenchlib.egg-info/top_level.txt +1 -0
  93. attackbenchlib-1.0.0a9/docs/.gitignore +6 -0
  94. attackbenchlib-1.0.0a9/docs/Makefile +20 -0
  95. attackbenchlib-1.0.0a9/docs/README.md +162 -0
  96. attackbenchlib-1.0.0a9/docs/api/analysis.rst +41 -0
  97. attackbenchlib-1.0.0a9/docs/api/attacks.rst +36 -0
  98. attackbenchlib-1.0.0a9/docs/api/datasets.rst +9 -0
  99. attackbenchlib-1.0.0a9/docs/api/index.rst +24 -0
  100. attackbenchlib-1.0.0a9/docs/api/metrics.rst +9 -0
  101. attackbenchlib-1.0.0a9/docs/api/models.rst +20 -0
  102. attackbenchlib-1.0.0a9/docs/architecture.rst +226 -0
  103. attackbenchlib-1.0.0a9/docs/conf.py +171 -0
  104. attackbenchlib-1.0.0a9/docs/contributing.rst +100 -0
  105. attackbenchlib-1.0.0a9/docs/examples.rst +368 -0
  106. attackbenchlib-1.0.0a9/docs/faq.rst +307 -0
  107. attackbenchlib-1.0.0a9/docs/index.rst +96 -0
  108. attackbenchlib-1.0.0a9/docs/installation.rst +109 -0
  109. attackbenchlib-1.0.0a9/docs/optimality.rst +209 -0
  110. attackbenchlib-1.0.0a9/docs/quickstart.rst +181 -0
  111. attackbenchlib-1.0.0a9/docs/requirements.txt +12 -0
  112. attackbenchlib-1.0.0a9/pyproject.toml +119 -0
  113. attackbenchlib-1.0.0a9/setup.cfg +4 -0
@@ -0,0 +1,162 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ .DS_Store
7
+ # Pycharm
8
+ .idea/
9
+
10
+ # Model Zoo
11
+ *.pth
12
+
13
+ # C extensions
14
+ *.so
15
+ *.pdf
16
+
17
+ # Distribution / packaging
18
+ .Python
19
+ build/
20
+ develop-eggs/
21
+ dist/
22
+ downloads/
23
+ eggs/
24
+ .eggs/
25
+ lib/
26
+ lib64/
27
+ parts/
28
+ sdist/
29
+ var/
30
+ wheels/
31
+ pip-wheel-metadata/
32
+ share/python-wheels/
33
+ *.egg-info/
34
+ .installed.cfg
35
+ *.egg
36
+ MANIFEST
37
+
38
+ # PyInstaller
39
+ # Usually these files are written by a python script from a template
40
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
41
+ *.manifest
42
+ *.spec
43
+
44
+ # Installer logs
45
+ pip-log.txt
46
+ pip-delete-this-directory.txt
47
+
48
+ # Unit test / coverage reports
49
+ htmlcov/
50
+ .tox/
51
+ .nox/
52
+ .coverage
53
+ .coverage.*
54
+ .cache
55
+ nosetests.xml
56
+ coverage.xml
57
+ *.cover
58
+ *.py,cover
59
+ .hypothesis/
60
+ .pytest_cache/
61
+
62
+ # Translations
63
+ *.mo
64
+ *.pot
65
+
66
+ # Django stuff:
67
+ *.log
68
+ local_settings.py
69
+ db.sqlite3
70
+ db.sqlite3-journal
71
+
72
+ # Flask stuff:
73
+ instance/
74
+ .webassets-cache
75
+
76
+ # Scrapy stuff:
77
+ .scrapy
78
+
79
+ # Sphinx documentation
80
+ docs/_build/
81
+ docs/_autosummary/
82
+ docs/.doctrees/
83
+ *.doctree
84
+
85
+ # PyBuilder
86
+ target/
87
+
88
+ # Jupyter Notebook
89
+ .ipynb_checkpoints
90
+
91
+ # IPython
92
+ profile_default/
93
+ ipython_config.py
94
+
95
+ # pyenv
96
+ .python-version
97
+
98
+ # pipenv
99
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
100
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
101
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
102
+ # install all needed dependencies.
103
+ #Pipfile.lock
104
+
105
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
106
+ __pypackages__/
107
+
108
+ # Celery stuff
109
+ celerybeat-schedule
110
+ celerybeat.pid
111
+
112
+ # SageMath parsed files
113
+ *.sage.py
114
+
115
+ # Environments
116
+ .env
117
+ .venv
118
+ env/
119
+ venv/
120
+ ENV/
121
+ env.bak/
122
+ venv.bak/
123
+
124
+ # Spyder project settings
125
+ .spyderproject
126
+ .spyproject
127
+
128
+ # Rope project settings
129
+ .ropeproject
130
+
131
+ # mkdocs documentation
132
+ /site
133
+
134
+ # mypy
135
+ .mypy_cache/
136
+ .dmypy.json
137
+ dmypy.json
138
+
139
+ # Pyre type checker
140
+ .pyre/
141
+
142
+ # resources folders
143
+ /data/
144
+ /models/
145
+
146
+ # test notebooks
147
+ *.ipynb
148
+
149
+ # DB stuff
150
+ /wandb/
151
+
152
+ #precompiled distances and cache
153
+ /cache/
154
+
155
+ #experiments and test results
156
+ /bomn_results/
157
+ /results_envelope/
158
+ /scripts/private_scripts/
159
+
160
+ # local configuration
161
+ /compiled/
162
+ /exp_configs/
@@ -0,0 +1,43 @@
1
+ # Read the Docs configuration file for AttackBench
2
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
+
4
+ # Required
5
+ version: 2
6
+
7
+ # Set the OS, Python version and other tools you might need
8
+ build:
9
+ os: ubuntu-22.04
10
+ tools:
11
+ python: "3.9"
12
+ jobs:
13
+ post_checkout:
14
+ # Cancel building pull requests when a new commit is pushed
15
+ - |
16
+ if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git show -s --format=%B $READTHEDOCS_GIT_COMMIT_HASH | grep -q "\[skip rtd\]";
17
+ then
18
+ echo "Skipping RTD build as requested in commit message";
19
+ exit 183;
20
+ fi
21
+
22
+ # Build documentation in the "docs/" directory with Sphinx
23
+ sphinx:
24
+ configuration: docs/conf.py
25
+ builder: html
26
+ fail_on_warning: false
27
+
28
+ # Optionally build your docs in additional formats such as PDF
29
+ # Disabled for now to avoid build issues
30
+ # formats:
31
+ # - pdf
32
+ # - epub
33
+
34
+ # Python configuration
35
+ python:
36
+ install:
37
+ # Install the package in editable mode (for importing in docs)
38
+ - method: pip
39
+ path: .
40
+ extra_requirements:
41
+ - docs
42
+ # Install documentation requirements
43
+ - requirements: docs/requirements.txt
@@ -0,0 +1,256 @@
1
+ Metadata-Version: 2.4
2
+ Name: attackbenchlib
3
+ Version: 1.0.0a9
4
+ Summary: A Python package for benchmarking adversarial attacks and defenses.
5
+ Author-email: Antonio Cinà <antonio.cina@unige.it>, Riccardo Trebiani <richitrebbia@gmail.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3.9
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: <3.13,>=3.9
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: torch>=2.4
15
+ Requires-Dist: torchvision>=0.19
16
+ Requires-Dist: matplotlib>=3.5.1
17
+ Requires-Dist: pandas>=1.4.0
18
+ Requires-Dist: scipy>=1.8.0
19
+ Requires-Dist: numpy>=1.21.0
20
+ Requires-Dist: tqdm>=4.56.2
21
+ Requires-Dist: wget>=3.2
22
+ Requires-Dist: wandb>=0.15.0
23
+ Requires-Dist: setuptools<71,>=65.0.0
24
+ Provides-Extra: attacks
25
+ Requires-Dist: adversarial-robustness-toolbox; extra == "attacks"
26
+ Requires-Dist: foolbox; extra == "attacks"
27
+ Requires-Dist: torchattacks; extra == "attacks"
28
+ Requires-Dist: cleverhans==4.0.0; extra == "attacks"
29
+ Provides-Extra: deeprobust
30
+ Requires-Dist: deeprobust; extra == "deeprobust"
31
+ Requires-Dist: scipy<1.8.0,>=1.5.0; extra == "deeprobust"
32
+ Provides-Extra: models
33
+ Requires-Dist: pillow>=8.0.0; extra == "models"
34
+ Requires-Dist: requests>=2.25.0; extra == "models"
35
+ Requires-Dist: timm>=0.9.0; extra == "models"
36
+ Requires-Dist: transformers>=4.20.0; extra == "models"
37
+ Requires-Dist: robustbench>=1.1; extra == "models"
38
+ Requires-Dist: pyautoattack>=0.2.0; extra == "models"
39
+ Requires-Dist: pretrainedmodels>=0.7.4; extra == "models"
40
+ Provides-Extra: metrics
41
+ Requires-Dist: scikit-learn>=1.0.0; extra == "metrics"
42
+ Requires-Dist: seaborn>=0.11.0; extra == "metrics"
43
+ Requires-Dist: plotly>=5.0.0; extra == "metrics"
44
+ Requires-Dist: tabulate>=0.9.0; extra == "metrics"
45
+ Provides-Extra: all
46
+ Requires-Dist: adversarial-robustness-toolbox; extra == "all"
47
+ Requires-Dist: foolbox; extra == "all"
48
+ Requires-Dist: torchattacks; extra == "all"
49
+ Requires-Dist: cleverhans==4.0.0; extra == "all"
50
+ Requires-Dist: robustbench>=1.1; extra == "all"
51
+ Requires-Dist: pyautoattack>=0.2.0; extra == "all"
52
+ Requires-Dist: timm>=0.9.0; extra == "all"
53
+ Requires-Dist: transformers>=4.20.0; extra == "all"
54
+ Requires-Dist: pretrainedmodels>=0.7.4; extra == "all"
55
+ Requires-Dist: scikit-learn>=1.0.0; extra == "all"
56
+ Requires-Dist: seaborn>=0.11.0; extra == "all"
57
+ Requires-Dist: plotly>=5.0.0; extra == "all"
58
+ Requires-Dist: tabulate>=0.9.0; extra == "all"
59
+ Requires-Dist: pillow>=8.0.0; extra == "all"
60
+ Requires-Dist: requests>=2.25.0; extra == "all"
61
+ Provides-Extra: dev
62
+ Requires-Dist: pytest>=6.0; extra == "dev"
63
+ Requires-Dist: black>=22.0; extra == "dev"
64
+ Requires-Dist: isort>=5.0; extra == "dev"
65
+ Requires-Dist: flake8>=4.0; extra == "dev"
66
+ Provides-Extra: docs
67
+ Requires-Dist: sphinx>=7.0.0; extra == "docs"
68
+ Requires-Dist: sphinx-rtd-theme>=2.0.0; extra == "docs"
69
+ Requires-Dist: sphinx-autodoc-typehints>=1.19.0; extra == "docs"
70
+ Requires-Dist: myst-parser>=2.0.0; extra == "docs"
71
+
72
+ # **AttackBench**: Evaluating Gradient-based Attacks for Adversarial Examples
73
+
74
+ Antonio Emanuele Cinà, Jérôme Rony, Maura Pintor, Luca Demetrio, Ambra Demontis, Battista Biggio, Ismail Ben Ayed, Fabio Roli, and Riccardo Trebiani
75
+
76
+ **Leaderboard**: [https://attackbench.github.io/](https://attackbench.github.io/)
77
+
78
+ **Paper:** [https://arxiv.org/pdf/2404.19460](https://arxiv.org/pdf/2404.19460)
79
+
80
+ **Tutorial Notebook:** [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1rzzLRjMovcns25qOeEXt15R3L2Md_Pst?usp=sharing)
81
+
82
+ ## How it works
83
+
84
+ The <code>AttackBench</code> framework wants to fairly compare gradient-based attacks based on their security evaluation curves. To this end, we derive a process involving five distinct stages, as depicted below.
85
+ - In stage (1), we construct a list of diverse non-robust and robust models to assess the attacks' impact on various settings, thus testing their adaptability to diverse defensive strategies.
86
+ - In stage (2), we define an environment for testing gradient-based attacks under a systematic and reproducible protocol.
87
+ This step provides common ground with shared assumptions, advantages, and limitations.
88
+ We then run the attacks against the selected models individually and collect the performance metrics of interest in our analysis, which are perturbation size, execution time, and query usage.
89
+ - In stage (3), we gather all the previously-obtained results, comparing attacks with the novel <code>local optimality</code> metric.
90
+ - Finally, in stage (4), we aggregate the optimality results from all considered models, and in stage (5) we rank the attacks based on their average optimality, namely <code>global optimality</code>.
91
+
92
+
93
+ <p align="center"><img src="https://attackbench.github.io/assets/AtkBench.svg" width="1300"></p>
94
+
95
+
96
+ ## Currently implemented
97
+
98
+ | Attack | Original | Advertorch | Adv_lib | ART | CleverHans | DeepRobust | Foolbox | Torchattacks |
99
+ |--------------|:--------:|:----------:|:-------:|:---:|:----------:|:----------:|:-------:|:------------:|
100
+ | DDN | ☒ | | ✓ | ☒ | ☒ | ☒ | ✓ | ☒ |
101
+ | ALMA | ☒ | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ |
102
+ | FMN | ✓ | ☒ | ✓ | ☒ | ☒ | ☒ | ✓ | ☒ |
103
+ | PGD | ☒ | | ✓ | ✓ | | ✓ | | ✓ |
104
+ | JSMA | ☒ | | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ |
105
+ | CW-L2 | ☒ | | ✓ | ✓ | | ~ | ✓ | ✓ |
106
+ | CW-LINF | ☒ | ☒ | ✓ | ✓ | ☒ | ☒ | ☒ | ☒ |
107
+ | FGSM | ☒ | | ☒ | ✓ | | | | ✓ |
108
+ | BB | ☒ | ☒ | ☒ | ✓ | ☒ | ☒ | ✓ | ☒ |
109
+ | DF | ✓ | ☒ | ☒ | ✓ | ☒ | ~ | ✓ | ✓ |
110
+ | SuperDF | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ | ☒ | ☒ |
111
+ | APGD | ✓ | ☒ | ✓ | ✓ | ☒ | ☒ | ☒ | ✓ |
112
+ | BIM | ☒ | | ☒ | ✓ | | ☒ | | ☒ |
113
+ | EAD | ☒ | | ☒ | ✓ | ☒ | ☒ | ✓ | ☒ |
114
+ | PDGD | ☒ | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ |
115
+ | PDPGD | ☒ | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ |
116
+ | TR | ✓ | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ |
117
+ | FAB | ✓ | | ✓ | ☒ | ☒ | ☒ | ☒ | ✓ |
118
+
119
+
120
+ Legend:
121
+ - _empty_ : not implemented yet
122
+ - ☒ : not available
123
+ - ✓ : implemented
124
+ - ~ : not functional yet
125
+
126
+
127
+
128
+ ## Requirements and Installation
129
+
130
+ - Python >= 3.9, < 3.13
131
+ - PyTorch >= 2.4
132
+ - TorchVision >= 0.19
133
+ - CUDA compatible GPU (recommended)
134
+
135
+ ### Install from PyPI
136
+
137
+ ```bash
138
+ pip install attackbench
139
+ ```
140
+
141
+ ### Optional dependencies
142
+
143
+ ```bash
144
+ # Attack library wrappers (ART, Foolbox, Torchattacks, CleverHans, RobustBench)
145
+ pip install "attackbench[attacks]"
146
+
147
+ # Model loading utilities (RobustBench, timm, transformers)
148
+ pip install "attackbench[models]"
149
+
150
+ # Analysis and visualization tools (scikit-learn, seaborn, plotly)
151
+ pip install "attackbench[metrics]"
152
+
153
+ # Everything (attacks + models + metrics)
154
+ pip install "attackbench[all]"
155
+ ```
156
+
157
+ > **Note:** `adv-lib` is not on PyPI. Install it manually if needed:
158
+ > `pip install git+https://github.com/jeromerony/adversarial-library`
159
+ >
160
+ > `deeprobust` requires `scipy<1.8.0` and only works on Python 3.9:
161
+ > `pip install "attackbench[deeprobust]"`
162
+
163
+ ### Install from source (development)
164
+
165
+ ```bash
166
+ git clone https://github.com/attackbench/AttackBench.git
167
+ cd AttackBench
168
+ pip install -e ".[dev]"
169
+ ```
170
+
171
+
172
+ ## Usage
173
+
174
+ ```python
175
+ import torch
176
+ import attackbench
177
+ from attackbench.attacks import apgd
178
+
179
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
180
+
181
+ # Load model and dataset
182
+ model = attackbench.get_model('Standard')
183
+ model.to(device)
184
+
185
+ dataset = attackbench.get_loader(dataset='cifar10', batch_size=128, num_samples=1000)
186
+
187
+ # Run attack
188
+ results = attackbench.run_attack(
189
+ model=model,
190
+ dataset=dataset,
191
+ attack=apgd,
192
+ threat_model='linf',
193
+ device=device
194
+ )
195
+
196
+ # Analyze results (requires attackbench[metrics])
197
+ stats = attackbench.get_stats(results, 'linf')
198
+ print(f"ASR: {stats['asr']*100:.1f}%")
199
+ ```
200
+
201
+ Preconfigured attacks available out of the box: `pgd`, `fgsm`, `apgd`, `fab`, `fmn`, `deepfool`, `superdeepfool`, `trust_region`.
202
+
203
+ To use attacks from external libraries (requires `attackbench[attacks]`):
204
+
205
+ ```python
206
+ # List available attacks
207
+ attacks = attackbench.list_attacks(threat_model='linf')
208
+
209
+ # Load a specific library attack
210
+ art_pgd = attackbench.get_attack(lib='art', attack='pgd', threat_model='linf')
211
+ results = attackbench.run_attack(model=model, dataset=dataset, attack=art_pgd, threat_model='linf', device=device)
212
+ ```
213
+
214
+
215
+
216
+ ## Attack format
217
+
218
+ Tthe wrappers for all the implementations (including libraries) must have the following format:
219
+
220
+ - inputs:
221
+ - `model`: `nn.Module` taking inputs in the [0, 1] range and returning logits in $\mathbb{R}^K$
222
+ - `inputs`: `FloatTensor` representing the input samples in the [0, 1] range
223
+ - `labels`: `LongTensor` representing the labels of the samples
224
+ - `targets`: `LongTensor` or `None` representing the targets associated to each samples
225
+ - `targeted`: `bool` flag indicating if a targeted attack should be performed
226
+ - output:
227
+ - `adv_inputs`: `FloatTensor` representing the perturbed inputs in the [0, 1] range
228
+
229
+
230
+ ## Citation
231
+
232
+ If you use the **AttackBench** leaderboards or implementation, then consider citing our [paper]():
233
+
234
+ ```bibtex
235
+ @inproceedings{cina2025attackbench,
236
+ title={Attackbench: Evaluating gradient-based attacks for adversarial examples},
237
+ author={Cin{\`a}, Antonio Emanuele and Rony, J{\'e}r{\^o}me and Pintor, Maura and Demetrio, Luca and Demontis, Ambra and Biggio, Battista and Ayed, Ismail Ben and Roli, Fabio},
238
+ booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
239
+ volume={39},
240
+ number={3},
241
+ pages={2600--2608},
242
+ year={2025},
243
+ DOI={10.1609/aaai.v39i3.32263}
244
+ }
245
+ ```
246
+
247
+ ## Contact
248
+ Feel free to contact us about anything related to **`AttackBench`** by creating an issue, a pull request or
249
+ by email at `antonio.cina@unige.it`.
250
+
251
+ ## Acknowledgements
252
+ AttackBench has been partially developed with the support of European Union’s [ELSA – European Lighthouse on Secure and Safe AI](https://elsa-ai.eu), Horizon Europe, grant agreement No. 101070617, and [Sec4AI4Sec - Cybersecurity for AI-Augmented Systems](https://www.sec4ai4sec-project.eu), Horizon Europe, grant agreement No. 101120393.
253
+
254
+ <img src="_static/assets/logos/sec4AI4sec.png" alt="sec4ai4sec" style="width:70px;"/> &nbsp;&nbsp;
255
+ <img src="_static/assets/logos/elsa.jpg" alt="elsa" style="width:70px;"/> &nbsp;&nbsp;
256
+ <img src="_static/assets/logos/FundedbytheEU.png" alt="europe" style="width:240px;"/>
@@ -0,0 +1,185 @@
1
+ # **AttackBench**: Evaluating Gradient-based Attacks for Adversarial Examples
2
+
3
+ Antonio Emanuele Cinà, Jérôme Rony, Maura Pintor, Luca Demetrio, Ambra Demontis, Battista Biggio, Ismail Ben Ayed, Fabio Roli, and Riccardo Trebiani
4
+
5
+ **Leaderboard**: [https://attackbench.github.io/](https://attackbench.github.io/)
6
+
7
+ **Paper:** [https://arxiv.org/pdf/2404.19460](https://arxiv.org/pdf/2404.19460)
8
+
9
+ **Tutorial Notebook:** [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1rzzLRjMovcns25qOeEXt15R3L2Md_Pst?usp=sharing)
10
+
11
+ ## How it works
12
+
13
+ The <code>AttackBench</code> framework wants to fairly compare gradient-based attacks based on their security evaluation curves. To this end, we derive a process involving five distinct stages, as depicted below.
14
+ - In stage (1), we construct a list of diverse non-robust and robust models to assess the attacks' impact on various settings, thus testing their adaptability to diverse defensive strategies.
15
+ - In stage (2), we define an environment for testing gradient-based attacks under a systematic and reproducible protocol.
16
+ This step provides common ground with shared assumptions, advantages, and limitations.
17
+ We then run the attacks against the selected models individually and collect the performance metrics of interest in our analysis, which are perturbation size, execution time, and query usage.
18
+ - In stage (3), we gather all the previously-obtained results, comparing attacks with the novel <code>local optimality</code> metric.
19
+ - Finally, in stage (4), we aggregate the optimality results from all considered models, and in stage (5) we rank the attacks based on their average optimality, namely <code>global optimality</code>.
20
+
21
+
22
+ <p align="center"><img src="https://attackbench.github.io/assets/AtkBench.svg" width="1300"></p>
23
+
24
+
25
+ ## Currently implemented
26
+
27
+ | Attack | Original | Advertorch | Adv_lib | ART | CleverHans | DeepRobust | Foolbox | Torchattacks |
28
+ |--------------|:--------:|:----------:|:-------:|:---:|:----------:|:----------:|:-------:|:------------:|
29
+ | DDN | ☒ | | ✓ | ☒ | ☒ | ☒ | ✓ | ☒ |
30
+ | ALMA | ☒ | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ |
31
+ | FMN | ✓ | ☒ | ✓ | ☒ | ☒ | ☒ | ✓ | ☒ |
32
+ | PGD | ☒ | | ✓ | ✓ | | ✓ | | ✓ |
33
+ | JSMA | ☒ | | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ |
34
+ | CW-L2 | ☒ | | ✓ | ✓ | | ~ | ✓ | ✓ |
35
+ | CW-LINF | ☒ | ☒ | ✓ | ✓ | ☒ | ☒ | ☒ | ☒ |
36
+ | FGSM | ☒ | | ☒ | ✓ | | | | ✓ |
37
+ | BB | ☒ | ☒ | ☒ | ✓ | ☒ | ☒ | ✓ | ☒ |
38
+ | DF | ✓ | ☒ | ☒ | ✓ | ☒ | ~ | ✓ | ✓ |
39
+ | SuperDF | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ | ☒ | ☒ |
40
+ | APGD | ✓ | ☒ | ✓ | ✓ | ☒ | ☒ | ☒ | ✓ |
41
+ | BIM | ☒ | | ☒ | ✓ | | ☒ | | ☒ |
42
+ | EAD | ☒ | | ☒ | ✓ | ☒ | ☒ | ✓ | ☒ |
43
+ | PDGD | ☒ | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ |
44
+ | PDPGD | ☒ | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ |
45
+ | TR | ✓ | ☒ | ✓ | ☒ | ☒ | ☒ | ☒ | ☒ |
46
+ | FAB | ✓ | | ✓ | ☒ | ☒ | ☒ | ☒ | ✓ |
47
+
48
+
49
+ Legend:
50
+ - _empty_ : not implemented yet
51
+ - ☒ : not available
52
+ - ✓ : implemented
53
+ - ~ : not functional yet
54
+
55
+
56
+
57
+ ## Requirements and Installation
58
+
59
+ - Python >= 3.9, < 3.13
60
+ - PyTorch >= 2.4
61
+ - TorchVision >= 0.19
62
+ - CUDA compatible GPU (recommended)
63
+
64
+ ### Install from PyPI
65
+
66
+ ```bash
67
+ pip install attackbench
68
+ ```
69
+
70
+ ### Optional dependencies
71
+
72
+ ```bash
73
+ # Attack library wrappers (ART, Foolbox, Torchattacks, CleverHans, RobustBench)
74
+ pip install "attackbench[attacks]"
75
+
76
+ # Model loading utilities (RobustBench, timm, transformers)
77
+ pip install "attackbench[models]"
78
+
79
+ # Analysis and visualization tools (scikit-learn, seaborn, plotly)
80
+ pip install "attackbench[metrics]"
81
+
82
+ # Everything (attacks + models + metrics)
83
+ pip install "attackbench[all]"
84
+ ```
85
+
86
+ > **Note:** `adv-lib` is not on PyPI. Install it manually if needed:
87
+ > `pip install git+https://github.com/jeromerony/adversarial-library`
88
+ >
89
+ > `deeprobust` requires `scipy<1.8.0` and only works on Python 3.9:
90
+ > `pip install "attackbench[deeprobust]"`
91
+
92
+ ### Install from source (development)
93
+
94
+ ```bash
95
+ git clone https://github.com/attackbench/AttackBench.git
96
+ cd AttackBench
97
+ pip install -e ".[dev]"
98
+ ```
99
+
100
+
101
+ ## Usage
102
+
103
+ ```python
104
+ import torch
105
+ import attackbench
106
+ from attackbench.attacks import apgd
107
+
108
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
109
+
110
+ # Load model and dataset
111
+ model = attackbench.get_model('Standard')
112
+ model.to(device)
113
+
114
+ dataset = attackbench.get_loader(dataset='cifar10', batch_size=128, num_samples=1000)
115
+
116
+ # Run attack
117
+ results = attackbench.run_attack(
118
+ model=model,
119
+ dataset=dataset,
120
+ attack=apgd,
121
+ threat_model='linf',
122
+ device=device
123
+ )
124
+
125
+ # Analyze results (requires attackbench[metrics])
126
+ stats = attackbench.get_stats(results, 'linf')
127
+ print(f"ASR: {stats['asr']*100:.1f}%")
128
+ ```
129
+
130
+ Preconfigured attacks available out of the box: `pgd`, `fgsm`, `apgd`, `fab`, `fmn`, `deepfool`, `superdeepfool`, `trust_region`.
131
+
132
+ To use attacks from external libraries (requires `attackbench[attacks]`):
133
+
134
+ ```python
135
+ # List available attacks
136
+ attacks = attackbench.list_attacks(threat_model='linf')
137
+
138
+ # Load a specific library attack
139
+ art_pgd = attackbench.get_attack(lib='art', attack='pgd', threat_model='linf')
140
+ results = attackbench.run_attack(model=model, dataset=dataset, attack=art_pgd, threat_model='linf', device=device)
141
+ ```
142
+
143
+
144
+
145
+ ## Attack format
146
+
147
+ Tthe wrappers for all the implementations (including libraries) must have the following format:
148
+
149
+ - inputs:
150
+ - `model`: `nn.Module` taking inputs in the [0, 1] range and returning logits in $\mathbb{R}^K$
151
+ - `inputs`: `FloatTensor` representing the input samples in the [0, 1] range
152
+ - `labels`: `LongTensor` representing the labels of the samples
153
+ - `targets`: `LongTensor` or `None` representing the targets associated to each samples
154
+ - `targeted`: `bool` flag indicating if a targeted attack should be performed
155
+ - output:
156
+ - `adv_inputs`: `FloatTensor` representing the perturbed inputs in the [0, 1] range
157
+
158
+
159
+ ## Citation
160
+
161
+ If you use the **AttackBench** leaderboards or implementation, then consider citing our [paper]():
162
+
163
+ ```bibtex
164
+ @inproceedings{cina2025attackbench,
165
+ title={Attackbench: Evaluating gradient-based attacks for adversarial examples},
166
+ author={Cin{\`a}, Antonio Emanuele and Rony, J{\'e}r{\^o}me and Pintor, Maura and Demetrio, Luca and Demontis, Ambra and Biggio, Battista and Ayed, Ismail Ben and Roli, Fabio},
167
+ booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
168
+ volume={39},
169
+ number={3},
170
+ pages={2600--2608},
171
+ year={2025},
172
+ DOI={10.1609/aaai.v39i3.32263}
173
+ }
174
+ ```
175
+
176
+ ## Contact
177
+ Feel free to contact us about anything related to **`AttackBench`** by creating an issue, a pull request or
178
+ by email at `antonio.cina@unige.it`.
179
+
180
+ ## Acknowledgements
181
+ AttackBench has been partially developed with the support of European Union’s [ELSA – European Lighthouse on Secure and Safe AI](https://elsa-ai.eu), Horizon Europe, grant agreement No. 101070617, and [Sec4AI4Sec - Cybersecurity for AI-Augmented Systems](https://www.sec4ai4sec-project.eu), Horizon Europe, grant agreement No. 101120393.
182
+
183
+ <img src="_static/assets/logos/sec4AI4sec.png" alt="sec4ai4sec" style="width:70px;"/> &nbsp;&nbsp;
184
+ <img src="_static/assets/logos/elsa.jpg" alt="elsa" style="width:70px;"/> &nbsp;&nbsp;
185
+ <img src="_static/assets/logos/FundedbytheEU.png" alt="europe" style="width:240px;"/>