Skip to content

Commit

Permalink
examples: update feature squeezing example to task engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsextonMITRE committed Oct 26, 2023
1 parent 9cac4e4 commit 6d85844
Show file tree
Hide file tree
Showing 27 changed files with 3,550 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
def create_adversarial_cw_inf_dataset(
data_dir: str,
model_name: str,
model_version: str,
model_version: int,
learning_rate: float,
max_iter: int,
verbose: str,
Expand All @@ -74,7 +74,7 @@ def create_adversarial_cw_inf_dataset(
confidence: float = 0.0,
**kwargs,
):
model_name = model_name
model_name = model_name + "/" + str(model_version)
LOGGER.info("Model Selected: ", model_name=model_name)
color_mode: str = "color" if image_size[2] == 3 else "grayscale"
target_size: Tuple[int, int] = image_size[:2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
def create_adversarial_cw_l2_dataset(
data_dir: str,
model_name: str,
model_version: str,
model_version: int,
confidence: float,
targeted: bool,
learning_rate: float,
Expand All @@ -76,7 +76,7 @@ def create_adversarial_cw_l2_dataset(
image_size: Tuple[int, int] = (28, 28),
**kwargs,
):
model_name = model_name + "/" + model_version
model_name = model_name + "/" + str(model_version)
LOGGER.info("Model Selected: ", model_name=model_name)
color_mode: str = "color" if image_size[2] == 3 else "grayscale"
target_size: Tuple[int, int] = image_size[:2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def evaluate_classification_metrics(classifier, adv_ds):
def create_adversarial_deepfool_dataset(
data_dir: str,
model_name: str,
model_version: str,
model_version: int,
epsilon: float,
nb_grads: int,
max_iter: int,
Expand All @@ -86,7 +86,7 @@ def create_adversarial_deepfool_dataset(
color_mode: str = "rgb",
**kwargs,
):
model_name = model_name + "/" + model_version
model_name = model_name + "/" + str(model_version)
attack = DeepFool(
classifier=keras_classifier,
batch_size=batch_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
def create_adversarial_jsma_dataset(
data_dir: str,
model_name: str,
model_version: str,
model_version: int,
theta: float,
gamma: float,
keras_classifier: KerasClassifier,
Expand All @@ -68,11 +68,11 @@ def create_adversarial_jsma_dataset(
batch_size: int = 32,
label_mode: str = "categorical",
color_mode: str = "grayscale",
image_size: Tuple[int, int] = (28, 28),
image_size: Tuple[int, int] = (28, 28, 1),
verbose: bool = True,
**kwargs,
):
model_name = model_name + "/" + model_version
model_name = model_name + "/" + str(model_version)
LOGGER.info("Model Selected: ", model_name=model_name)
color_mode: str = "color" if image_size[2] == 3 else "grayscale"
target_size: Tuple[int, int] = image_size[:2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import numpy as np
import structlog
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator, save_img
from tensorflow.keras.preprocessing.image import DirectoryIterator, ImageDataGenerator, save_img

from dioptra import pyplugs
from dioptra.sdk.exceptions import ARTDependencyError, TensorflowDependencyError
Expand All @@ -51,19 +51,19 @@
@require_package("art", exc_type=ARTDependencyError)
@require_package("tensorflow", exc_type=TensorflowDependencyError)
def feature_squeeze(
data_dir,
run_id,
model,
model_architecture,
batch_size,
seed,
bit_depth,
model_version,
adv_tar_name,
image_size,
adv_data_dir,
data_flow,
):
data_dir: str,
run_id: str,
model: str,
model_architecture: str,
adv_tar_name: str,
image_size: Tuple[int,int,int],
adv_data_dir: str,
data_flow: DirectoryIterator,
batch_size: int = 32,
seed: int = -1,
bit_depth: int = 8,
model_version: str = 1,
) -> None:
rng = np.random.default_rng(seed if seed >= 0 else None)

if seed < 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@
"hash": "edee40310913f16e2ca02c1d37887bcb7f07f00399ca119bb7e27de7d632ea99"
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -937,7 +937,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.10"
"version": "3.9.5"
}
},
"nbformat": 4,
Expand Down
22 changes: 22 additions & 0 deletions examples/tensorflow-mnist-feature-squeezing-legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Tensorflow MNIST Feature Squeezing demo

This example demonstrates using Dioptra to run experiments that investigate the effectiveness of the feature-squeezing defense against a series of evasion attacks against a neural network model.
The demo can be found in the Jupyter notebook file [demo.ipynb](demo.ipynb).

## Running the example

To prepare your environment for running this example, follow the linked instructions below:

1. [Create and activate a Python virtual environment and install the necessary dependencies](../README.md#creating-a-virtual-environment)
2. [Download the MNIST dataset using the download_data.py script.](../README.md#downloading-datasets)
3. [Follow the links in these User Setup instructions](../../README.md#user-setup) to do the following:
- Build the containers
- Use the cookiecutter template to generate the scripts, configuration files, and Docker Compose files you will need to run Dioptra
4. [Edit the docker-compose.yml file to mount the data folder in the worker containers](../README.md#mounting-the-data-folder-in-the-worker-containers)
5. [Initialize and start Dioptra](https://pages.nist.gov/dioptra/getting-started/running-dioptra.html#initializing-the-deployment)
6. [Register the custom task plugins for Dioptra's examples and demos](../README.md#registering-custom-task-plugins)
7. [Register the queues for Dioptra's examples and demos](../README.md#registering-queues)
8. [Start JupyterLab and open `demo.ipynb`](../README.md#starting-jupyter-lab)

Steps 1–4 and 6–7 only need to be run once.
**Returning users only need to repeat Steps 5 (if you stopped Dioptra using `docker compose down`) and 8 (if you stopped the `jupyter lab` process)**.
Loading

0 comments on commit 6d85844

Please sign in to comment.