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

Added support for Overload attack #2337

Merged
merged 17 commits into from
Jun 15, 2024

Conversation

CNOCycle
Copy link
Contributor

Description

This pull request adds the support of the Overload Attack proposed in [1].

[1] Overload: Latency Attacks on Object Detection for Edge Devices. [Paper]

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 Test
  • Notebook Example

Test Configuration:

  • OS: Ubuntu 20.04
  • Python version: 3.8.12
  • ART version or commit number: 0400813
  • PyTorch version: 1.13.1+cu116
  • cudnn version: 8302

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
  • My changes have been tested using only GPU devices

@beat-buesser beat-buesser self-requested a review November 30, 2023 15:39
@beat-buesser beat-buesser self-assigned this Nov 30, 2023
@beat-buesser beat-buesser added the enhancement New feature or request label Nov 30, 2023
@beat-buesser beat-buesser added this to the ART 1.18.0 milestone Nov 30, 2023
@beat-buesser
Copy link
Collaborator

Hi @CNOCycle Thank you very much for your pull request! Could you please change the target and rebase on to dev branch dev_1.18.0?

@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2023

Codecov Report

Attention: Patch coverage is 15.96639% with 100 lines in your changes missing coverage. Please review.

Project coverage is 77.55%. Comparing base (83f49b7) to head (7e589ee).

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff               @@
##           dev_1.18.0    #2337      +/-   ##
==============================================
- Coverage       85.66%   77.55%   -8.12%     
==============================================
  Files             327      329       +2     
  Lines           29954    30073     +119     
  Branches         5540     5173     -367     
==============================================
- Hits            25661    23322    -2339     
- Misses           2866     5449    +2583     
+ Partials         1427     1302     -125     
Files Coverage Δ
art/attacks/evasion/__init__.py 100.00% <100.00%> (ø)
art/utils.py 79.49% <ø> (-0.43%) ⬇️
art/attacks/evasion/overload/box_iou.py 20.00% <20.00%> (ø)
art/attacks/evasion/overload/overload.py 15.04% <15.04%> (ø)

... and 69 files with indirect coverage changes

@CNOCycle CNOCycle changed the base branch from main to dev_1.18.0 November 30, 2023 16:17
tests/attacks/evasion/test_overload_attack.py Fixed Show fixed Hide fixed
art/attacks/evasion/overload.py Fixed Show fixed Hide fixed
art/attacks/evasion/overload.py Fixed Show fixed Hide fixed
art/attacks/evasion/overload.py Fixed Show fixed Hide fixed
art/attacks/evasion/overload.py Fixed Show fixed Hide 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 @CNOCycle Thank you very mich for your pull request! I have added a few review requests, please let me know what you think.

@@ -0,0 +1,260 @@
# MIT License
#
# Copyright (C) The Adversarial Robustness Toolbox (ART) Authors 2018
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
# Copyright (C) The Adversarial Robustness Toolbox (ART) Authors 2018
# Copyright (C) The Adversarial Robustness Toolbox (ART) Authors 2024

"batch_size",
]

_estimator_requirements = ()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add parent classes for object detection estimators for PyTorch-specific models, similar to #2440.


def __init__(
self,
estimator: "torch.nn.Module",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add type for object detection models in PyTorch using the types to be defined in #2440 for the same purpose.

"""
Create a overload attack instance.

:param estimator: A trained YOLO5 model.
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
:param estimator: A trained YOLO5 model.
:param estimator: A PyTorch object detection estimator for a YOLO5 model.

Comment on lines 105 to 107
"""

import torch
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
"""
import torch
"""
import torch

try:
import torch
model = torch.hub.load('ultralytics/yolov5:v7.0', model='yolov5s')
x = np.random(0.0, 1.0, size=(100, 3, 640, 640))
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 check this line, should it not be np.random.normal?



@pytest.mark.only_with_platform("pytorch")
def test_check_params(art_warning):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test seems to be failing.


x_adv = attack.generate(x)

assert x.shape == x_adv.shape
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 add additional asserts to check the expected values in x_adv?

Comment on lines 129 to 131
"""

import torch
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
"""
import torch
"""
import torch

# IoU = inter / (area1 + area2 - inter)
return inter / ((a2 - a1).prod(2) + (b2 - b1).prod(2) - inter + eps)

def _check_params(self) -> None:
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 it would be very helpful if we could add a check if the provided model is a Yolo v5 model.


def __init__(
self,
estimator: PyTorchObjectDetector,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We cannot directly use the class as type definition. Could you please create or use a type definition in art/utils.py?

:param x: A given image
:return: Overload loss and the weight of each pixel
"""

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

art/utils.py Fixed Show fixed Hide fixed
@@ -225,6 +225,8 @@
PyTorchRegressor,
]

PYTORCH_OBJECT_DETECTOR_TYPE = Union[PyTorchObjectDetector] # pylint: disable=C0103

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'PYTORCH_OBJECT_DETECTOR_TYPE' is not used.
@beat-buesser beat-buesser merged commit 7e589ee into Trusted-AI:dev_1.18.0 Jun 15, 2024
26 of 33 checks passed
@beat-buesser
Copy link
Collaborator

@CNOCycle Thank you very much for your first accepted pull request to ART!

@beat-buesser beat-buesser added this to Pull request done in ART 1.18.0 Jun 16, 2024
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
ART 1.18.0
Pull request done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants