1919This module implements the Threshold Attack and Pixel Attack.
2020The Pixel Attack is a generalisation of One Pixel Attack.
2121
22- | One Pixel Attack Paper link:
23- https://ieeexplore.ieee.org/abstract/document/8601309/citations#citations
24- (arXiv link: https://arxiv.org/pdf/1710.08864.pdf)
25- | Pixel and Threshold Attack Paper link:
26- https://arxiv.org/abs/1906.06026
22+ | One Pixel Attack Paper link: https://arxiv.org/ans/1710.08864
23+ | Pixel and Threshold Attack Paper link: https://arxiv.org/abs/1906.06026
2724"""
2825# pylint: disable=C0302
2926from __future__ import absolute_import , division , print_function , unicode_literals
6158class PixelThreshold (EvasionAttack ):
6259 """
6360 These attacks were originally implemented by Vargas et al. (2019) & Su et al.(2019).
64- | One Pixel Attack Paper link:
65- https://ieeexplore.ieee.org/abstract/document/8601309/citations#citations
66- (arXiv link: https://arxiv.org/pdf/1710.08864.pdf)
67- | Pixel and Threshold Attack Paper link:
68- https://arxiv.org/abs/1906.06026
61+
62+ | One Pixel Attack Paper link: https://arxiv.org/abs/1710.08864
63+ | Pixel and Threshold Attack Paper link: https://arxiv.org/abs/1906.06026
6964 """
7065
7166 attack_params = EvasionAttack .attack_params + ["th" , "es" , "max_iter" , "targeted" , "verbose" , "verbose_es" ]
@@ -83,6 +78,7 @@ def __init__(
8378 ) -> None :
8479 """
8580 Create a :class:`.PixelThreshold` instance.
81+
8682 :param classifier: A trained classifier.
8783 :param th: threshold value of the Pixel/ Threshold attack. th=None indicates finding a minimum threshold.
8884 :param es: Indicates whether the attack uses CMAES (0) or DE (1) as Evolutionary Strategy.
@@ -139,6 +135,7 @@ def rescale_input(self, x):
139135 def generate (self , x : np .ndarray , y : Optional [np .ndarray ] = None , ** kwargs ) -> np .ndarray :
140136 """
141137 Generate adversarial samples and return them in an array.
138+
142139 :param x: An array with the original inputs.
143140 :param y: Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or indices of shape
144141 (nb_samples,). Only provide this parameter if you'd like to use true labels when crafting adversarial
@@ -164,7 +161,7 @@ def generate(self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs) -> n
164161 if self .th is None :
165162 logger .info (
166163 "Performing minimal perturbation Attack. \
167- This takes substainally long time to process. \
164+ This could take long time to process. \
168165 For sanity check, pass th=10 to the Attack instance."
169166 )
170167
@@ -357,11 +354,9 @@ class PixelAttack(PixelThreshold):
357354 """
358355 This attack was originally implemented by Vargas et al. (2019). It is generalisation of One Pixel Attack originally
359356 implemented by Su et al. (2019).
360- | One Pixel Attack Paper link:
361- https://ieeexplore.ieee.org/abstract/document/8601309/citations#citations
362- (arXiv link: https://arxiv.org/pdf/1710.08864.pdf)
363- | Pixel Attack Paper link:
364- https://arxiv.org/abs/1906.06026
357+
358+ | One Pixel Attack Paper link: https://arxiv.org/abs/1710.08864
359+ | Pixel Attack Paper link: https://arxiv.org/abs/1906.06026
365360 """
366361
367362 def __init__ (
@@ -375,6 +370,7 @@ def __init__(
375370 ) -> None :
376371 """
377372 Create a :class:`.PixelAttack` instance.
373+
378374 :param classifier: A trained classifier.
379375 :param th: threshold value of the Pixel/ Threshold attack. th=None indicates finding a minimum threshold.
380376 :param es: Indicates whether the attack uses CMAES (0) or DE (1) as Evolutionary Strategy.
@@ -440,8 +436,8 @@ def _get_bounds(self, img: np.ndarray, limit) -> Tuple[List[list], list]:
440436class ThresholdAttack (PixelThreshold ):
441437 """
442438 This attack was originally implemented by Vargas et al. (2019).
443- | Paper link:
444- https://arxiv.org/abs/1906.06026
439+
440+ | Paper link: https://arxiv.org/abs/1906.06026
445441 """
446442
447443 def __init__ (
@@ -455,6 +451,7 @@ def __init__(
455451 ) -> None :
456452 """
457453 Create a :class:`.PixelThreshold` instance.
454+
458455 :param classifier: A trained classifier.
459456 :param th: threshold value of the Pixel/ Threshold attack. th=None indicates finding a minimum threshold.
460457 :param es: Indicates whether the attack uses CMAES (0) or DE (1) as Evolutionary Strategy.
@@ -499,7 +496,9 @@ class CMAEarlyStoppingException(Exception):
499496To speed up predictions, the entire parameters array is passed to `self.func`,
500497where a neural network model can batch its computations and execute in parallel
501498Search for `CHANGES` to find all code changes.
499+
502500Dan Kondratyuk 2018
501+
503502Original code adapted from
504503https://github.com/scipy/scipy/blob/70e61dee181de23fdd8d893eaa9491100e2218d7/scipy/optimize/_differentialevolution.py
505504----------
0 commit comments