Skip to content

Commit 2c1fe19

Browse files
committed
Updating patch attacks based on convo with Beat
1 parent 3675a96 commit 2c1fe19

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

art/attacks/evasion/adversarial_patch/adversarial_patch_pytorch.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,13 @@ def generate( # type: ignore
511511
if self.patch_location is not None and mask is not None:
512512
raise ValueError("Masks can only be used if the `patch_location` is `None`.")
513513

514+
if y is None and self.targeted:
515+
raise ValueError("The targeted version of AdversarialPatch attack requires provided target labels.")
516+
514517
if hasattr(self.estimator, "nb_classes"):
515518

516519
y_array: np.ndarray
517520

518-
if y is not None and not self.targeted:
519-
raise ValueError("The untargeted version of AdversarialPatch attack does not use target labels.")
520-
521521
if y is None: # pragma: no cover
522522
logger.info("Setting labels to estimator classification predictions.")
523523
y_array = to_categorical(
@@ -536,9 +536,6 @@ def generate( # type: ignore
536536
else:
537537
self.use_logits = True
538538
else:
539-
if y is not None and not self.targeted:
540-
raise ValueError("The untargeted version of AdversarialPatch attack does not use target labels.")
541-
542539
if y is None: # pragma: no cover
543540
logger.info("Setting labels to estimator object detection predictions.")
544541
y = self.estimator.predict(x=x)

art/attacks/evasion/dpatch_robust.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def generate( # type: ignore
155155
if y is None and self.targeted:
156156
raise ValueError("The targeted version of RobustDPatch attack requires target labels provided to `y`.")
157157
if y is not None and not self.targeted:
158-
raise ValueError("The RobustDPatch attack does not use target labels.")
158+
raise ValueError("The untargeted version of RobustDPatch attack does not use target labels provided to 'y'.")
159159
if x.ndim != 4: # pragma: no cover
160160
raise ValueError("The adversarial patch can only be applied to images.")
161161

0 commit comments

Comments
 (0)