Skip to content

Commit 5914d23

Browse files
author
Beat Buesser
committed
Apply Black formatter
Signed-off-by: Beat Buesser <[email protected]>
1 parent 377923a commit 5914d23

File tree

5 files changed

+10
-34
lines changed

5 files changed

+10
-34
lines changed

art/attacks/evasion/imperceptible_asr/imperceptible_asr_pytorch.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,7 @@ def _forward_1st_stage(
464464

465465
# Transform data into the model input space
466466
inputs, targets, input_rates, target_sizes, batch_idx = self.estimator.preprocess_transform_model_input(
467-
x=masked_adv_input.to(self.estimator.device),
468-
y=original_output,
469-
real_lengths=real_lengths,
467+
x=masked_adv_input.to(self.estimator.device), y=original_output, real_lengths=real_lengths,
470468
)
471469

472470
# Compute real input sizes
@@ -606,10 +604,7 @@ class only supports targeted attack.
606604
return result
607605

608606
def _forward_2nd_stage(
609-
self,
610-
local_delta_rescale: "torch.Tensor",
611-
theta_batch: np.ndarray,
612-
original_max_psd_batch: np.ndarray,
607+
self, local_delta_rescale: "torch.Tensor", theta_batch: np.ndarray, original_max_psd_batch: np.ndarray,
613608
) -> "torch.Tensor":
614609
"""
615610
The forward pass of the second stage of the attack.
@@ -667,7 +662,7 @@ def _compute_masking_threshold(self, x: np.ndarray) -> Tuple[np.ndarray, np.ndar
667662

668663
psd = abs(transformed_x / win_length)
669664
original_max_psd = np.max(psd * psd)
670-
with np.errstate(divide='ignore'):
665+
with np.errstate(divide="ignore"):
671666
psd = (20 * np.log10(psd)).clip(min=-200)
672667
psd = 96 - np.max(psd) + psd
673668

art/estimators/speech_recognition/pytorch_deep_speech.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,7 @@ def __init__(
256256
enabled = True
257257

258258
self._model, self._optimizer = amp.initialize(
259-
models=self._model,
260-
optimizers=self._optimizer,
261-
enabled=enabled,
262-
opt_level=opt_level,
263-
loss_scale=1.0,
259+
models=self._model, optimizers=self._optimizer, enabled=enabled, opt_level=opt_level, loss_scale=1.0,
264260
)
265261

266262
def predict(
@@ -522,10 +518,7 @@ def fit(self, x: np.ndarray, y: np.ndarray, batch_size: int = 128, nb_epochs: in
522518
self._optimizer.step()
523519

524520
def preprocess_transform_model_input(
525-
self,
526-
x: "torch.Tensor",
527-
y: np.ndarray,
528-
real_lengths: np.ndarray,
521+
self, x: "torch.Tensor", y: np.ndarray, real_lengths: np.ndarray,
529522
) -> Tuple["torch.Tensor", "torch.Tensor", "torch.Tensor", "torch.Tensor", List]:
530523
"""
531524
Apply preprocessing and then transform the user input space into the model input space. This function is used
@@ -556,11 +549,7 @@ def preprocess_transform_model_input(
556549

557550
# Transform the input space
558551
inputs, targets, input_rates, target_sizes, batch_idx = self._transform_model_input(
559-
x=x,
560-
y=y,
561-
compute_gradient=False,
562-
tensor_input=True,
563-
real_lengths=real_lengths,
552+
x=x, y=y, compute_gradient=False, tensor_input=True, real_lengths=real_lengths,
564553
)
565554

566555
return inputs, targets, input_rates, target_sizes, batch_idx

tests/estimators/classification/test_blackbox.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ def test_repr(self):
9090
self.assertIn("BlackBoxClassifier", repr_)
9191
self.assertIn("clip_values=[ 0. 255.]", repr_)
9292
self.assertIn("defences=None", repr_)
93-
self.assertIn(
94-
"preprocessing=StandardisationMeanStd(mean=0, std=1, apply_fit=True, apply_predict=True)", repr_
95-
)
93+
self.assertIn("preprocessing=StandardisationMeanStd(mean=0, std=1, apply_fit=True, apply_predict=True)", repr_)
9694

9795

9896
if __name__ == "__main__":

tests/estimators/classification/test_classifier.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ def test_repr(self):
117117
self.assertIn("ClassifierInstance", repr_)
118118
self.assertIn("clip_values=None", repr_)
119119
self.assertIn("defences=None", repr_)
120-
self.assertIn(
121-
"preprocessing=StandardisationMeanStd(mean=0, std=1, apply_fit=True, apply_predict=True)", repr_
122-
)
120+
self.assertIn("preprocessing=StandardisationMeanStd(mean=0, std=1, apply_fit=True, apply_predict=True)", repr_)
123121

124122

125123
class TestClassifierNeuralNetwork(TestBase):
@@ -146,9 +144,7 @@ def test_repr(self):
146144
self.assertIn(f"channel_index={Deprecated}, channels_first=True", repr_)
147145
self.assertIn("clip_values=[0. 1.]", repr_)
148146
self.assertIn("defences=None", repr_)
149-
self.assertIn(
150-
"preprocessing=StandardisationMeanStd(mean=0, std=1, apply_fit=True, apply_predict=True)", repr_
151-
)
147+
self.assertIn("preprocessing=StandardisationMeanStd(mean=0, std=1, apply_fit=True, apply_predict=True)", repr_)
152148

153149

154150
if __name__ == "__main__":

tests/estimators/classification/test_detector_classifier.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ def test_save(self):
167167
def test_repr(self):
168168
repr_ = repr(self.detector_classifier)
169169
self.assertIn("art.estimators.classification.detector_classifier.DetectorClassifier", repr_)
170-
self.assertIn(
171-
"preprocessing=StandardisationMeanStd(mean=0, std=1, apply_fit=True, apply_predict=True)", repr_
172-
)
170+
self.assertIn("preprocessing=StandardisationMeanStd(mean=0, std=1, apply_fit=True, apply_predict=True)", repr_)
173171

174172

175173
if __name__ == "__main__":

0 commit comments

Comments
 (0)