perceptual-advex
perceptual-advex copied to clipboard
A mistake which may lead to performance degradation
https://github.com/cassidylaidlaw/perceptual-advex/blob/70af18f174a269ed17368116b41e59e10cad0195/perceptual_advex/perceptual_attacks.py#L623
We should update "perturbations" after we update "live". Otherwise, some samples which already meet the requirements will still be updated through https://github.com/cassidylaidlaw/perceptual-advex/blob/70af18f174a269ed17368116b41e59e10cad0195/perceptual_advex/perceptual_attacks.py#L633
You can try to replace line 612-627 in perceptual-advex/perceptual_advex/perceptual_attacks.py with the following:
updates = torch.zeros_like(inputs)
updates[live] = -grad_normed * (
step_size / (dist_grads + 1e-8)
)[:, None, None, None]
if self.random_targets:
live[live] = (adv_labels != labels[live]) | (lpips_dists > self.bound)
else:
live[live] = (adv_labels == labels[live]) | (lpips_dists > self.bound)
if live.sum() == 0:
break
perturbations.data[live] = (
(inputs[live] + perturbations[live] +
updates[live]).clamp(0, 1) -
inputs[live]
).detach()
Thanks for finding this! I'm going to run some experiments with your suggested change and check what the results are, then I'll commit it to the repo.