cleverhans-lab / cleverhans

An adversarial example library for constructing attacks, building defenses, and benchmarking both
MIT License
6.21k stars 1.39k forks source link

TF2: CarliniWagnerL2 fails if argument `y` is provided and batch size is unequal to number of samples #1241

Open thijs-vanweezel opened 10 months ago

thijs-vanweezel commented 10 months ago

The issue tracker should only be used to report bugs or feature requests. If you are looking for support from other library users, please ask a question on StackOverflow.

Describe the bug If an argument for parameter y is provided in the function carlini_wagner_l2, the error below is raised, and the only way to avoid this is to set argument batch_size equal to the number of samples in y. CarliniWagnerL2Exception: x and y do not have the same shape!

To Reproduce

import tensorflow as tf
from cleverhans.tf2.attacks.carlini_wagner_l2 import carlini_wagner_l2

(x, y), _ = tf.keras.datasets.cifar10.load_data()
x = tf.image.convert_image_dtype(y, dtype=tf.float32)

# <load model here>

x_adv = carlini_wagner_l2(classifier, x=x[:8], y=y[:8], max_iterations=10, batch_size=4) # arguments chosen for time concerns

Expected behavior Just like x, the argument y should be split into batches.