Skip to content

Commit 1244ce3

Browse files
author
Beat Buesser
committed
Fix LGTM warnings
Signed-off-by: Beat Buesser <[email protected]>
1 parent 2dc8ad6 commit 1244ce3

File tree

6 files changed

+10
-15
lines changed

6 files changed

+10
-15
lines changed

art/attacks/poisoning/gradient_matching_attack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def __initialize_poison_pytorch(
248248
x_poison: np.ndarray,
249249
y_poison: np.ndarray, # pylint: disable=unused-argument
250250
):
251-
import torch
251+
import torch # lgtm [py/import-and-import-from]
252252
from torch import nn
253253
from art.estimators.classification.pytorch import PyTorchClassifier
254254

@@ -454,7 +454,7 @@ def __poison__pytorch(self, x_poison: np.ndarray, y_poison: np.ndarray) -> Tuple
454454
:return: A pair of poisoned samples, B-score (cosine similarity of the gradients).
455455
"""
456456

457-
import torch
457+
import torch # lgtm [py/import-and-import-from]
458458

459459
device = "cuda" if torch.cuda.is_available() else "cpu"
460460

art/estimators/certification/deep_z/deep_z.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import numpy as np
2626
import torch
2727

28-
from torch import nn
29-
3028

3129
class ZonoDenseLayer(torch.nn.Module):
3230
"""
@@ -211,7 +209,7 @@ def __init__(
211209
padding: Union[int, Tuple[int, int]] = 0,
212210
):
213211
super().__init__()
214-
self.conv = nn.Conv2d(
212+
self.conv = torch.nn.Conv2d(
215213
in_channels=in_channels,
216214
out_channels=out_channels,
217215
kernel_size=kernel_size,

art/estimators/certification/deep_z/pytorch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import warnings
2727
import numpy as np
2828
import torch
29-
from torch import nn
3029

3130
from art.estimators.certification.deep_z.deep_z import ZonoConv, ZonoDenseLayer, ZonoReLU, ZonoBounds
3231
from art.estimators.classification.pytorch import PyTorchClassifier
@@ -125,7 +124,7 @@ def forward_hook(input_module, hook_input, hook_output):
125124
input_for_hook = torch.unsqueeze(input_for_hook, dim=0)
126125
model(input_for_hook) # hooks are fired sequentially from model input to the output
127126

128-
self.ops = nn.ModuleList()
127+
self.ops = torch.nn.ModuleList()
129128
for module in modules:
130129
print("registered", type(module))
131130
if isinstance(module, torch.nn.modules.conv.Conv2d):

art/preprocessing/expectation_over_transformation/image_rotation/pytorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def _check_params(self) -> None:
211211
"""For `label_type="object_detection"` only a list of multiples of 90 degrees is supported."""
212212
)
213213
if isinstance(self.angles, list):
214-
for angle in self.angles:
214+
for angle in self.angles: # lgtm [py/non-iterable-in-for-loop]
215215
if divmod(angle, 90)[1] != 0:
216216
raise ValueError(
217217
"""For `label_type="object_detection"` only a list of multiples of 90 degrees is

tests/estimators/certification/test_deepz.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import os
2121
import pytest
2222

23-
import torch
2423
import numpy as np
25-
26-
from torch import nn
24+
import torch
2725

2826
from art.utils import load_dataset
2927
from art.estimators.certification.deep_z import PytorchDeepZ
@@ -76,7 +74,7 @@ def test_mnist_certification(art_warning, fix_get_mnist_data):
7674
ptc = get_image_classifier_pt(from_logits=True, use_maxpool=False)
7775

7876
zonotope_model = PytorchDeepZ(
79-
model=ptc.model, clip_values=(0, 1), loss=nn.CrossEntropyLoss(), input_shape=(1, 28, 28), nb_classes=10
77+
model=ptc.model, clip_values=(0, 1), loss=torch.nn.CrossEntropyLoss(), input_shape=(1, 28, 28), nb_classes=10
8078
)
8179

8280
correct_upper_bounds = np.asarray(
@@ -173,7 +171,7 @@ def test_cifar_certification(art_warning, fix_get_cifar10_data):
173171

174172
ptc = get_cifar10_image_classifier_pt(from_logits=True)
175173
zonotope_model = PytorchDeepZ(
176-
model=ptc.model, clip_values=(0, 1), loss=nn.CrossEntropyLoss(), input_shape=(3, 32, 32), nb_classes=10
174+
model=ptc.model, clip_values=(0, 1), loss=torch.nn.CrossEntropyLoss(), input_shape=(3, 32, 32), nb_classes=10
177175
)
178176

179177
correct_upper_bounds = np.asarray(

tests/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def get_image_classifier_tf_v1(from_logits=False, load_init=True, sess=None):
336336

337337

338338
def get_image_generator_tf_v2(capacity: int, z_dim: int):
339-
import tensorflow as tf
339+
import tensorflow as tf # lgtm [py/import-and-import-from]
340340

341341
def make_image_generator_model(capacity: int, z_dim: int) -> tf.keras.Sequential():
342342
model = tf.keras.Sequential()
@@ -372,7 +372,7 @@ def make_image_generator_model(capacity: int, z_dim: int) -> tf.keras.Sequential
372372

373373

374374
def get_image_gan_tf_v2():
375-
import tensorflow as tf
375+
import tensorflow as tf # lgtm [py/import-and-import-from]
376376

377377
noise_dim = 100
378378
capacity = 64

0 commit comments

Comments
 (0)