Skip to content

Commit eadc651

Browse files
authored
Merge pull request #1446 from Trusted-AI/development_maintenance_190
Code maintenance updates for ART 1.9.0
2 parents 16e84e4 + cbf4f9d commit eadc651

File tree

20 files changed

+116
-45
lines changed

20 files changed

+116
-45
lines changed

art/attacks/evasion/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from art.attacks.evasion.imperceptible_asr.imperceptible_asr import ImperceptibleASR
2929
from art.attacks.evasion.imperceptible_asr.imperceptible_asr_pytorch import ImperceptibleASRPyTorch
3030
from art.attacks.evasion.iterative_method import BasicIterativeMethod
31+
from art.attacks.evasion.laser_attack.laser_attack import LaserAttack
3132
from art.attacks.evasion.lowprofool import LowProFool
3233
from art.attacks.evasion.newtonfool import NewtonFool
3334
from art.attacks.evasion.pe_malware_attack import MalwareGDTensorFlow

art/attacks/evasion/adversarial_texture/adversarial_texture_pytorch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def generate( # type: ignore # pylint: disable=W0222
324324
:param x: Input videos of shape NFHWC.
325325
:param y: True labels of format `List[Dict[str, np.ndarray]]`, one dictionary for each input image. The keys of
326326
the dictionary are:
327+
327328
- boxes [N_FRAMES, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
328329
0 <= y1 < y2 <= H.
329330

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

art/attacks/inference/membership_inference/label_only_boundary_distance.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"""
1919
This module implements the Label-Only Inference Attack based on Decision Boundary.
2020
21-
| Paper link: https://arxiv.org/abs/2007.14321 (Choquette-Choo et al.) and https://arxiv.org/abs/2007.15528 (Li and
22-
Zhang)
21+
| Paper link: https://arxiv.org/abs/2007.14321 (Choquette-Choo et al.)
22+
| Paper link: https://arxiv.org/abs/2007.15528 (Li and Zhang)
2323
"""
2424
import logging
2525
from typing import Optional, TYPE_CHECKING
@@ -41,10 +41,10 @@ class LabelOnlyDecisionBoundary(MembershipInferenceAttack):
4141
"""
4242
Implementation of Label-Only Inference Attack based on Decision Boundary.
4343
44-
| Paper link: https://arxiv.org/abs/2007.14321 (Choquette-Choo et al.) and https://arxiv.org/abs/2007.15528 (Li
45-
and Zhang)
46-
4744
You only need to call ONE of the calibrate methods, depending on which attack you want to launch.
45+
46+
| Paper link: https://arxiv.org/abs/2007.14321 (Choquette-Choo et al.)
47+
| Paper link: https://arxiv.org/abs/2007.15528 (Li and Zhang)
4848
"""
4949

5050
attack_params = MembershipInferenceAttack.attack_params + [
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""
22
Module containing estimators for object tracking.
33
"""
4+
from art.estimators.object_tracking.object_tracker import ObjectTrackerMixin
5+
46
from art.estimators.object_tracking.pytorch_goturn import PyTorchGoturn

art/estimators/poison_mitigation/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
"""
44
from art.estimators.poison_mitigation import neural_cleanse
55
from art.estimators.poison_mitigation.strip import strip
6+
from art.estimators.poison_mitigation.neural_cleanse.keras import KerasNeuralCleanse
7+
from art.estimators.poison_mitigation.strip.strip import STRIPMixin

conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def _get_image_iterator():
235235
return dataset
236236

237237
if framework == "pytorch":
238-
import torch
238+
import torch # lgtm [py/repeated-import]
239239

240240
# Create tensors from data
241241
x_train_tens = torch.from_numpy(x_train_mnist)
@@ -946,7 +946,7 @@ def __init__(self):
946946
preprocessing=(0, 1),
947947
)
948948

949-
import torch
949+
import torch # lgtm [py/repeated-import]
950950

951951
self.channels_first = False
952952
self._input_shape = None
169 KB
Loading

0 commit comments

Comments
 (0)