Harry24k / adversarial-attacks-pytorch

PyTorch implementation of adversarial attacks [torchattacks].
https://adversarial-attacks-pytorch.readthedocs.io/en/latest/index.html
MIT License
1.79k stars 337 forks source link

[QUESTION] Binary search for Carlini-Wagner #167

Closed Adversarian closed 7 months ago

Adversarian commented 7 months ago

❔ Any questions

Hi! First I would like to thank you for your tremendous work on this project. I had a question regarding the CW attack.

In the README page of the project a section under "Getting Started" mentions "Binary search for CW" whereas the documentation states that binary search over c was not implemented because it is time consuming. This has left me confused because if there is a way to perform binary search over c using this library, I would like to know so I can stop using multiple libraries and if not, then what is the subsection under "Getting Started" referring to?

rikonaka commented 7 months ago

Hi @Adversarian , I don’t quite understand something about your expression in I would like to know so I can stop using multiple libraries and if not.

According to the README page, if you want to perform a binary search, you can try the following code.

atk1 = torchattacks.CW(model, c=0.1, steps=1000, lr=0.01)
atk2 = torchattacks.CW(model, c=1, steps=1000, lr=0.01)
atk = torchattacks.MultiAttack([atk1, atk2])

But this code can't seem to stop early.

Well, I tested this code (I am not the maintainer or contributor of this code), and I found that this code does not seem to be able to perform the binary search function it claims. This code only uses one of the attacks to obtain the image, not a binary search. I will submit a version of CW's binary search as soon as possible

test

Adversarian commented 7 months ago

Hi @rikonaka, thank you for your prompt response.

Regarding your confusion, I am currently using foolbox which includes a CW implementation with binary search and torchattacks for everything else and I was hoping to migrating to torchattacks for everything if possible which makes my code very cleaner and easier to understand, maintain and debug.

I understand that a binary search with CW is not very difficult to implement but I simply don't have to time at the moment to submit my own PR so I would immensely appreciate it if you could make it happen.

rikonaka commented 7 months ago

Hi @rikonaka, thank you for your prompt response.

Regarding your confusion, I am currently using foolbox which includes a CW implementation with binary search and torchattacks for everything else and I was hoping to migrating to torchattacks for everything if possible which makes my code very cleaner and easier to understand, maintain and debug.

I understand that a binary search with CW is not very difficult to implement but I simply don't have to time at the moment to submit my own PR so I would immensely appreciate it if you could make it happen.

Good news 😉, I just spent two hours implementing the CW with binary search, and soon you can use it in torchattacks. It has now been submitted and is ready to be merged into the mainline.

Adversarian commented 7 months ago

I am very much obliged. Thank you so much. I'm gonna optimistically close this now!