Skip to content

Commit 52505e4

Browse files
Irina NicolaeIrina Nicolae
authored andcommitted
Fix bug in JSMA to avoid infinite loop (close #54)
1 parent 50d18ff commit 52505e4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

art/attacks/saliency_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def generate(self, x, **kwargs):
7676
target = targets[ind]
7777
all_feat = set()
7878

79-
while current_pred != target and len(all_feat)/self._nb_features <= self.gamma and bool(search_space):
79+
while current_pred != target and len(all_feat) / self._nb_features <= self.gamma and bool(search_space):
8080
# Compute saliency map
8181
feat1, feat2 = self._saliency_map(np.reshape(val, dims), target, search_space)
8282

@@ -144,7 +144,7 @@ def _saliency_map(self, x, target, search_space):
144144
# Remove gradients for already used features
145145
used_features = list(set(range(self._nb_features)) - search_space)
146146
coeff = 2 * int(self.theta > 0) - 1
147-
grads[used_features] = - np.max(np.abs(grads)) * coeff
147+
grads[used_features] = -np.inf * coeff
148148

149149
if self.theta > 0:
150150
ind = np.argpartition(grads, -2)[-2:]

0 commit comments

Comments
 (0)