Skip to content

Commit 50d18ff

Browse files
Irina NicolaeIrina Nicolae
authored andcommitted
Avoid division by 0 in NewtonFool
1 parent c986b96 commit 50d18ff

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

art/attacks/newtonfool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ def _compute_pert(theta, grads, norm_grad):
119119
:param norm_grad: norm of gradient values at the attacked class.
120120
:return: pertubation.
121121
"""
122+
# Pick a small scalar to avoid division by 0
123+
tol = 10e-8
122124
nom = -theta * grads
123-
denom = norm_grad**2
125+
denom = norm_grad**2 if norm_grad > tol else tol
124126
result = nom / float(denom)
125127

126128
return result

0 commit comments

Comments
 (0)