Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5ec65e0
Support SNAL attack
CNOCycle Apr 28, 2024
49f45fd
Remove unused variables
CNOCycle May 28, 2024
3d35aaf
Update licence and docstrings
CNOCycle May 28, 2024
136368e
Separate files with different licenses
CNOCycle May 28, 2024
3489e5a
Fix for missing parts
CNOCycle Jun 28, 2024
73bcb96
Refine set_candidates
CNOCycle Jun 28, 2024
3202d72
Add a param collector
CNOCycle Jun 28, 2024
7b881b8
Refine SNAL
CNOCycle Jun 28, 2024
4771a7d
Add _check_params function
CNOCycle Jul 1, 2024
1b02ba9
Add unittest
CNOCycle Jul 1, 2024
6416773
Update notebook
CNOCycle Jul 1, 2024
3be3f55
Support YOLOv8
CNOCycle Jul 2, 2024
21b304c
Refine vthe ersion checker
CNOCycle Jul 2, 2024
8d2f72b
Format coding style
CNOCycle Jul 2, 2024
2f86987
ormat coding style
CNOCycle Jul 19, 2024
23e3a1b
Format coding style
CNOCycle Jul 20, 2024
3cf0320
Fix for Warning C0325
CNOCycle Jul 29, 2024
03283a2
Fix for Warning C0103
CNOCycle Jul 31, 2024
646e605
Fix for coding style
CNOCycle Jul 31, 2024
8076822
Fix for the interface
CNOCycle Jul 31, 2024
14c0a8b
Fix for coding style by black
CNOCycle Jul 31, 2024
4c5dc96
Fix for warnings reported by the pylint
CNOCycle Jul 31, 2024
181bc3a
Fix for typos
CNOCycle Aug 6, 2024
2e0c6d9
Resolve errors reported by the mypy
CNOCycle Aug 6, 2024
33b63ad
Fix for error: wrong-import-order
CNOCycle Aug 6, 2024
5294b3f
Fix for missing image
CNOCycle Sep 9, 2024
84e3522
Fix for coding style
CNOCycle Sep 9, 2024
69c4361
Update testing code
CNOCycle Sep 11, 2024
6980c62
Fix for AttributeError
CNOCycle Sep 11, 2024
693e545
Fix for coding style
CNOCycle Sep 11, 2024
d27f500
Add a flag to be used for marking the YOLOv8 model
CNOCycle Sep 14, 2024
38b03c6
Fix for an import error caused by ultralytics
CNOCycle Sep 20, 2024
492a6ce
Set more relaxed test thresholds
CNOCycle Sep 20, 2024
ce3aec7
Merge branch 'dev_1.19.0' into attack/snal
beat-buesser Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions art/attacks/evasion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
from art.attacks.evasion.shapeshifter import ShapeShifter
from art.attacks.evasion.simba import SimBA
from art.attacks.evasion.spatial_transformation import SpatialTransformation
from art.attacks.evasion.steal_now_attack_later.steal_now_attack_later import SNAL
from art.attacks.evasion.square_attack import SquareAttack
from art.attacks.evasion.pixel_threshold import ThresholdAttack
from art.attacks.evasion.universal_perturbation import UniversalPerturbation
Expand Down
Empty file.
698 changes: 698 additions & 0 deletions art/attacks/evasion/steal_now_attack_later/bbox_ioa.py

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions art/attacks/evasion/steal_now_attack_later/drop_block2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# pylint: disable=C0114
# BSD 3-Clause License
#
# Copyright (c) Soumith Chintala 2016,
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
import torch


def drop_block2d(x: "torch.Tensor", prob: float, block_size: int):
"""
=== NOTE ===
This function is modified from torchvision (torchvision/ops/drop_block.py)
BSD 3-Clause License
=== ==== ===
:param x (Tensor[N, C, H, W]): The input tensor or 4-dimensions with the first one
being its batch i.e. a batch with ``N`` rows.
:param prob (float): Probability of an element to be dropped.
:param block_size (int): Size of the block to drop.

:return: Tensor[N, C, H, W]: The mask of activate pixels.
"""
import torch

if prob < 0.0 or prob > 1.0:
raise ValueError(f"drop probability has to be between 0 and 1, but got {prob}.")

Check warning on line 54 in art/attacks/evasion/steal_now_attack_later/drop_block2d.py

View check run for this annotation

Codecov / codecov/patch

art/attacks/evasion/steal_now_attack_later/drop_block2d.py#L54

Added line #L54 was not covered by tests
if x.ndim != 4:
raise ValueError(f"input should be 4 dimensional. Got {x.ndim} dimensions.")

Check warning on line 56 in art/attacks/evasion/steal_now_attack_later/drop_block2d.py

View check run for this annotation

Codecov / codecov/patch

art/attacks/evasion/steal_now_attack_later/drop_block2d.py#L56

Added line #L56 was not covered by tests

N, _, H, W = x.size() # pylint: disable=C0103
block_size = min(block_size, W, H)
# compute the gamma of Bernoulli distribution
gamma = (prob * H * W) / ((block_size**2) * ((H - block_size + 1) * (W - block_size + 1)))
noise = torch.empty((N, 1, H - block_size + 1, W - block_size + 1), dtype=x.dtype, device=x.device)
noise.bernoulli_(gamma)

noise = torch.nn.functional.pad(noise, [block_size // 2] * 4, value=0)
noise = torch.nn.functional.max_pool2d(
noise, stride=(1, 1), kernel_size=(block_size, block_size), padding=block_size // 2
)
mask = 1 - noise
return mask
Loading