Follow these steps to add a new attack to the system using the art library.
-
Prepare the Attack Class in
artFormat- Ensure your attack class follows the
artlibrary structure and includes ageneratemethod.
- Ensure your attack class follows the
-
Upload Your Attack as a Python Package to Artifact Registry - Can skip this step if you've installed the art_plugin
-
Navigate to Artifact Registry
- Open the GCP console and search for "Artifact Registry."
-
Create a Repository
- Click on “Create repository” at the top of the page.
- Choose the repository type (in this case, select Python).
- Complete the creation process to have a repository ready for saving your package.
-
Upload the Python Package
- Install necessary tools:
pip install twine keyrings.google-artifactregistry-auth wheel
- Specify package version:
Ensure you have a
setup.pyfile that includes the following structure:from setuptools import setup, find_packages setup( name="art_attacks_plugin", version="0.2", author="MABADATA", author_email="[email protected]", description="New ART attacks plugins", include_package_data=True, classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], dependency_links=[ 'https://pypi.python.org/simple' ], package_dir={"": "src"}, packages=find_packages(where="src"), python_requires=">=3.6", )
- Build the package:
python setup.py bdist_wheel
- Upload to Artifact Registry:
twine upload --repository-url <repo-url>/<repo-name> dist/*
- Install necessary tools:
-
-
Install the Package from Artifact Registry in the Backend Project
- In the
Dockerfileof the backend project, add the following line to install the package:RUN pip install --index-url <repo-url> <package-name> - Example:
RUN pip install --index-url https://me-west1-python.pkg.dev/autodefenseml/art-attacks-plugin/simple/ art-attacks-plugin
- In the
-
Add the Attack to the
art-handlerRepository- Clone the
art-handlerrepository from GitHub if you haven’t already. - In the
attack_defense_map.jsonfile, add the new attack details. For example:"29": { "name": "Boundary_Tabular", "class_name": "art_attacks_plugin.Boundary_Tabular.BoundaryAttack", "type": "Evasion", "violation": "Integrity", "assumption": "BB", "influence": "Exploratory", "p-norm": "inf", "run_time": "Long", "description": "Implementation of the boundary attack tabular version by Fraidi Yael Itzhakev | Paper link: https://arxiv.org/abs/1712.04248", "default_max_iter": 5000 }
- Open the
setup.pyfile in theart-handlerrepository, increase the version number, and rebuild the package:python setup.py bdist_wheel
- Upload the package to Artifact Registry:
twine upload --repository-url https://us-central1-python.pkg.dev/autodefenseml/art-handler/ dist/*
- Clone the
-
Import the Attack Package in Code
- In the appropriate file (e.g.,
attack_defense_validation.py), import your attack package:from <package_name> import *
- In the appropriate file (e.g.,
-
Make Additional Changes as Needed
- If your attack requires additional parameters or configurations, or if you want to bable to optimize the parameters during evaluation, make the necessary addition modifications in
attack_defense_validation.py(in thepre_runpackage) andmodel_evaluation.py(in theevalpackage). For example, add the new attack to the hyperparameter optimization list here. - Look for the
generatefunction within these files and apply any changes required for the new attack to work correctly.
- If your attack requires additional parameters or configurations, or if you want to bable to optimize the parameters during evaluation, make the necessary addition modifications in
-
Prepare the Defense Class in
artFormat- Ensure your defense class follows the
artlibrary structure and includes a__call__method.
- Ensure your defense class follows the
-
Step 2+3 are the same as the new attack
-
Add the Defense to the
art-handlerRepository- In the
attack_defense_map.jsonfile, add the new defense details as follows:
"14":{ "name":"Counter_Samples", "class_name":"art_attacks_plugin.Counter_Samples.Counter_Samples", "type":"preprocessor", "description":"The implemetation of CounterSamples presented in the paper : https://arxiv.org/abs/2403.10562" }
- In the
- Open the
setup.pyfile in theart-handlerrepository, increase the version number, and rebuild the package:python setup.py bdist_wheel
- Upload the package to Artifact Registry:
twine upload --repository-url https://us-central1-python.pkg.dev/autodefenseml/art-handler/ dist/*
- Import the defense Package in Code
- In the appropriate file (e.g.,
attack_defense_validation.py), import your defense package:from <package_name> import *
- Make Additional Changes as Needed
- If your defense requires additional parameters or configurations, make the necessary modifications in
attack_defense_validation.py(in thepre_runpackage) andmodel_evaluation.py(in theevalpackage). For example, add the hyperparameters and their ranges for optimizaiton here. - Look for the
__call__function within these files and apply any changes required for the new defense to work correctly.
- If your defense requires additional parameters or configurations, make the necessary modifications in