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 PyTorch Object Detection Estimators Missing Gradients Bug #2249

Merged
merged 2 commits into from
Aug 18, 2023

Conversation

f4str
Copy link
Collaborator

@f4str f4str commented Aug 17, 2023

Description

When a non-leaf tensor is moved to another device, the gradient retention property is lost and needs to be manually set again. This PR adds this minor change to both the PyTorchObjectDetector and PyTorchYolo estimators.

Fixes #2248

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.

  • Tests for PyTorchObjectDetector are unchanged
  • Tests for PyTorchFasterRCNN are unchanged

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>
@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2023

Codecov Report

Merging #2249 (4650875) into dev_1.15.1 (52c240a) will decrease coverage by 0.01%.
The diff coverage is 66.66%.

❗ 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.1    #2249      +/-   ##
==============================================
- Coverage       85.62%   85.62%   -0.01%     
==============================================
  Files             308      308              
  Lines           27470    27476       +6     
  Branches         5046     5048       +2     
==============================================
+ Hits            23522    23526       +4     
- Misses           2668     2669       +1     
- Partials         1280     1281       +1     
Files Changed Coverage Δ
...mators/object_detection/pytorch_object_detector.py 84.65% <33.33%> (-0.90%) ⬇️
art/estimators/object_detection/pytorch_yolo.py 82.48% <100.00%> (+0.24%) ⬆️

Signed-off-by: Farhan Ahmed <Farhan.Ahmed@ibm.com>
@f4str f4str changed the title Fix PyTorchObjectDetector Missing Gradients Bug Fix PyTorch Object Detection Estimators Missing Gradients Bug Aug 17, 2023
@beat-buesser
Copy link
Collaborator

Hi @f4str Thank you for your pull request. In #2238 we made the same change also in method PyTorchObjectDetector._preprocess_and_convert_inputs. Is the same change also needed in PyTorchYolo._preprocess_and_convert_inputs?

@beat-buesser beat-buesser self-requested a review August 18, 2023 09:04
@beat-buesser beat-buesser self-assigned this Aug 18, 2023
@beat-buesser beat-buesser added bug Something isn't working improvement Improve implementation labels Aug 18, 2023
@beat-buesser beat-buesser added this to the ART 1.15.1 milestone Aug 18, 2023
@beat-buesser beat-buesser linked an issue Aug 18, 2023 that may be closed by this pull request
@f4str
Copy link
Collaborator Author

f4str commented Aug 18, 2023

Hi @beat-buesser the previous change in #2238 addressed a different bug that only occured for the PyTorchObjectDetector that was bug was already addressed for the PyTorchYolo in #2169. The PR applied the same fix.

This is a separate bug-fix independent from both #2238 and #2169 that affects both the PyTorchObjectDetector and PyTorchYolo. The code solution looks similar, but it's a different fix.

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 noticing and fixing this bug!

@beat-buesser beat-buesser merged commit 0a01458 into Trusted-AI:dev_1.15.1 Aug 18, 2023
@f4str f4str deleted the pytorch-frcnn-loss-fix branch August 18, 2023 21:01
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
None yet
Development

Successfully merging this pull request may close these issues.

DPatch Attack Error in PyTorchObjectDetector
3 participants