@@ -18,10 +18,10 @@ class UniversalPerturbation(Attack):
1818 'jsma' : 'art.attacks.saliency_map.SaliencyMapMethod' ,
1919 'vat' : 'art.attacks.virtual_adversarial.VirtualAdversarialMethod'
2020 }
21- attack_params = ['attacker' , 'attacker_params' , 'delta' , 'max_iter' , 'eps' , 'p ' ]
21+ attack_params = ['attacker' , 'attacker_params' , 'delta' , 'max_iter' , 'eps' , 'norm ' ]
2222
2323 def __init__ (self , classifier , attacker = 'deepfool' , attacker_params = None , delta = 0.2 , max_iter = 20 , eps = 10.0 ,
24- p = np .inf ):
24+ norm = np .inf ):
2525 """
2626 :param classifier: A trained model.
2727 :type classifier: :class:`Classifier`
@@ -36,16 +36,16 @@ def __init__(self, classifier, attacker='deepfool', attacker_params=None, delta=
3636 :type max_iter: `int`
3737 :param eps: Attack step size (input variation)
3838 :type eps: `float`
39- :param p : Order of the norm. Possible values: np.inf, 2 (default is np.inf)
40- :type p : `int`
39+ :param norm : Order of the norm. Possible values: np.inf, 2 (default is np.inf)
40+ :type norm : `int`
4141 """
4242 super (UniversalPerturbation , self ).__init__ (classifier )
4343 kwargs = {'attacker' : attacker ,
4444 'attacker_params' : attacker_params ,
4545 'delta' : delta ,
4646 'max_iter' : max_iter ,
4747 'eps' : eps ,
48- 'p ' : p
48+ 'norm ' : norm
4949 }
5050 self .set_params (** kwargs )
5151
@@ -66,8 +66,8 @@ def generate(self, x, **kwargs):
6666 :type max_iter: `int`
6767 :param eps: Attack step size (input variation)
6868 :type eps: `float`
69- :param p : Order of the norm. Possible values: np.inf, 2 (default is np.inf)
70- :type p : `int`
69+ :param norm : Order of the norm. Possible values: np.inf, 2 (default is np.inf)
70+ :type norm : `int`
7171 :return: An array holding the adversarial examples.
7272 :rtype: `np.ndarray`
7373 """
@@ -108,7 +108,7 @@ def generate(self, x, **kwargs):
108108 v += adv_xi - xi
109109
110110 # Project on L_p ball
111- v = self ._clip_perturbation (v , self .eps , self .p )
111+ v = self ._clip_perturbation (v , self .eps , self .norm )
112112 nb_iter += 1
113113
114114 # Compute the error rate
@@ -137,8 +137,8 @@ def set_params(self, **kwargs):
137137 :type max_iter: `int`
138138 :param eps: Attack step size (input variation)
139139 :type eps: `float`
140- :param p : Order of the norm. Possible values: np.inf, 2 (default is np.inf)
141- :type p : `int`
140+ :param norm : Order of the norm. Possible values: np.inf, 2 (default is np.inf)
141+ :type norm : `int`
142142 """
143143 super (UniversalPerturbation , self ).set_params (** kwargs )
144144
@@ -153,25 +153,25 @@ def set_params(self, **kwargs):
153153
154154 return True
155155
156- def _clip_perturbation (self , v , eps , p ):
156+ def _clip_perturbation (self , v , eps , norm ):
157157 """
158158 Clip the values in v if their L_p norm is larger than eps.
159159
160160 :param v: array of perturbations to clip.
161161 :type v: `np.ndarray`
162162 :param eps: maximum norm allowed.
163163 :type eps: `float`
164- :param p : L_p norm to use for clipping. Only p = 2 and p = Inf supported for now.
165- :type p : `int`
164+ :param norm : L_p norm to use for clipping. Only `norm == 2` and `norm == np.inf` supported for now.
165+ :type norm : `int`
166166 :return: clipped values of v
167167 :rtype: `np.ndarray`
168168 """
169- if p == 2 :
169+ if norm == 2 :
170170 v *= min (1. , eps / np .linalg .norm (v , axis = (1 , 2 )))
171- elif p == np .inf :
171+ elif norm == np .inf :
172172 v = np .sign (v ) * np .minimum (abs (v ), eps )
173173 else :
174- raise NotImplementedError ('Values of p different from 2 and Inf are currently not supported.' )
174+ raise NotImplementedError ('Values of `norm` different from 2 and `np.inf` are currently not supported.' )
175175
176176 return v
177177
0 commit comments