Skip to content

Commit e13740b

Browse files
committed
ensure .detach() and .cpu() are called
Signed-off-by: David Slater <[email protected]>
1 parent 1fd1f92 commit e13740b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

art/attacks/evasion/imperceptible_asr/imperceptible_asr_pytorch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ class only supports targeted attack.
409409
for local_batch_size_idx in range(local_batch_size):
410410
if decoded_output[local_batch_size_idx] == y[local_batch_size_idx]:
411411
# Adjust the rescale coefficient
412-
max_local_delta = np.max(np.abs(local_delta[local_batch_size_idx].detach().numpy()))
412+
max_local_delta = np.max(np.abs(local_delta[local_batch_size_idx].detach().cpu().numpy()))
413413

414414
if rescale[local_batch_size_idx][0] * self.eps > max_local_delta:
415415
rescale[local_batch_size_idx] = max_local_delta / self.eps
@@ -564,7 +564,7 @@ class only supports targeted attack.
564564
if decoded_output[local_batch_size_idx] == y[local_batch_size_idx]:
565565
if loss_2nd_stage[local_batch_size_idx] < best_loss_2nd_stage[local_batch_size_idx]:
566566
# Update best loss at 2nd stage
567-
best_loss_2nd_stage[local_batch_size_idx] = loss_2nd_stage[local_batch_size_idx].numpy()
567+
best_loss_2nd_stage[local_batch_size_idx] = loss_2nd_stage[local_batch_size_idx].detach().cpu().numpy()
568568

569569
# Save the best adversarial example
570570
successful_adv_input[local_batch_size_idx] = masked_adv_input[local_batch_size_idx]

0 commit comments

Comments
 (0)