Skip to content

Commit

Permalink
Apply Black formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Beat Buesser <[email protected]>
  • Loading branch information
Beat Buesser committed Aug 7, 2020
1 parent 7e5ccb4 commit 3d06512
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions art/attacks/evasion/deepfool.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ def generate(self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs) -> n

# Compute perturbation with implicit batching
for batch_id in trange(
int(np.ceil(x_adv.shape[0] / float(self.batch_size))),
desc="DeepFool",
disable=not self.verbose):
int(np.ceil(x_adv.shape[0] / float(self.batch_size))), desc="DeepFool", disable=not self.verbose
):
batch_index_1, batch_index_2 = batch_id * self.batch_size, (batch_id + 1) * self.batch_size
batch = x_adv[batch_index_1:batch_index_2].copy()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def _apply_perturbation(self, x: "torch.Tensor", perturbation: "torch.Tensor", e
clip_min, clip_max = self.estimator.clip_values
x = torch.max(
torch.min(x, torch.tensor(clip_max).to(self.estimator.device)),
torch.tensor(clip_min).to(self.estimator.device)
torch.tensor(clip_min).to(self.estimator.device),
)

return x
Expand Down Expand Up @@ -328,7 +328,7 @@ def _compute_torch(
clip_min, clip_max = self.estimator.clip_values
x_adv = torch.max(
torch.min(x_adv, torch.tensor(clip_max).to(self.estimator.device)),
torch.tensor(clip_min).to(self.estimator.device)
torch.tensor(clip_min).to(self.estimator.device),
)

else:
Expand Down
4 changes: 2 additions & 2 deletions art/defences/preprocessor/mp3_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def wav_to_mp3(x, sample_rate):
elif x.dtype != np.int16 and normalized:
# x is not of type np.int16 and seems to be normalized. Therefore undoing normalization and
# casting to np.int16.
x = (x * 2**15).astype(np.int16)
x = (x * 2 ** 15).astype(np.int16)

tmp_wav, tmp_mp3 = BytesIO(), BytesIO()
write(tmp_wav, sample_rate, x)
Expand All @@ -134,7 +134,7 @@ def wav_to_mp3(x, sample_rate):

if normalized:
# x was normalized. Therefore normalizing x_mp3.
x_mp3 = x_mp3 * 2**-15
x_mp3 = x_mp3 * 2 ** -15
return x_mp3

if x.ndim != 3:
Expand Down
2 changes: 1 addition & 1 deletion tests/attacks/test_wasserstein.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def set_learning_phase(self):
kernel_size=3,
max_iter=1,
conjugate_sinkhorn_max_iter=10,
projected_sinkhorn_max_iter=10
projected_sinkhorn_max_iter=10,
)

x = np.random.normal(size=(1, 3, 33, 32))
Expand Down

0 comments on commit 3d06512

Please sign in to comment.