Skip to content

Commit dd8ed3c

Browse files
author
Beat Buesser
committed
Fix LGTM
Signed-off-by: Beat Buesser <[email protected]>
1 parent 089b8d0 commit dd8ed3c

File tree

8 files changed

+18
-20
lines changed

8 files changed

+18
-20
lines changed

art/attacks/evasion/imperceptible_asr/imperceptible_asr_pytorch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import logging
2828
from typing import Tuple, TYPE_CHECKING
2929

30-
import torch
3130
import numpy as np
31+
import scipy
3232

3333
from art.attacks.attack import EvasionAttack
3434
from art.estimators.estimator import BaseEstimator, LossGradientsMixin, NeuralNetworkMixin
@@ -421,6 +421,7 @@ def _forward_1st_stage(
421421
- decoded_output: Transcription output.
422422
- masked_adv_input: Perturbed inputs.
423423
"""
424+
import torch # lgtm [py/repeated-import]
424425
from warpctc_pytorch import CTCLoss
425426

426427
# Compute perturbed inputs
@@ -607,7 +608,6 @@ def _compute_masking_threshold(self, x: np.ndarray) -> Tuple[np.ndarray, np.ndar
607608
:param x: Samples of shape (seq_length,).
608609
:return: A tuple of the masking threshold and the maximum psd.
609610
"""
610-
import scipy
611611
import librosa
612612

613613
# First compute the psd matrix

art/attacks/inference/membership_inference/black_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def to_cuda(x):
223223

224224
optimizer.zero_grad()
225225
outputs = self.attack_model(input1, input2)
226-
loss = loss_fn(outputs, targets.unsqueeze(1))
226+
loss = loss_fn(outputs, targets.unsqueeze(1)) # lgtm [py/call-to-non-callable]
227227

228228
loss.backward()
229229
optimizer.step()

art/defences/preprocessor/preprocessor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ class PreprocessorPyTorch(Preprocessor):
135135
Abstract base class for preprocessing defences implemented in PyTorch that support efficient preprocessor-chaining.
136136
"""
137137

138-
import torch
139-
140138
@abc.abstractmethod
141139
def forward(
142140
self, x: "torch.Tensor", y: Optional["torch.Tensor"] = None

art/defences/preprocessor/spatial_smoothing_pytorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def forward(
193193
else:
194194
# NHWC <-- NCHW
195195
x = x_nchw.permute(0, 2, 3, 1)
196-
elif x_ndim == 5:
196+
elif x_ndim == 5: # lgtm [py/redundant-comparison]
197197
if self.channels_first:
198198
# NCFHW <-- NFCHW <-- NCHW
199199
x_nfchw = x_nchw.reshape(nb_clips, clip_size, channels, height, width)

art/estimators/certification/neural_cleanse/neural_cleanse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def outlier_detection(self, x_val: np.ndarray, y_val: np.ndarray) -> List[Tuple[
284284

285285
median = np.median(l1_norms)
286286
mad = consistency_constant * np.median(np.abs(l1_norms - median))
287-
min_mad = np.abs(np.min(l1_norms) - median) / mad
287+
# min_mad = np.abs(np.min(l1_norms) - median) / mad
288288
flagged_labels = []
289289

290290
for class_idx in range(num_classes):

art/estimators/object_detection/pytorch_faster_rcnn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(
8484
:param device_type: Type of device to be used for model and tensors, if `cpu` run on CPU, if `gpu` run on GPU
8585
if available otherwise run on CPU.
8686
"""
87-
import torch
87+
import torch # lgtm [py/repeated-import]
8888

8989
# Remove in 1.5.0
9090
if channel_index == 3:
@@ -149,7 +149,7 @@ def loss_gradient(self, x: np.ndarray, y: List[Dict[str, np.ndarray]], **kwargs)
149149
- scores (Tensor[N]): the scores or each prediction.
150150
:return: Loss gradients of the same shape as `x`.
151151
"""
152-
import torch
152+
import torch # lgtm [py/repeated-import]
153153
import torchvision # lgtm [py/repeated-import]
154154

155155
self._model.train()

art/estimators/object_detection/tensorflow_faster_rcnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,5 +509,5 @@ def fit(self):
509509
def get_activations(self):
510510
raise NotImplementedError
511511

512-
def set_learning_phase(self):
512+
def set_learning_phase(self, train: bool) -> None:
513513
raise NotImplementedError

conftest.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ def image_iterator(framework, is_tf_version_2, get_default_mnist_subset, default
197197
return torch.utils.data.DataLoader(dataset=dataset, batch_size=default_batch_size, shuffle=True)
198198

199199
if framework == "mxnet":
200-
from mxnet import gluon
200+
import mxnet
201201

202-
dataset = gluon.data.dataset.ArrayDataset(x_train_mnist, y_train_mnist)
203-
return gluon.data.DataLoader(dataset, batch_size=5, shuffle=True)
202+
dataset = mxnet.gluon.data.dataset.ArrayDataset(x_train_mnist, y_train_mnist)
203+
return mxnet.gluon.data.DataLoader(dataset, batch_size=5, shuffle=True)
204204

205205
return None
206206

@@ -323,20 +323,20 @@ def _expected_values():
323323

324324
@pytest.fixture(scope="session")
325325
def get_image_classifier_mx_model():
326-
from mxnet.gluon import nn
326+
import mxnet
327327

328328
# TODO needs to be made parameterizable once Mxnet allows multiple identical models to be created in one session
329329
from_logits = True
330330

331-
class Model(nn.Block):
331+
class Model(mxnet.gluon.nn.Block):
332332
def __init__(self, **kwargs):
333333
super(Model, self).__init__(**kwargs)
334-
self.model = nn.Sequential()
334+
self.model = mxnet.gluon.nn.Sequential()
335335
self.model.add(
336-
nn.Conv2D(channels=1, kernel_size=7, activation="relu",),
337-
nn.MaxPool2D(pool_size=4, strides=4),
338-
nn.Flatten(),
339-
nn.Dense(10, activation=None,),
336+
mxnet.gluon.nn.Conv2D(channels=1, kernel_size=7, activation="relu",),
337+
mxnet.gluon.nn.MaxPool2D(pool_size=4, strides=4),
338+
mxnet.gluon.nn.Flatten(),
339+
mxnet.gluon.nn.Dense(10, activation=None,),
340340
)
341341

342342
def forward(self, x):

0 commit comments

Comments
 (0)