@@ -56,6 +56,7 @@ class AdversarialPatch(EvasionAttack):
5656 "learning_rate" ,
5757 "max_iter" ,
5858 "batch_size" ,
59+ "targeted" ,
5960 "verbose" ,
6061 ]
6162
@@ -71,6 +72,7 @@ def __init__(
7172 max_iter : int = 500 ,
7273 batch_size : int = 16 ,
7374 patch_shape : Optional [Tuple [int , int , int ]] = None ,
75+ targeted : bool = True ,
7476 verbose : bool = True ,
7577 ):
7678 """
@@ -89,6 +91,7 @@ def __init__(
8991 :param patch_shape: The shape of the adversarial patch as a tuple of shape (width, height, nb_channels).
9092 Currently only supported for `TensorFlowV2Classifier`. For classifiers of other frameworks
9193 the `patch_shape` is set to the shape of the input samples.
94+ :param targeted: Indicates whether the attack is targeted (True) or untargeted (False).
9295 :param verbose: Show progress bars.
9396 """
9497 super ().__init__ (estimator = classifier )
@@ -106,6 +109,7 @@ def __init__(
106109 max_iter = max_iter ,
107110 batch_size = batch_size ,
108111 patch_shape = patch_shape ,
112+ targeted = targeted ,
109113 verbose = verbose ,
110114 )
111115 elif isinstance (self .estimator , PyTorchClassifier ):
@@ -121,6 +125,7 @@ def __init__(
121125 batch_size = batch_size ,
122126 patch_shape = patch_shape ,
123127 patch_type = "circle" ,
128+ targeted = targeted ,
124129 verbose = verbose ,
125130 )
126131 else :
@@ -134,6 +139,7 @@ def __init__(
134139 learning_rate = learning_rate ,
135140 max_iter = max_iter ,
136141 batch_size = batch_size ,
142+ targeted = targeted ,
137143 verbose = verbose ,
138144 )
139145 self ._check_params ()
@@ -241,5 +247,8 @@ def _check_params(self) -> None:
241247 if not self ._attack .batch_size > 0 :
242248 raise ValueError ("The batch size must be greater than 0." )
243249
250+ if not isinstance (self ._attack .targeted , bool ):
251+ raise ValueError ("The argument `targeted` has to be of type bool." )
252+
244253 if not isinstance (self ._attack .verbose , bool ):
245254 raise ValueError ("The argument `verbose` has to be of type bool." )
0 commit comments