Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make output to output_images, refine README #20

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`.
Expand Down
Loading