@@ -129,10 +129,13 @@ def _check_params(self) -> None:
129129 raise ValueError ("The argument `verbose` has to be of type bool." )
130130 if self .estimator .clip_values is None :
131131 raise ValueError ("This attack requires estimator clip values to be defined." )
132+
132133 def rescale_input (self , x ):
134+ """Rescale inputs"""
133135 x = x .astype (np .float32 ) / 255.0
134136 x = (x * (self .estimator .clip_values [1 ] - self .estimator .clip_values [0 ])) + self .estimator .clip_values [0 ]
135137 return x
138+
136139 def generate (self , x : np .ndarray , y : Optional [np .ndarray ] = None , ** kwargs ) -> np .ndarray :
137140 """
138141 Generate adversarial samples and return them in an array.
@@ -321,9 +324,9 @@ def callback_fn(x, convergence=None): # pylint: disable=R1710,W0613
321324 callback = callback_fn ,
322325 iterations = self .max_iter ,
323326 )
324- except CMAEarlyStoppingException as e :
327+ except CMAEarlyStoppingException as err :
325328 if self .verbose_es :
326- logger .info (e . message )
329+ logger .info (err )
327330
328331 adv_x = strategy .result [0 ]
329332 else :
@@ -476,11 +479,13 @@ def _perturb_image(self, x: np.ndarray, img: np.ndarray) -> np.ndarray:
476479 ):
477480 image [i , j , k ] = adv [count ]
478481 return imgs
479-
482+
483+
480484class CMAEarlyStoppingException (Exception ):
481485 """Raised when CMA is stopping early after successful optimisation."""
482486 pass
483487
488+
484489# TODO: Make the attack compatible with current version of SciPy Optimize
485490# Differential Evolution
486491# pylint: disable=W0105
0 commit comments