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

Fix AdversarialPatchPyTorch compatibility with YOLO estimator #2169

Merged
merged 8 commits into from
Jun 27, 2023

Conversation

kieranfraser
Copy link
Collaborator

@kieranfraser kieranfraser commented May 29, 2023

Description

  • Updating the format of targets passed to the estimator in AdversarialPatchPyTorch to reflect updates to PyTorchYolo.
  • Fix for getting gradients from input tensor in PyTorchYolo.
  • Adding a test in tests/estimators/object_detection/test_pytorch_yolo.py to check that adversarial patches work with the estimator.

Fixes #2148

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.

  • test_patch - added a test in test_pytorch_yolo.py to verify that AdversarialPatchPyTorch works with the YOLO estimator

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

@codecov-commenter
Copy link

codecov-commenter commented May 29, 2023

Codecov Report

Merging #2169 (c67cd57) into dev_1.15.0 (28a3f8c) will decrease coverage by 7.56%.
The diff coverage is 50.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Impacted file tree graph

@@              Coverage Diff               @@
##           dev_1.15.0    #2169      +/-   ##
==============================================
- Coverage       85.66%   78.10%   -7.56%     
==============================================
  Files             306      306              
  Lines           27022    27026       +4     
  Branches         4962     4965       +3     
==============================================
- Hits            23148    21109    -2039     
- Misses           2602     4756    +2154     
+ Partials         1272     1161     -111     
Impacted Files Coverage Δ
...ion/adversarial_patch/adversarial_patch_pytorch.py 57.37% <36.36%> (-7.15%) ⬇️
art/estimators/object_detection/pytorch_yolo.py 82.24% <100.00%> (+1.58%) ⬆️

... and 30 files with indirect coverage changes

@beat-buesser beat-buesser self-requested a review June 9, 2023 09:29
@beat-buesser beat-buesser self-assigned this Jun 9, 2023
@beat-buesser beat-buesser added bug Something isn't working improvement Improve implementation labels Jun 9, 2023
@beat-buesser beat-buesser added this to Pull request open in ART 1.15.0 via automation Jun 9, 2023
@beat-buesser beat-buesser added this to the ART 1.15.0 milestone Jun 9, 2023
…yTorch, updating notebook

Signed-off-by: Kieran Fraser <Kieran.Fraser@ibm.com>
…yTorch, updating notebook

Signed-off-by: Kieran Fraser <Kieran.Fraser@ibm.com>
…lpha in python yolo libraries. Adding test for adversarial patch

Signed-off-by: Kieran Fraser <Kieran.Fraser@ibm.com>
Signed-off-by: Kieran Fraser <Kieran.Fraser@ibm.com>
@@ -367,7 +367,7 @@ def test_compute_loss(art_warning, get_pytorch_yolo):
# Compute loss
loss = object_detector.compute_loss(x=x_test, y=y_test)

assert pytest.approx(11.20741, abs=0.9) == float(loss)
assert pytest.approx(11.20741, abs=1.5) == float(loss)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

YOLO generates inconsistent loss for the same input. Fix is to freeze batch_norm and drop_out layers. However freezing these layers results in compute_loss returning NaN for some inputs due to a known issue in the python YOLO library. See #2148 for detail.

Signed-off-by: Kieran Fraser <Kieran.Fraser@ibm.com>
@kieranfraser kieranfraser marked this pull request as ready for review June 14, 2023 09:06
@kieranfraser kieranfraser changed the base branch from main to dev_1.15.0 June 14, 2023 15:30
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 @kieranfraser Thank you very much! The changes look good to me.

@beat-buesser beat-buesser merged commit 8cb3607 into Trusted-AI:dev_1.15.0 Jun 27, 2023
37 checks passed
ART 1.15.0 automation moved this from Pull request open to Pull request done Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working improvement Improve implementation
Projects
No open projects
ART 1.15.0
Pull request done
Development

Successfully merging this pull request may close these issues.

Error in **attack_adversarial_patch_pytorch_yolo.ipynb**
3 participants