Skip to content

Commit 9c3f572

Browse files
committed
general inclusion of pylint: disable=W0221. Updates to randomized/derandomized tools
Signed-off-by: GiulioZizzo <[email protected]>
1 parent cc441c9 commit 9c3f572

File tree

10 files changed

+14
-77
lines changed

10 files changed

+14
-77
lines changed

art/estimators/certification/derandomized_smoothing/pytorch.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,7 @@ def fit( # pylint: disable=W0221
469469
"""
470470
import torch
471471

472-
if verbose is not None:
473-
if isinstance(verbose, int):
474-
if verbose == 0:
475-
display_pb = False
476-
else:
477-
display_pb = True
478-
else:
479-
display_pb = verbose
480-
else:
481-
display_pb = False
472+
display_pb = self.process_verbose(verbose)
482473

483474
# Set model mode
484475
self._model.train(mode=training_mode)

art/estimators/certification/derandomized_smoothing/tensorflow.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,7 @@ def fit( # pylint: disable=W0221
178178
"""
179179
import tensorflow as tf
180180

181-
if verbose is not None:
182-
if isinstance(verbose, int):
183-
if verbose == 0:
184-
display_pb = False
185-
else:
186-
display_pb = True
187-
else:
188-
display_pb = verbose
189-
else:
190-
display_pb = False
181+
display_pb = self.process_verbose(verbose)
191182

192183
if self._train_step is None: # pragma: no cover
193184
if self._loss_object is None: # pragma: no cover

art/estimators/certification/randomized_smoothing/macer/pytorch.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,7 @@ class was initialised.
163163
import torch.nn.functional as F
164164
from torch.utils.data import TensorDataset, DataLoader
165165

166-
if verbose is not None:
167-
if isinstance(verbose, int):
168-
if verbose == 0:
169-
display_pb = False
170-
else:
171-
display_pb = True
172-
else:
173-
display_pb = verbose
174-
else:
175-
display_pb = self.verbose
166+
display_pb = self.process_verbose(verbose)
176167

177168
# Set model mode
178169
self._model.train(mode=training_mode)

art/estimators/certification/randomized_smoothing/macer/tensorflow.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,7 @@ class was initialised.
157157
"""
158158
import tensorflow as tf
159159

160-
if verbose is not None:
161-
if isinstance(verbose, int):
162-
if verbose == 0:
163-
display_pb = False
164-
else:
165-
display_pb = True
166-
else:
167-
display_pb = verbose
168-
else:
169-
display_pb = self.verbose
160+
display_pb = self.process_verbose(verbose)
170161

171162
if self._train_step is None: # pragma: no cover
172163
if self._optimizer is None: # pragma: no cover

art/estimators/certification/randomized_smoothing/smooth_adv/pytorch.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,7 @@ class was initialised.
179179
import torch
180180
from torch.utils.data import TensorDataset, DataLoader
181181

182-
if verbose is not None:
183-
if isinstance(verbose, int):
184-
if verbose == 0:
185-
display_pb = False
186-
else:
187-
display_pb = True
188-
else:
189-
display_pb = verbose
190-
else:
191-
display_pb = self.verbose
182+
display_pb = self.process_verbose(verbose)
192183

193184
# Set model mode
194185
self._model.train(mode=training_mode)

art/estimators/certification/randomized_smoothing/smooth_adv/tensorflow.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,7 @@ class was initialised.
174174
"""
175175
import tensorflow as tf
176176

177-
if verbose is not None:
178-
if isinstance(verbose, int):
179-
if verbose == 0:
180-
display_pb = False
181-
else:
182-
display_pb = True
183-
else:
184-
display_pb = verbose
185-
else:
186-
display_pb = self.verbose
177+
display_pb = self.process_verbose(verbose)
187178

188179
if self._train_step is None: # pragma: no cover
189180
if self._loss_object is None: # pragma: no cover

art/estimators/certification/randomized_smoothing/smooth_mix/pytorch.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,7 @@ class was initialised.
197197
import torch.nn.functional as F
198198
from torch.utils.data import TensorDataset, DataLoader
199199

200-
if verbose is not None:
201-
if isinstance(verbose, int):
202-
if verbose == 0:
203-
display_pb = False
204-
else:
205-
display_pb = True
206-
else:
207-
display_pb = verbose
208-
else:
209-
display_pb = self.verbose
200+
display_pb = self.process_verbose(verbose)
210201

211202
# Set model mode
212203
self._model.train(mode=training_mode)

art/estimators/certification/randomized_smoothing/tensorflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _predict_classifier(self, x: np.ndarray, batch_size: int, training_mode: boo
131131
def _fit_classifier(self, x: np.ndarray, y: np.ndarray, batch_size: int, nb_epochs: int, **kwargs) -> None:
132132
return TensorFlowV2Classifier.fit(self, x, y, batch_size=batch_size, nb_epochs=nb_epochs, **kwargs)
133133

134-
def fit(
134+
def fit( # pylint: disable=W0221
135135
self,
136136
x: np.ndarray,
137137
y: np.ndarray,

art/estimators/classification/pytorch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def process_verbose(self, verbose: Optional[Union[bool, int]] = None) -> bool:
388388
else:
389389
# Check if the verbose attribute is present in the current classifier
390390
if hasattr(self, "verbose"):
391-
display_pb = self.verbose
391+
display_pb = self.verbose # type: ignore
392392
# else default to False
393393
else:
394394
display_pb = False
@@ -487,7 +487,7 @@ def fit( # pylint: disable=W0221
487487
if scheduler is not None:
488488
scheduler.step()
489489

490-
def fit_generator(
490+
def fit_generator( # pylint: disable=W0221
491491
self, generator: "DataGenerator", nb_epochs: int = 20, verbose: Optional[Union[bool, int]] = None, **kwargs
492492
) -> None:
493493
"""

art/estimators/classification/tensorflow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def process_verbose(self, verbose: Optional[Union[bool, int]] = None) -> bool:
287287
else:
288288
# Check if the verbose attribute is present in the current classifier
289289
if hasattr(self, "verbose"):
290-
display_pb = self.verbose
290+
display_pb = self.verbose # type: ignore
291291
# else default to False
292292
else:
293293
display_pb = False
@@ -1024,14 +1024,14 @@ def process_verbose(self, verbose: Optional[Union[bool, int]] = None) -> bool:
10241024
else:
10251025
# Check if the verbose attribute is present in the current classifier
10261026
if hasattr(self, "verbose"):
1027-
display_pb = self.verbose
1027+
display_pb = self.verbose # type: ignore
10281028
# else default to False
10291029
else:
10301030
display_pb = False
10311031

10321032
return display_pb
10331033

1034-
def fit(
1034+
def fit( # pylint: disable=W0221
10351035
self,
10361036
x: np.ndarray,
10371037
y: np.ndarray,
@@ -1100,7 +1100,7 @@ def train_step(model, images, labels):
11001100
if scheduler is not None:
11011101
scheduler(epoch)
11021102

1103-
def fit_generator(
1103+
def fit_generator( # pylint: disable=W0221
11041104
self, generator: "DataGenerator", nb_epochs: int = 20, verbose: Optional[Union[bool, int]] = None, **kwargs
11051105
) -> None:
11061106
"""

0 commit comments

Comments
 (0)