Skip to content

Commit c06b59a

Browse files
committed
Fix dependencies
Signed-off-by: Beat Buesser <[email protected]>
1 parent 3e0382c commit c06b59a

File tree

8 files changed

+175
-127
lines changed

8 files changed

+175
-127
lines changed

art/attacks/evasion/steal_now_attack_later/steal_now_attack_later.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@
4242
logger = logging.getLogger(__name__)
4343

4444

45-
# tiling
4645
def _generate_tile_kernel(patch: list, mask: list, tile_size: int) -> Tuple["torch.Tensor", "torch.Tensor"]:
4746
"""
48-
Generate specific size of pertuerbed tiles from randomly selected patches.
47+
Generate specific size of perturbed tiles from randomly selected patches.
4948
50-
:param patch: Candiate patches.
49+
:param patch: Candidate patches.
5150
:param mask: Masks for each patch.
5251
:param tile_size: The size of each tile.
53-
:return: Pertuerbed tiles and corresponding maskes.
52+
:return: Perturbed tiles and corresponding masks.
5453
"""
5554
import torch
5655
import torchvision
@@ -79,7 +78,7 @@ def _generate_tile_kernel(patch: list, mask: list, tile_size: int) -> Tuple["tor
7978
min_len = height
8079

8180
if max_len > tile_size:
82-
new_len = round(min_len * tile_size / max_len)
81+
new_len = max(round(min_len * tile_size / max_len), 1)
8382
p_1 = torchvision.transforms.Resize((tile_size, new_len))(t_patch)
8483
# fix for the case that (strides - new_len) > new_len
8584
p_list = []
@@ -95,7 +94,7 @@ def _generate_tile_kernel(patch: list, mask: list, tile_size: int) -> Tuple["tor
9594
n_mask = torch.where(n_patch == 0, torch.zeros_like(n_patch), torch.ones_like(n_patch))
9695

9796
elif max_len >= tile_size / 2.0:
98-
new_len = round(min_len * (tile_size / 2.0) / max_len)
97+
new_len = max(round(min_len * (tile_size / 2.0) / max_len), 1)
9998

10099
p_list = []
101100
for _ in range(tile_size // new_len):
@@ -150,13 +149,13 @@ def _generate_tile_kernel(patch: list, mask: list, tile_size: int) -> Tuple["tor
150149

151150
def generate_tile(patches: list, masks: list, tile_size: int, scale: list) -> Tuple["torch.Tensor", "torch.Tensor"]:
152151
"""
153-
Generate different size of pertuerbed tiles from randomly selected patches.
152+
Generate different size of perturbed tiles from randomly selected patches.
154153
155-
:param patch: Candiate patches.
154+
:param patch: Candidate patches.
156155
:param mask: Masks for each patch.
157156
:param tile_size: The size of each tile.
158-
:param scale: Scale factor for various tileing size.
159-
:return: Pertuerbed tiles and corresponding maskes.
157+
:param scale: Scale factor for various tiling size.
158+
:return: Perturbed tiles and corresponding masks.
160159
"""
161160
import torch
162161

@@ -316,8 +315,8 @@ def __init__(
316315
Create a SNAL attack instance.
317316
318317
:param estimator: A trained YOLOv8 model or other models with the same output format
319-
:param candidates: The collected pateches to generate perturbations.
320-
:param collector: A callbel uses to generate patches.
318+
:param candidates: The collected patches to generate perturbations.
319+
:param collector: A callable uses to generate patches.
321320
:param eps: Maximum perturbation that the attacker can introduce.
322321
:param max_iter: The maximum number of iterations.
323322
:param num_grid: The number of grids for width and high dimension.
@@ -391,7 +390,7 @@ def _attack(self, x_adv: "torch.Tensor", x: "torch.Tensor") -> "torch.Tensor":
391390
raise ValueError("The size of the image must be divided by the number of grids")
392391
tile_size = x.shape[-1] // self.num_grid
393392

394-
# Prapare a 2D array to store the results of each grid
393+
# Prepare a 2D array to store the results of each grid
395394
buffer_depth = 5
396395
tile_mat = {}
397396
for idx_i in range(self.num_grid):
@@ -503,10 +502,10 @@ def _attack(self, x_adv: "torch.Tensor", x: "torch.Tensor") -> "torch.Tensor":
503502

504503
def _get_loss(self, pert: "torch.Tensor", epsilon: float) -> "torch.Tensor": # pylint: disable=R0201
505504
"""
506-
Calculate accumulated distance of the perturbations outside the epslion ball.
505+
Calculate accumulated distance of the perturbations outside the epsilon ball.
507506
508507
:param pert: Perturbations in the pixel space.
509-
:param epsilon: The radius of the eplion bass.
508+
:param epsilon: The radius of the epsilon bass.
510509
:return: loss.
511510
"""
512511
import torch
@@ -526,7 +525,7 @@ def _color_projection( # pylint: disable=R0201
526525
527526
:param tile: The target to convert.
528527
:param x_ref: The source data.
529-
:param epsilon: The radius of the eplion bass.
528+
:param epsilon: The radius of the epsilon bass.
530529
:return: The converted tile.
531530
"""
532531
import torch

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def image_iterator(framework, get_default_mnist_subset, default_batch_size):
210210

211211
def _get_image_iterator():
212212
if framework == "keras" or framework == "kerastf":
213-
from keras.preprocessing.image import ImageDataGenerator
213+
from tensorflow.keras.preprocessing.image import ImageDataGenerator
214214

215215
keras_gen = ImageDataGenerator(
216216
width_shift_range=0.075,

0 commit comments

Comments
 (0)