Trusted-AI / adversarial-robustness-toolbox

Adversarial Robustness Toolbox (ART) - Python Library for Machine Learning Security - Evasion, Poisoning, Extraction, Inference - Red and Blue Teams
https://adversarial-robustness-toolbox.readthedocs.io/en/latest/
MIT License
4.88k stars 1.17k forks source link

Divide by zero #15

Closed akshayag closed 5 years ago

akshayag commented 6 years ago

Hello,

Was running the code on CIFAR for 150 epochs and with batch size 32

Craft attack on training examples /adversarial-robustness-toolbox-master/art/attacks/deepfool.py:84: RuntimeWarning: divide by zero encountered in true_divide r = (abs(f_diff[l]) / pow(np.linalg.norm(grad_diff[l]), 2)) grad_diff[l] /adversarial-robustness-toolbox-master/art/attacks/deepfool.py:84: RuntimeWarning: invalid value encountered in multiply r = (abs(f_diff[l]) / pow(np.linalg.norm(grad_diff[l]), 2)) grad_diff[l]

ririnicolae commented 6 years ago

Hi, @akshayag! Thanks for letting us know! I'll add a small tolerance constant to avoid divide by 0 warnings.

akshayag commented 6 years ago

Please write some instructions to use other attack methods also. For example, I am getting the error when trying to run the attack CarliniL2Method

x_train_adv = adv_crafter.generate(x_train) File "/adversarial-robustness-toolbox-master/art/attacks/carlini.py", line 124, in generate assert not (self.targeted and y is None) AssertionError

Similarly, if there will be an example line for other methods also to craft the adversary.

ririnicolae commented 6 years ago

We will try to provide more examples. Meanwhile, for your current error, as per CarliniL2Method documentation, you either need to set targeted=False when creating the attack, or provide target labels y when calling generate.

akshayag commented 6 years ago

Please take a look at this error also.

Create VirtualAdversarialMethod attack

Craft attack on training examples /adversarial-robustness-toolbox-master/art/attacks/virtual_adversarial.py:91: RuntimeWarning: invalid value encountered in float_scalars d_new[array_iter.multi_index] = (kl_div2 - kl_div1) / self.finite_diff /adversarial-robustness-toolbox-master/art/attacks/virtual_adversarial.py:116: RuntimeWarning: invalid value encountered in multiply x = x * inverse

ririnicolae commented 6 years ago

@akshayag Fix for both divide by 0 issues is pushed. Please confirm that the warning is gone.