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

Is there a way to change/override the expected loss function of Foolbox's 'attack' function? #689

Open
John-Chin opened this issue Jun 7, 2022 · 1 comment
Labels

Comments

@John-Chin
Copy link

Hi,
I am currently trying to generate adversarial images of a CIFAR10 dataset that can fool a CNN in a simple color estimation task.

As a little background for this color estimation task, I created a CNN to estimate the average global color of an image as a 3d column vector in terms of [average red channel, average blue channel, average green channel]. To train this CNN, I used a relabeled CIFAR10 dataset (where each label is no longer a number denoting it's class but a 3d vector of the average color) and MSE as my loss function.

But now, when I tried to use foolbox's attack function
raw_advs, clipped_advs, success = attack(fmodel, images, labels, epsilons=epsilons)
to create an adversarial image, I ran into this error:

Screen Shot 2022-05-30 at 7 31 55 PM

From this error trace, it seems that the attack function is automatically geared toward object recognition models that use cross entropy loss and output a 1d label.

So my question is: is there any way to modify the attack function's expected loss function to be Mean Square Error instead of Cross Entropy? Or perhaps I should not use the built-in attack function, and instead generate the adversarial images manually?
Thank you for any thoughts or tips.

@John-Chin John-Chin changed the title Is there a way to change the expected loss function of Foolbox's 'attack' function? Is there a way to change/override the expected loss function of Foolbox's 'attack' function? Jun 14, 2022
@zimmerrol
Copy link
Member

Hi. Usually, one considers tha combination of loss function and optimization algorithm as the adversarial attack. Thus, changing the loss function of an attack gives you a new adversarial attack. Therefore, in foolbox, you cannot change the loss function of (most) attacks arbitrarily. However, you can always create a new class, inherit from whatever attack you want to modify and then overwrite the definition of the loss function. Does that make sense to you?

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

No branches or pull requests

2 participants