Skip to content

Commit c7f2ad0

Browse files
minhitbkBeat Buesser
authored andcommitted
apply black format
Signed-off-by: Ngoc Minh Tran <[email protected]>
1 parent 97bfa3d commit c7f2ad0

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

art/attacks/evasion/imperceptible_asr/imperceptible_asr_pytorch.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ def _forward_1st_stage(
451451

452452
# Transform data into the model input space
453453
inputs, targets, input_rates, target_sizes, batch_idx = self.estimator.preprocess_transform_model_input(
454-
x=masked_adv_input.to(self.estimator.device), y=original_output, real_lengths=real_lengths,
454+
x=masked_adv_input.to(self.estimator.device),
455+
y=original_output,
456+
real_lengths=real_lengths,
455457
)
456458

457459
# Compute real input sizes
@@ -591,7 +593,10 @@ class only supports targeted attack.
591593
return result
592594

593595
def _forward_2nd_stage(
594-
self, local_delta_rescale: "torch.Tensor", theta_batch: np.ndarray, original_max_psd_batch: np.ndarray,
596+
self,
597+
local_delta_rescale: "torch.Tensor",
598+
theta_batch: np.ndarray,
599+
original_max_psd_batch: np.ndarray,
595600
) -> "torch.Tensor":
596601
"""
597602
The forward pass of the second stage of the attack.

art/estimators/speech_recognition/pytorch_deep_speech.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ def __init__(
258258
enabled = True
259259

260260
self._model, self._optimizer = amp.initialize(
261-
models=self._model, optimizers=self._optimizer, enabled=enabled, opt_level=opt_level, loss_scale=1.0,
261+
models=self._model,
262+
optimizers=self._optimizer,
263+
enabled=enabled,
264+
opt_level=opt_level,
265+
loss_scale=1.0,
262266
)
263267

264268
def predict(
@@ -324,7 +328,7 @@ def predict(
324328
# Aggregate results
325329
result_outputs = np.zeros(
326330
shape=(x_preprocessed.shape[0], result_output_sizes.max(), results[0].shape[-1]),
327-
dtype=config.ART_NUMPY_DTYPE
331+
dtype=config.ART_NUMPY_DTYPE,
328332
)
329333

330334
for m in range(num_batch):
@@ -517,7 +521,10 @@ def fit(self, x: np.ndarray, y: np.ndarray, batch_size: int = 128, nb_epochs: in
517521
self._optimizer.step()
518522

519523
def preprocess_transform_model_input(
520-
self, x: "torch.Tensor", y: np.ndarray, real_lengths: np.ndarray,
524+
self,
525+
x: "torch.Tensor",
526+
y: np.ndarray,
527+
real_lengths: np.ndarray,
521528
) -> Tuple["torch.Tensor", "torch.Tensor", "torch.Tensor", "torch.Tensor", List]:
522529
"""
523530
Apply preprocessing and then transform the user input space into the model input space. This function is used
@@ -548,7 +555,11 @@ def preprocess_transform_model_input(
548555

549556
# Transform the input space
550557
inputs, targets, input_rates, target_sizes, batch_idx = self._transform_model_input(
551-
x=x, y=y, compute_gradient=False, tensor_input=True, real_lengths=real_lengths,
558+
x=x,
559+
y=y,
560+
compute_gradient=False,
561+
tensor_input=True,
562+
real_lengths=real_lengths,
552563
)
553564

554565
return inputs, targets, input_rates, target_sizes, batch_idx

tests/attacks/evasion/test_imperceptible_asr_pytorch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_imperceptible_asr_pytorch(art_warning, expected_values, use_amp, device
5353
[
5454
np.array(x1 * 100, dtype=ART_NUMPY_DTYPE),
5555
np.array(x2 * 100, dtype=ART_NUMPY_DTYPE),
56-
np.array(x3 * 100, dtype=ART_NUMPY_DTYPE)
56+
np.array(x3 * 100, dtype=ART_NUMPY_DTYPE),
5757
]
5858
)
5959

@@ -71,7 +71,7 @@ def test_imperceptible_asr_pytorch(art_warning, expected_values, use_amp, device
7171
pretrained_model="librispeech",
7272
device_type=device_type,
7373
use_amp=use_amp,
74-
preprocessing_defences=audio_filter
74+
preprocessing_defences=audio_filter,
7575
)
7676

7777
# Create attack

tests/estimators/speech_recognition/test_pytorch_deep_speech.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_pytorch_deep_speech(art_warning, expected_values, use_amp, device_type)
5858
[
5959
np.array(x1 * 100, dtype=ART_NUMPY_DTYPE),
6060
np.array(x2 * 100, dtype=ART_NUMPY_DTYPE),
61-
np.array(x3 * 100, dtype=ART_NUMPY_DTYPE)
61+
np.array(x3 * 100, dtype=ART_NUMPY_DTYPE),
6262
]
6363
)
6464

tests/preprocessing/test_l_filter_pytorch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_audio_filter(fir_filter, art_warning, expected_values):
4949
[
5050
np.array(x1 * 2, dtype=ART_NUMPY_DTYPE),
5151
np.array(x2 * 2, dtype=ART_NUMPY_DTYPE),
52-
np.array(x3 * 2, dtype=ART_NUMPY_DTYPE)
52+
np.array(x3 * 2, dtype=ART_NUMPY_DTYPE),
5353
]
5454
)
5555

0 commit comments

Comments
 (0)