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

Open
wants to merge 1 commit into
base: dev_1.18.0
Choose a base branch
from

Conversation

CNOCycle
Copy link

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

Merging #2337 (39f7587) into dev_1.18.0 (0400813) will decrease coverage by 15.73%.
The diff coverage is 15.38%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##           dev_1.18.0    #2337       +/-   ##
===============================================
- Coverage       85.60%   69.87%   -15.73%     
===============================================
  Files             324      325        +1     
  Lines           29326    29443      +117     
  Branches         5407     5426       +19     
===============================================
- Hits            25104    20574     -4530     
- Misses           2840     7674     +4834     
+ Partials         1382     1195      -187     
Files Coverage Δ
art/attacks/evasion/__init__.py 98.24% <100.00%> (+0.03%) ⬆️
art/attacks/evasion/overload.py 14.65% <14.65%> (ø)

... and 83 files with indirect coverage changes

@CNOCycle CNOCycle changed the base branch from main to dev_1.18.0 November 30, 2023 16:17
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))

Check failure

Code scanning / CodeQL

Non-callable called Error

Call to a
non-callable
of
builtin-class module
.

idx_min = torch.argmin(scores)
grid_min = grid_box[idx_min]
x1, y1, x2, y2 = grid_min.int()

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable x1 is not used.

idx_min = torch.argmin(scores)
grid_min = grid_box[idx_min]
x1, y1, x2, y2 = grid_min.int()

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable y1 is not used.

idx_min = torch.argmin(scores)
grid_min = grid_box[idx_min]
x1, y1, x2, y2 = grid_min.int()

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable x2 is not used.

idx_min = torch.argmin(scores)
grid_min = grid_box[idx_min]
x1, y1, x2, y2 = grid_min.int()

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable y2 is not used.
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.

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
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

3 participants