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

when computing cosine similarity #4

Closed
juliuswang0728 opened this issue May 25, 2022 · 1 comment
Closed

when computing cosine similarity #4

juliuswang0728 opened this issue May 25, 2022 · 1 comment

Comments

@juliuswang0728
Copy link

Hi! this is more of a question for the elegant work you have here but less of an issue.

So when you take cosine similarity (which is to be decreased during training) between two feature maps, you take,

loss = torch.cosine_similarity((adv_out_slice*attention).reshape(adv_out_slice.shape[0], -1), 
                            (img_out_slice*attention).reshape(img_out_slice.shape[0], -1)).mean()

and that's to compare two flatten vectors, each of which is the flattened feature maps of size (N feature channels, width, height).

I wonder why not comparing the flattened feature maps with respect to each channel, and then take the average across channels? To me, you're comparing two vectors that are (Nwidthheight)-dimensional, which is not so straightforward to me. Thanks in advance for any intuition behind!

@qilong-zhang
Copy link
Collaborator

Hi @juliuswang0728, thanks for your attention to our paper. For the issue you mentioned, we actually did not study it in depth, because we think the goals of these two calculation methods are similar.

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