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 in CarliniWagnerL2 for tf2 #1205

Open
grahamannett opened this issue Mar 30, 2021 · 2 comments
Open

bug in CarliniWagnerL2 for tf2 #1205

grahamannett opened this issue Mar 30, 2021 · 2 comments
Assignees

Comments

@grahamannett
Copy link
Contributor

grahamannett commented Mar 30, 2021

Seems like this is because CarliniWagnerL2.attack takes a single instance of x? Not sure if this is intended but is there anyway to allow for multiple x to be passed in at once? Would that help with the speed of the attack since at the moment generating a single attack for an in put takes ~45 seconds on a pretrained model.

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
when trying to use cw2 attack from cleverhans I get an error about

ValueError: Dimensions must be equal, but are 3 and 10 for '{{node mul_5}} = Mul[T=DT_FLOAT](const, Maximum)' with input shapes: [10,160,160,3], [10].

To Reproduce
Steps to reproduce the behavior:

  1. Using dataset from fastai IMAGENETTE dataset
  2. Using functional api from tf.keras with a pretrained model
  3. Something like this
attacker = CarliniWagnerL2(model)
adv_x = attacker.attack(x_tensor)

results in

    ValueError: Dimensions must be equal, but are 3 and 10 for '{{node mul_5}} = Mul[T=DT_FLOAT](const, Maximum)' with input shapes: [10,160,160,3], [10].

Where the issue is, is from (I think):
https://github.com/cleverhans-lab/cleverhans/blob/master/cleverhans/tf2/attacks/carlini_wagner_l2.py#L333

where const is a tensor from tf.ones * initial const of the x input and loss_1 is a tensor that is the shape of the y output. I don't exactly see where this value comes from in the original paper so unsure exactly what the value should look like

Expected behavior
Adversarial output

Screenshots
If applicable, add screenshots to help explain your problem.

@akshaymehra24
Copy link

Change in line https://github.com/cleverhans-lab/cleverhans/blob/master/cleverhans/tf2/attacks/carlini_wagner_l2.py#L153

From:
const = tf.ones(shape) * self.initial_const

To:
const = tf.ones(shape[0]) * self.initial_const

@thijs-vanweezel
Copy link

To: const = tf.ones(shape[0]) * self.initial_const

Could we please implement this in the main branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants