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

Set _device parameter automatically in PreprocessorPyTorch (fixes #1442) #1444

Merged
merged 6 commits into from
Dec 16, 2021

Conversation

nilakshdas
Copy link
Contributor

@nilakshdas nilakshdas commented Dec 15, 2021

Description

The _device parameter is not automatically initialized in a PreprocessorPyTorch object. It is referenced in the PreprocessorPyTorch.device property, which in turn is used in the PreprocessorPyTorch.__call__ method. This PR alleviates the requirement for child classes to set the _device parameter and reduces code redundancy.

Fixes #1442.

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

$ pytest --framework=pytorch \
    tests/defences/preprocessor \
    tests/preprocessing/audio \
    tests/preprocessing/test_standardisation_mean_std.py
================================================================= test session starts =================================================================
platform linux -- Python 3.6.9, pytest-5.4.1, py-1.11.0, pluggy-0.13.1
rootdir: /workspaces/adversarial-robustness-toolbox, inifile: setup.cfg
plugins: mock-3.2.0, pep8-1.0.6, typeguard-2.13.3, anyio-3.4.0, cov-2.10.1
collected 133 items                                                                                                                                   

tests/defences/preprocessor/test_inverse_gan.py s                                                                                               [  0%]
tests/defences/preprocessor/test_jpeg_compression.py ssssssssssssssssssssss                                                                     [ 17%]
tests/defences/preprocessor/test_mp3_compression.py ..sssssssss                                                                                 [ 25%]
tests/defences/preprocessor/test_mp3_compression_pytorch.py .......                                                                             [ 30%]
tests/defences/preprocessor/test_preprocessor.py ........                                                                                       [ 36%]
tests/defences/preprocessor/test_resample.py sssss                                                                                              [ 40%]
tests/defences/preprocessor/test_spatial_smoothing.py sssssssssssss                                                                             [ 50%]
tests/defences/preprocessor/test_spatial_smoothing_pytorch.py x......xx......                                                                   [ 61%]
tests/defences/preprocessor/test_spatial_smoothing_tensorflow.py sssssssssssssss                                                                [ 72%]
tests/defences/preprocessor/test_video_compression.py sss...                                                                                    [ 77%]
tests/defences/preprocessor/test_video_compression_pytorch.py .......                                                                           [ 82%]
tests/preprocessing/audio/test_l_filter.py sssssssss                                                                                            [ 89%]
tests/preprocessing/audio/test_l_filter_pytorch.py ssssss.                                                                                      [ 94%]
tests/preprocessing/test_standardisation_mean_std.py sss..ss                                                                                    [100%]

====================================================== 42 passed, 88 skipped, 3 xfailed in 7.77s ======================================================

Test Configuration:

  • OS: Ubuntu 18.04.4 LTS
  • Python version: Python 3.6.9
  • ART version or commit number: 4bf284b
  • PyTorch: 1.5.0

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: Nilaksh Das <nilakshdas@gatech.edu>
Signed-off-by: Nilaksh Das <nilakshdas@gatech.edu>
Signed-off-by: Nilaksh Das <nilakshdas@gatech.edu>
@lgtm-com
Copy link

lgtm-com bot commented Dec 15, 2021

This pull request introduces 1 alert when merging 5c84b3a into 09e0e19 - view on LGTM.com

new alerts:

  • 1 for Module is imported more than once

@beat-buesser beat-buesser self-requested a review December 15, 2021 10:28
@beat-buesser beat-buesser self-assigned this Dec 15, 2021
@beat-buesser beat-buesser added the improvement Improve implementation label Dec 15, 2021
@beat-buesser beat-buesser changed the base branch from main to dev_1.9.0 December 15, 2021 10:28
@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2021

Codecov Report

Merging #1444 (1377522) into dev_1.9.0 (a7c1f7b) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff              @@
##           dev_1.9.0    #1444      +/-   ##
=============================================
- Coverage      90.31%   90.27%   -0.04%     
=============================================
  Files            240      240              
  Lines          19682    19672      -10     
  Branches        3490     3490              
=============================================
- Hits           17775    17759      -16     
- Misses          1110     1114       +4     
- Partials         797      799       +2     
Impacted Files Coverage Δ
...t/defences/preprocessor/mp3_compression_pytorch.py 94.59% <100.00%> (-0.41%) ⬇️
art/defences/preprocessor/preprocessor.py 78.26% <100.00%> (+1.89%) ⬆️
...defences/preprocessor/spatial_smoothing_pytorch.py 87.65% <100.00%> (-0.45%) ⬇️
...defences/preprocessor/video_compression_pytorch.py 94.73% <100.00%> (-0.39%) ⬇️
art/preprocessing/audio/l_filter/pytorch.py 100.00% <100.00%> (ø)
.../preprocessing/standardisation_mean_std/pytorch.py 100.00% <100.00%> (ø)
art/attacks/evasion/brendel_bethge.py 86.27% <0.00%> (-1.64%) ⬇️
art/attacks/evasion/boundary.py 92.72% <0.00%> (-1.22%) ⬇️

@lgtm-com
Copy link

lgtm-com bot commented Dec 15, 2021

This pull request introduces 1 alert when merging 5c84b3a into 24d7062 - view on LGTM.com

new alerts:

  • 1 for Module is imported more than once

@beat-buesser beat-buesser added this to the ART 1.9.0 milestone Dec 15, 2021
@beat-buesser
Copy link
Collaborator

Hi @nilakshdas Thank you very much! This is a great pull request! It looks like pylint found that we can now remove some of the imports of torch but afterwards the pull request will be ready to be merged for ART 1.9.

Signed-off-by: Nilaksh Das <nilakshdas@gatech.edu>
@nilakshdas
Copy link
Contributor Author

Hi @beat-buesser, I've fixed the import issues identified by pylint. Thanks so much for your guidance in my first PR to ART!

@lgtm-com
Copy link

lgtm-com bot commented Dec 16, 2021

This pull request introduces 1 alert and fixes 4 when merging 1e0f824 into df2e613 - view on LGTM.com

new alerts:

  • 1 for Module is imported more than once

fixed alerts:

  • 4 for Module is imported more than once

Signed-off-by: Nilaksh Das <nilakshdas@gatech.edu>
@lgtm-com
Copy link

lgtm-com bot commented Dec 16, 2021

This pull request introduces 1 alert and fixes 5 when merging a7b5c93 into df2e613 - view on LGTM.com

new alerts:

  • 1 for Module is imported more than once

fixed alerts:

  • 5 for Module is imported more than once

@lgtm-com
Copy link

lgtm-com bot commented Dec 16, 2021

This pull request introduces 1 alert and fixes 5 when merging 1377522 into a7c1f7b - view on LGTM.com

new alerts:

  • 1 for Module is imported more than once

fixed alerts:

  • 5 for Module is imported more than once

@beat-buesser beat-buesser merged commit 4f41ea7 into Trusted-AI:dev_1.9.0 Dec 16, 2021
@nilakshdas nilakshdas deleted the fix-1442 branch December 16, 2021 18:29
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.

_device is not automatically initialized in PreprocessorPyTorch
3 participants