Skip to content
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