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

2005 generate adversarial dataset #3

Merged
merged 26 commits into from
Oct 23, 2023

Conversation

treubig26
Copy link
Collaborator

What does this MR do and why?

Add engine to support creation of adversarial datasets (datasets with an evasion attack pre-applied to all samples for the ability to perform quicker real-time demonstrations).

Also refactors the batches from tuples of (x, y) to dictionaries (where the x_key and y_key are provided so armory knows how to obtain x/y from the dictionary). This is done to avoid reducing or dropping information from the original dataset.

Related issues

#2005

How to set up and validate locally

In the examples/src/charmory_examples/image_classification/eurosat_precomputed_pgd/ folder:

  • Run create_adversarial_eurosat.py [convnext|swin|vit] to create an adversarial dataset
  • Run run_against_pregenerated.py [convnext|swin|vit] [convnext|swin|vit] to perform evaluation using the adversarial dataset
    • first argument is the name of the model to be evaluated
    • second argument is the name of the model used to generate the adversarial dataset (i.e., what was used with create_adversarial_eurosat.py)
  • Run run_with_attack.py [convnext|swin|vit] to perform inline attack evaluation (typical armory usage)

MR approval & acceptance process

Areas of focus for the review:

  • Briefly look over changes to examples introduced by LightningEngine rename and evaluation.Dataset changes
  • Tuple vs dict batch changes in src/charmory/data.py and src/charmory/tasks/base.py
  • New adversarial dataset engine in src/charmory/engine/adversarial_dataset.py
  • EuroSAT example in examples/src/charmory_examples/image_classification/eurosat_precomputed_pgd/
  • New exports of target info in src/charmory/tasks/image_classification.py and src/charmory/tasks/object_detection.py
    • Not strictly necessary, but was put in place when the initial plan was to rely on mlflow exports and is still useful

Closes #2005

@treubig26 treubig26 requested a review from mwartell October 19, 2023 15:52
@treubig26 treubig26 self-assigned this Oct 19, 2023
@treubig26 treubig26 requested a review from Honaker October 19, 2023 16:09
@mwartell
Copy link
Contributor

There are two deprecation warnings on vit at least.

/home/msw/.virtualenvs/cdao/lib/python3.10/site-packages/transformers/models/vit/feature_extraction_vit.py:28: FutureWarning: The class ViTFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please use ViTImageProcessor instead.
/home/msw/.virtualenvs/cdao/lib/python3.10/site-packages/datasets/load.py:2086: FutureWarning: 'task' was deprecated in version 2.13.0 and will be removed in 3.0.0.

@treubig26
Copy link
Collaborator Author

There are two deprecation warnings on vit at least.

/home/msw/.virtualenvs/cdao/lib/python3.10/site-packages/transformers/models/vit/feature_extraction_vit.py:28: FutureWarning: The class ViTFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please use ViTImageProcessor instead. /home/msw/.virtualenvs/cdao/lib/python3.10/site-packages/datasets/load.py:2086: FutureWarning: 'task' was deprecated in version 2.13.0 and will be removed in 3.0.0.

Yeah, those are coming right out of HuggingFace because of the model's built-in configuration/metadata. I've seen similar deprecation warnings on a lot of the models picked at random from the HF hub (even from popular models). If HF goes through with the deprecated feature removal in version 3.0, there will be a lot of broken/unusuable models in their hub.

Copy link
Contributor

@mwartell mwartell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A PR of Treubig cleanliness. Thanks.

I am not waiting for the dataset to load before merging. I'll report errors post hoc should I happen to see one.

.pre-commit-config.yaml Show resolved Hide resolved
@mwartell mwartell merged commit 7a16b13 into master Oct 23, 2023
@treubig26 treubig26 deleted the 2005-generate-adversarial-dataset branch October 23, 2023 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants