jeromerony/fast_adversarial

how to limit the norm of the perturbation of c&w and deepfool attack

Closed this issue · 4 comments

Hi, how can I get the results of this column?
image

Hi, you can obtain this column by renorming the perturbation at 0.5 and testing the accuracy with the renormed perturbations.

So I just need to set a constraint after the perturbation has been generated.

Well, there is no "constraint" on these attacks (neither on ours) but you can manually renorm the perturbation once it is generated. Assuming delta is the perturbation (not the perturbed image) added to the batch of images contained in [0, 1], you can renorm delta to the target_norm with:

renormed_delta = torch.renorm(delta, 2, 0, target_norm)

Perturbations that have a smaller norm than target_norm will not be modified while the ones having larger norms will get renormed.

Thanks, it's useful.