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

Implement STRIP Defense Against Poisoning Attacks #656

Merged
merged 19 commits into from
Nov 2, 2020
Merged

Conversation

ebubae
Copy link
Collaborator

@ebubae ebubae commented Oct 13, 2020

Description

This PR:

Type of change

Please check all relevant options.

  • Improvement (non-breaking)
  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Testing

Please describe the tests that you ran to verify your changes. Consider listing any relevant details of your test configuration.

Currently tests are running and pass for Keras and TF Keras. I had some issues with the Pytorch unit test classifier.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Sorry, something went wrong.

@ebubae ebubae requested a review from beat-buesser October 13, 2020 23:17
@ebubae ebubae added this to the ART v1.5.0 milestone Oct 13, 2020
@beat-buesser beat-buesser self-assigned this Oct 14, 2020
@beat-buesser beat-buesser added the enhancement New feature or request label Oct 14, 2020
@@ -0,0 +1,108 @@
# MIT License
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please convert these tests to the new pytest pattern: https://github.com/Trusted-AI/adversarial-robustness-toolbox/wiki/ART-Unit-Testing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

run_tests.sh Outdated
@@ -111,6 +111,7 @@ declare -a defences=("tests/defences/test_adversarial_trainer.py" \
"tests/defences/test_pixel_defend.py" \
"tests/defences/test_reverse_sigmoid.py" \
"tests/defences/test_rounded.py" \
"tests/defences/test_strip.py" \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please convert these tests to the new pytest pattern: https://github.com/Trusted-AI/adversarial-robustness-toolbox/wiki/ART-Unit-Testing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. Please check that it's truly framework-independent. I'm not sure if it's only testing TF.

self,
num_samples: int = 20,
false_acceptance_rate: float = 0.01,
) -> "CLASSIFIER_TYPE":
Copy link
Collaborator

@beat-buesser beat-buesser Oct 15, 2020

Choose a reason for hiding this comment

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

Could we make the return type more specific to reflect the STRIPMixin? I think it's not just a general classifier anymore.

Copy link
Collaborator Author

@ebubae ebubae Oct 20, 2020

Choose a reason for hiding this comment

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

This is a very good point. I've added a TypeVar to bound the return type.


:param num_samples: The number of samples to use to test entropy at inference time
:param false_acceptance_rate: The percentage of acceptable false acceptance
:param predict function
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this line needs an update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

# Randomly select samples from test set
selected_indices = np.random.choice(np.arange(len(x_val)), self.num_samples)

# Perturn the images by combining them
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Perturn the images by combining them
# Perturb the images by combining them

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching this.

@beat-buesser
Copy link
Collaborator

beat-buesser commented Oct 15, 2020

Could you please update art.estimators.__init__.py with an import of poison_mitigation after line 18?

Could you please add the new notebook to notebooks/README.md, probably in the section Poisoning?

@@ -0,0 +1,4 @@
"""
Neural cleanse estimators.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this docstring needs an update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Collaborator

@beat-buesser beat-buesser left a comment

Choose a reason for hiding this comment

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

Hi @ebubae Thank you very much for implementing a new defence against poisoning! A think it's a very nice implementation and I only have a few formatting requests.

@ebubae ebubae linked an issue Oct 15, 2020 that may be closed by this pull request
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
@codecov-io
Copy link

codecov-io commented Oct 19, 2020

Codecov Report

Merging #656 into dev_1.5.0 will decrease coverage by 0.07%.
The diff coverage is 45.00%.

Impacted file tree graph

@@              Coverage Diff              @@
##           dev_1.5.0     #656      +/-   ##
=============================================
- Coverage      58.93%   58.86%   -0.08%     
=============================================
  Files            155      159       +4     
  Lines          14206    14282      +76     
  Branches        2551     2559       +8     
=============================================
+ Hits            8373     8407      +34     
- Misses          5031     5072      +41     
- Partials         802      803       +1     
Impacted Files Coverage Δ
...poison_mitigation/neural_cleanse/neural_cleanse.py 17.85% <ø> (ø)
art/estimators/poison_mitigation/strip/strip.py 29.16% <29.16%> (ø)
art/defences/transformer/poisoning/strip.py 58.33% <58.33%> (ø)
art/defences/transformer/poisoning/__init__.py 100.00% <100.00%> (ø)
...t/defences/transformer/poisoning/neural_cleanse.py 62.50% <100.00%> (ø)
art/estimators/poison_mitigation/__init__.py 100.00% <100.00%> (ø)
...ators/poison_mitigation/neural_cleanse/__init__.py 100.00% <100.00%> (ø)
...timators/poison_mitigation/neural_cleanse/keras.py 15.17% <100.00%> (ø)
art/estimators/poison_mitigation/strip/__init__.py 100.00% <100.00%> (ø)
... and 5 more

Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Signed-off-by: Ebube Chuba <ebube.chuba@ibm.com>
Copy link
Collaborator

@beat-buesser beat-buesser left a comment

Choose a reason for hiding this comment

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

Hi @ebubae Thank you very much for implementing the STRIP defense against poisoning attacks!

@beat-buesser beat-buesser merged commit cb31e75 into dev_1.5.0 Nov 2, 2020
@beat-buesser beat-buesser deleted the strip branch November 2, 2020 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement STRIP defense against poisoning attacks
3 participants