Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix - Carlini_Wagner_L2 (tf2) - raise exception when clip_min or clip_max is type None #1234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions cleverhans/tf2/attacks/carlini_wagner_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down