Skip to content

Commit cbf4f9d

Browse files
author
Beat Buesser
committed
Changes for compatibility with Python 3.6
Signed-off-by: Beat Buesser <[email protected]>
1 parent 5b1bfdf commit cbf4f9d

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

art/attacks/evasion/laser_attack/algorithms.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def greedy_search(
5555

5656
params = adv_object_generator.random()
5757
for _ in range(iterations):
58-
predicted_class = actual_class
5958
for sign in [-1, 1]:
6059
params_prim = adv_object_generator.update_params(params, sign=sign)
6160
adversarial_image = image_generator.update_image(image, params_prim)

art/attacks/evasion/laser_attack/laser_attack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(
6868
"""
6969
:param estimator: Predictor of the image class.
7070
:param iterations: Maximum number of iterations of the algorithm.
71-
:param laser_generator: Object responsible for generation laser beams images and their updation.
71+
:param laser_generator: Object responsible for generation laser beams images and their update.
7272
:param image_generator: Object responsible for image generation.
7373
:param random_initializations: How many times repeat the attack.
7474
:param optimisation_algorithm: Algorithm used to generate adversarial example. May be replaced.
@@ -280,7 +280,7 @@ def __init__(self, min_params: LaserBeam, max_params: LaserBeam, max_step: float
280280
"""
281281
:params min_params: left bound of the params range
282282
:params max_params: right bound of the params range
283-
:params max_step: maximal part of the random LaserBeam object drawed from the range.
283+
:params max_step: maximal part of the random LaserBeam object drawn from the range.
284284
"""
285285
self.min_params = min_params
286286
self.max_params = max_params

art/attacks/evasion/laser_attack/utils.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,28 @@
2020
2121
| Paper link: https://arxiv.org/abs/2103.06504
2222
"""
23-
24-
import string
2523
from abc import ABC, abstractmethod
26-
from dataclasses import dataclass
2724
from logging import Logger
2825
from pathlib import Path
26+
import string
2927
from typing import Any, Callable, List, Tuple, Union
3028

3129
import numpy as np
3230
import matplotlib.pyplot as plt
3331

3432

35-
@dataclass
3633
class Line:
3734
"""
3835
Representation of the linear function.
3936
"""
4037

41-
angle: float
42-
bias: float
38+
def __init__(self, angle: float, bias: float):
39+
"""
40+
:param angle: Angle in radian.
41+
:param bias: Bias of the angle.
42+
"""
43+
self.angle = angle
44+
self.bias = bias
4345

4446
def __call__(self, x: float) -> float:
4547
return np.math.tan(self.angle) * x + self.bias
@@ -64,14 +66,18 @@ def to_numpy(self) -> np.ndarray:
6466
return np.array([self.angle, self.bias])
6567

6668

67-
@dataclass
6869
class Range:
6970
"""
7071
Representation of mathematical range concept
7172
"""
7273

73-
left: float
74-
right: float
74+
def __init__(self, left: float, right: float):
75+
"""
76+
:param left: Left range.
77+
:param right: Right range.
78+
"""
79+
self.left = left
80+
self.right = right
7581

7682
def __contains__(self, value):
7783
return self.left <= value < self.right
@@ -256,14 +262,18 @@ def save_nrgb_image(image: np.ndarray, number=0, name_length=5, directory="attac
256262
plt.imsave(im_name, image)
257263

258264

259-
@dataclass
260265
class DebugInfo:
261266
"""
262-
Logs debug informations during attacking process.
267+
Logs debug information during attacking process.
263268
"""
264269

265-
logger: Logger
266-
artifacts_directory: str
270+
def __init__(self, logger: Logger, artifacts_directory: str):
271+
"""
272+
:param logger: Logger instance.
273+
:param artifacts_directory: Artifacts directory.
274+
"""
275+
self.logger = logger
276+
self.artifacts_directory = artifacts_directory
267277

268278
def log(self, adv_object: AdversarialObject) -> None:
269279
"""

0 commit comments

Comments
 (0)