bethgelab / foolbox

A Python toolbox to create adversarial examples that fool neural networks in PyTorch, TensorFlow, and JAX
https://foolbox.jonasrauber.de
MIT License
2.77k stars 426 forks source link

FGSM -- Strange hard-coded number #289

Closed harrywang-1523 closed 5 years ago

harrywang-1523 commented 5 years ago

https://github.com/bethgelab/foolbox/blob/c3dd8020f7bf289bc9c778eb3f8586188ee3609e/foolbox/attacks/gradient.py#L40

I am not certain if this i < 20 makes sense? I understand that after one iteration, the epsilon is updated to be a length 20 list. Nevertheless, in the first iteration, epsilons have length 1000. This hard-coded parameter seems strange to me. Shouldn't it be something like i < len(epsilons)?

jonasrauber commented 5 years ago

Repeating the line search is usually not necessary. We only added this that if the line search is already success with its smallest value (for i = 0), then we repeat it with even smaller epsilons. I generalized this to i < 20 to get higher precision relative precision of the line search for i = 1..19, i.e. when the line search is successful quite early.