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

how to visualize the loss landscape? #3

Closed
seyeeet opened this issue Mar 29, 2021 · 4 comments
Closed

how to visualize the loss landscape? #3

seyeeet opened this issue Mar 29, 2021 · 4 comments

Comments

@seyeeet
Copy link

seyeeet commented Mar 29, 2021

in the paper you mentioned and showed an example of visualizing the loss landscape.
Can you please explain how to do it ?
I would really appreciate it if you can share the code for that since I am new to this topic and your implementation will be super useful!

@jbeomlee93
Copy link
Owner

Hi @seyeeet, the loss landscape was visualized through the following process.

  1. For an image x, compute the classification loss L(x).
  2. Compute vec{n} by backward L, and obtain any random vector vec{r}.
  3. Compute L(x+alpha*vec{n}+beta*vec{r}). -1<beta<1, alpha>0: adversarial attack, alpha<0: adversarial climbing
  4. Plot (alpha, beta, L(x+alpha*vec{n}+beta*vec{r}))

Thanks!

@seyeeet
Copy link
Author

seyeeet commented Apr 12, 2021

Thanks for your explanation, it is more clear now.
Can you please explain a little more how to compute vec{n} and vec{r} and what is the shape of vec{n} and vec{r}.
I mean what vec{n} means, I mean what is the dimension of vec and are n and r integers?
Sorry I am new to this and your explanation is very helpful

@jbeomlee93
Copy link
Owner

vec{n} and vec{r} are actually matrices with the same spatial size as the input image.

vec{n} is a gradient map of classification loss L with respect to an image, which can be obtained similar to the following:

model.zero_grad()
img_single.grad.zero_()
loss.backward()
data_grad = img_single.grad.data

vec{r} is literally a random matrix.

Thanks.

@seyeeet
Copy link
Author

seyeeet commented Apr 13, 2021

thank you

@seyeeet seyeeet closed this as completed Apr 13, 2021
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