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.73k stars 422 forks source link

tf2.1 DeepFool attack errors with eagerpy implementation #552

Open marissadotter opened 4 years ago

marissadotter commented 4 years ago

HI! When implementing DeepFool L2 attack, I get an error caused by a function not being implemented in eagerpy. Is there any update on when this function will be updated, or any work-arounds to get this attack running?

I am running tensorflow 2.1, and the latest follbox 3.0.2, eagerpy 0.27.0

Here is the error output:

Traceback (most recent call last):
  File "foolbox_deepfool.py", line 67, in <module>
    adv = gen_atack(fmodel, j, attack, i, k)
  File "foolbox_deepfool.py", line 46, in gen_atack
    adversarial = attack(fmodel, ep.astensor(img), criterion, epsilons=epsilon) 
  File "/home/mdotter/.conda/envs/tf2/lib/python3.7/site-packages/foolbox/attacks/base.py", line 410, in __call__
    xp = self.run(model, x, criterion, early_stop=early_stop, **kwargs)
  File "/home/mdotter/.conda/envs/tf2/lib/python3.7/site-packages/foolbox/attacks/deepfool.py", line 129, in run
    loss_aux_and_grad = ep.value_and_grad_fn(x, loss_fun, has_aux=True)
  File "/home/mdotter/.conda/envs/tf2/lib/python3.7/site-packages/eagerpy/framework.py", line 340, in value_and_grad_fn
    return t._value_and_grad_fn(f, has_aux=has_aux)
  File "/home/mdotter/.conda/envs/tf2/lib/python3.7/site-packages/eagerpy/tensor/numpy.py", line 363, in _value_and_grad_fn
    raise NotImplementedError  # pragma: no cover
NotImplementedError
jonasrauber commented 4 years ago

Can you share some of the code you are running? I guess you are passing in NumPy arrays where Foolbox expects TensorFlow tensors (for this model), but it's hard to tell without any code.