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

Refactor Evasion Detectors #1993

Merged

Conversation

f4str
Copy link
Collaborator

@f4str f4str commented Jan 17, 2023

Description

Refactor the art.defences.detector.evasion module by creating a base abstract class EvasionDetector which all of the evasion detectors now inherit from. This base class has a .detect() method which will return a report and binary numpy array for which samples are detected adversarial. The BinaryInputDetector, BinaryActivationDetector, and SubsetScanningDetector classes have been refactored accordingly to inherit from EvasionDetector and use the .detect() method.

The unit tests have been updated accordingly and now use the pytest framework, so they have been removed from legacy tests.

This is technically a "breaking change" since the module has been refactored, but existing functionality is unchanged. Documentation has been updated along with updating notebooks/detection_adversarial_samples_cifar10.ipynb to use the new evasion detector structure.

Fixes #1913

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.

  • Unit tests for BinaryInputDetector using Keras, TensorFlow, and PyTorch
  • Unit tests for BinaryActivationDetector using Keras, TensorFlow, and PyTorch
  • Unit tests for SubsetScanningDetector using Keras, TensorFlow, and PyTorch

Test Configuration:

  • OS
  • Python version
  • ART version or commit number
  • TensorFlow / Keras / PyTorch / MXNet version

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

Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
@codecov-commenter
Copy link

codecov-commenter commented Jan 17, 2023

Codecov Report

Merging #1993 (a2b2ceb) into dev_1.14.0 (5ddd8ef) will decrease coverage by 0.01%.
The diff coverage is 80.66%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Impacted file tree graph

@@              Coverage Diff               @@
##           dev_1.14.0    #1993      +/-   ##
==============================================
- Coverage       85.41%   85.41%   -0.01%     
==============================================
  Files             290      291       +1     
  Lines           25437    25453      +16     
  Branches         4573     4587      +14     
==============================================
+ Hits            21728    21740      +12     
+ Misses           2541     2539       -2     
- Partials         1168     1174       +6     
Impacted Files Coverage Δ
...tector/evasion/subsetscanning/scoring_functions.py 66.66% <ø> (ø)
...ces/detector/evasion/binary_activation_detector.py 68.42% <68.42%> (ø)
art/defences/detector/evasion/evasion_detector.py 69.56% <69.56%> (ø)
...fences/detector/evasion/subsetscanning/detector.py 83.19% <84.84%> (-0.62%) ⬇️
art/defences/detector/evasion/__init__.py 100.00% <100.00%> (ø)
...defences/detector/evasion/binary_input_detector.py 100.00% <100.00%> (ø)
art/attacks/evasion/boundary.py 92.72% <0.00%> (-1.22%) ⬇️

Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
@f4str f4str marked this pull request as ready for review January 18, 2023 02:40
@beat-buesser beat-buesser self-requested a review January 18, 2023 15:49
@beat-buesser beat-buesser added the improvement Improve implementation label Jan 18, 2023
@beat-buesser beat-buesser added this to the ART 1.14.0 milestone Jan 18, 2023
@beat-buesser beat-buesser linked an issue Jan 18, 2023 that may be closed by this pull request
@beat-buesser beat-buesser assigned beat-buesser and unassigned f4str Jan 18, 2023
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
Signed-off-by: Farhan Ahmed <Farhan.Ahmed@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 @f4str Thank you very much for refactoring the evasion detectors, this should be very useful for many users! I also like how you made the detector tests framework independent!

@beat-buesser beat-buesser merged commit 4a8f40b into Trusted-AI:dev_1.14.0 Feb 8, 2023
@f4str f4str deleted the evasion-detector-refactor branch February 8, 2023 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improve implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Evasion Detectors
3 participants