From 88ef8b2bcff471f12541cfbb3886ddb68e95393f Mon Sep 17 00:00:00 2001 From: oiannace Date: Wed, 1 Feb 2023 20:49:15 -0500 Subject: [PATCH] Carlini_Wagner_L2 (tf2) - raise exception when clip_min or clip_max is type None --- cleverhans/tf2/attacks/carlini_wagner_l2.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cleverhans/tf2/attacks/carlini_wagner_l2.py b/cleverhans/tf2/attacks/carlini_wagner_l2.py index 60d97ec65..220afce47 100644 --- a/cleverhans/tf2/attacks/carlini_wagner_l2.py +++ b/cleverhans/tf2/attacks/carlini_wagner_l2.py @@ -47,8 +47,8 @@ def __init__( :param y: (optional) Tensor with target labels. :param targeted: (optional) Targeted attack? :param batch_size (optional): Number of attacks to run simultaneously. - :param clip_min: (optional) float. Minimum float values for adversarial example components. - :param clip_max: (optional) float. Maximum float value for adversarial example components. + :param clip_min: Minimum float values for adversarial example components. + :param clip_max: Maximum float value for adversarial example components. :param binary_search_steps (optional): The number of times we perform binary search to find the optimal tradeoff- constant between norm of the purturbation @@ -117,12 +117,20 @@ def _attack(self, x): raise CarliniWagnerL2Exception( f"The input is smaller than the minimum value of {self.clip_min}r" ) + else: + raise CarliniWagnerL2Exception( + "The parameter clip_min can not be None." + ) if self.clip_max is not None: if not np.all(tf.math.less_equal(x, self.clip_max)): raise CarliniWagnerL2Exception( f"The input is greater than the maximum value of {self.clip_max}!" ) + else: + raise CarliniWagnerL2Exception( + "The parameter clip_max can not be None." + ) # cast to tensor if provided as numpy array original_x = tf.cast(x, tf.float32)