From 6ee834b6008aa5e8c26e845c782b8af40dd853c7 Mon Sep 17 00:00:00 2001 From: Tom Carter Date: Thu, 5 Dec 2024 11:00:56 +0000 Subject: [PATCH] make output to output_images, refine README (#20) --- Makefile | 4 ++-- README.md | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 996f5ff..2fc240d 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ .PHONY: example_standard example_standard: mkdir -p ./output - docker run -v ./output:/app/output tomcarter23/adversarial_attack:latest python -m adversarial_attack --model resnet50 --mode standard --image ./sample_images/imagenet/lionfish_ILSVRC2012_val_00019791.JPEG --category-truth lionfish --category-target monarch --epsilon 1.0e-3 --max-iterations 50 --output ./output/adversarial_lionfish.JPEG --log DEBUG + docker run -v ./output_images:/app/output_images tomcarter23/adversarial_attack:latest python -m adversarial_attack --model resnet50 --mode standard --image ./sample_images/imagenet/lionfish_ILSVRC2012_val_00019791.JPEG --category-truth lionfish --epsilon 1.0e-3 --max-iterations 50 --output ./output_images/adversarial_lionfish.JPEG --log DEBUG .PHONY: example_targeted example_targeted: mkdir -p ./output - docker run -v ./output:/app/output tomcarter23/adversarial_attack:latest python -m adversarial_attack --model resnet50 --mode targeted --image ./sample_images/imagenet/lionfish_ILSVRC2012_val_00019791.JPEG --category-truth lionfish --category-target monarch --epsilon 1.0e-3 --max-iterations 50 --output ./output/lionfish_to_monarch.JPEG --log DEBUG + docker run -v ./output_images:/app/output_images tomcarter23/adversarial_attack:latest python -m adversarial_attack --model resnet50 --mode targeted --image ./sample_images/imagenet/lionfish_ILSVRC2012_val_00019791.JPEG --category-truth lionfish --category-target monarch --epsilon 1.0e-3 --max-iterations 50 --output ./output_images/lionfish_to_monarch.JPEG --log DEBUG diff --git a/README.md b/README.md index 10a63b0..0bc201e 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,12 @@ docker run -v /path/to/images:/app/images -v /path/to/output:/app/output tomcart The command mounts the `/path/to/images` directory to the `/app/images` directory in the container and the `/path/to/output` directory to the `/app/output` directory in the container. The command then runs the adversarial attack on the `goldfish.JPEG` image in the `/images` directory and saves the resulting adversarial image as `adversarial_goldfish.JPEG` in the `/output` directory. +## Input Images for Testing + +The `sample_images/imagenet` directory contains a set of example images from the ILSCVR2012 Imagenet validation dataset which constitute part of the same dataset that the pre-trained models were trained on. +The images are named according to their true class label (e.g., `lawn_mower_ILSVRC2012_val_00020327.JPEG`), where the true class label is the part of the filename before the `ILSVRC2012` identifier. +True classes in each of the provided models do not contain underscores e.g. `lawn mower`. This format should be used if using these sample images for testing. These images are used in the following examples and tests. + ## Running Two Examples via Make Possibly the simplest way to run some examples is through the `make` command. Two examples have been pre-prepared in the `Makefile` to demonstrate the use of the library. These are the `example_standard` and `example_targeted` commands. @@ -136,13 +142,9 @@ and make example_targeted ``` -The commands will use the latest docker image of the library and run the standard and targeted attacks on the `lionfish_ILSVRC2012_val_00019791.JPEG` example image. Output images will be saved in the newly created `output` directory and information about the attack will be printed to the console. +The commands will use the latest docker image of the library and run the standard and targeted attacks on the `lionfish_ILSVRC2012_val_00019791.JPEG` example image using the `resnet50` model. Output images will be saved in the `output_images` directory and information about the attack will be printed to the console. -## Specific Example - -The `sample_images/imagenet` directory contains a set of example images from the ILSCVR2012 Imagenet validation dataset which constitute part of the same dataset that the pre-trained models were trained on. -The images are named according to their true class label (e.g., `lawn_mower_ILSVRC2012_val_00020327.JPEG`), where the true class label is the part of the filename before the `ILSVRC2012` identifier. -True classes in each of the provided models do not contain underscores e.g. `lawn mower`. This format should be used if using these sample images for testing. +## Specific Example: Targeted Attack The following command demonstrates how to run a targeted adversarial attack on a ResNet50 model using the `hare` image from the `sample_images` directory. The target category is `goldfish`, and the epsilon value is `1.0e-3` with a maximum of `50` iterations. The resulting adversarial image is saved as `output_images/hare_to_goldfish.jpg`.