Skip to content

Commit 5ec0dc3

Browse files
Update Exception Handling
1 parent 52cbb5f commit 5ec0dc3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

art/attacks/evasion/pixel_threshold.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def predict_fn(x):
289289
def callback_fn(x, convergence=None): # pylint: disable=R1710,W0613
290290
if self.es == 0:
291291
if self._attack_success(x.result[0], image, target_class):
292-
raise Exception("Attack Completed :) Earlier than expected")
292+
raise CMAEarlyStoppingException("Attack Completed :) Earlier than expected")
293293
else:
294294
return self._attack_success(x, image, target_class)
295295

@@ -321,9 +321,9 @@ def callback_fn(x, convergence=None): # pylint: disable=R1710,W0613
321321
callback=callback_fn,
322322
iterations=self.max_iter,
323323
)
324-
except Exception as exception:
324+
except CMAEarlyStoppingException as e:
325325
if self.verbose_es:
326-
print(exception)
326+
logger.info(e.message)
327327

328328
adv_x = strategy.result[0]
329329
else:
@@ -476,7 +476,10 @@ def _perturb_image(self, x: np.ndarray, img: np.ndarray) -> np.ndarray:
476476
):
477477
image[i, j, k] = adv[count]
478478
return imgs
479-
479+
480+
class CMAEarlyStoppingException(Exception):
481+
"""Raised when CMA is stopping early after successful optimisation."""
482+
pass
480483

481484
# TODO: Make the attack compatible with current version of SciPy Optimize
482485
# Differential Evolution

0 commit comments

Comments
 (0)