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

pytorch gradient attack #91

Closed
dongshuhao opened this issue Dec 15, 2017 · 4 comments
Closed

pytorch gradient attack #91

dongshuhao opened this issue Dec 15, 2017 · 4 comments

Comments

@dongshuhao
Copy link

dongshuhao commented Dec 15, 2017

grad = self._process_gradient(grad)

Why do we need to have the grad divided by the std? I do not think it is necessary.

@wielandbrendel
Copy link
Member

self._process_gradient simply backprops the gradient through the preprocessing step (subtraction of the mean, scaling).

@dongshuhao
Copy link
Author

dongshuhao commented Dec 15, 2017

This line is for backprops.

loss.backward()

The point it is why do we need:

result = gradient / pdiv

Based on:

perturbed = image + gradient * epsilon

The estimated grad is applied to the original image. Why do we need to do the preprocessing on the grad then?

@wielandbrendel
Copy link
Member

See, the processing pipeline is this: original image -> preprocessed image -> model output. Most importantly, the model only sees the preprocessed image! Hence, loss.backward() gives you the gradient with respect to the preprocessed image. self._process_gradient takes this gradient and returns the gradient with respect to the original image. If there is no preprocessing then the two are identical.

@dongshuhao
Copy link
Author

@wielandbrendel I got it! Thanks!

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

2 participants