Skip to content

Commit e435ec6

Browse files
author
Beat Buesser
committed
Fix LGTM alerts
Signed-off-by: Beat Buesser <[email protected]>
1 parent d81dde9 commit e435ec6

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

art/attacks/evasion/hop_skip_jump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from __future__ import absolute_import, division, print_function, unicode_literals
2525

2626
import logging
27-
from typing import Optional, Tuple, Union, List, TYPE_CHECKING
27+
from typing import Optional, Tuple, Union, TYPE_CHECKING
2828

2929
import numpy as np
3030
from tqdm import tqdm

art/attacks/evasion/imperceptible_asr/imperceptible_asr.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def _create_adversarial(self, x, y) -> np.ndarray:
194194
x_adversarial = [None] * batch_size
195195

196196
x_perturbed = x.copy()
197-
perturbation = np.zeros_like(x_perturbed)
198197

199198
for i in range(self.max_iter_1):
200199
# perform FGSM step for x

art/estimators/certification/randomized_smoothing/numpy.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import numpy as np
2626

27+
from art.estimators.estimator import BaseEstimator
2728
from art.estimators.certification.randomized_smoothing.randomized_smoothing import RandomizedSmoothingMixin
2829
from art.estimators.classification import ClassifierMixin, ClassGradientsMixin
2930
import logging
@@ -35,7 +36,7 @@
3536
logger = logging.getLogger(__name__)
3637

3738

38-
class NumpyRandomizedSmoothing(RandomizedSmoothingMixin, ClassGradientsMixin, ClassifierMixin):
39+
class NumpyRandomizedSmoothing(RandomizedSmoothingMixin, ClassGradientsMixin, ClassifierMixin, BaseEstimator):
3940
"""
4041
Implementation of Randomized Smoothing applied to classifier predictions and gradients, as introduced
4142
in Cohen et al. (2019).
@@ -53,12 +54,20 @@ def __init__(
5354
:param scale: Standard deviation of Gaussian noise added.
5455
:param alpha: The failure probability of smoothing
5556
"""
56-
super().__init__(classifier)
57+
super().__init__(
58+
model=None,
59+
input_shape=classifier.input_shape,
60+
nb_classes=classifier.nb_classes,
61+
channels_first=classifier.channels_first,
62+
clip_values=classifier.clip_values,
63+
preprocessing_defences=classifier.preprocessing_defences,
64+
postprocessing_defences=classifier.postprocessing_defences,
65+
preprocessing=classifier.preprocessing,
66+
sample_size=sample_size,
67+
scale=scale,
68+
alpha=alpha,
69+
)
5770
self.classifier = classifier
58-
self._nb_classes = classifier.nb_classes
59-
self.sample_size = sample_size
60-
self.scale = scale
61-
self.alpha = alpha
6271

6372
def _predict_classifier(self, x: np.ndarray, batch_size: int) -> np.ndarray:
6473
"""

conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
def get_default_framework():
5252
import tensorflow as tf
5353

54-
default_framework = "tensorflow"
55-
5654
if tf.__version__[0] == "2":
5755
default_framework = "tensorflow2"
5856
else:
@@ -343,7 +341,7 @@ def _expected_values():
343341

344342
@pytest.fixture(scope="session")
345343
def get_image_classifier_mx_model():
346-
import mxnet
344+
import mxnet # lgtm [py/import-and-import-from]
347345

348346
# TODO needs to be made parameterizable once Mxnet allows multiple identical models to be created in one session
349347
from_logits = True
@@ -374,7 +372,7 @@ def forward(self, x):
374372

375373
@pytest.fixture
376374
def get_image_classifier_mx_instance(get_image_classifier_mx_model, mnist_shape):
377-
import mxnet
375+
import mxnet # lgtm [py/import-and-import-from]
378376
from art.estimators.classification import MXClassifier
379377

380378
model = get_image_classifier_mx_model

0 commit comments

Comments
 (0)