how to limit the norm of the perturbation of c&w and deepfool attack
Closed this issue · 4 comments
xiahaifeng1995 commented
jeromerony commented
Hi, you can obtain this column by renorming the perturbation at 0.5 and testing the accuracy with the renormed perturbations.
xiahaifeng1995 commented
So I just need to set a constraint after the perturbation has been generated.
jeromerony commented
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.
xiahaifeng1995 commented
Thanks, it's useful.