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

Relevance embedding #42

Closed
taeyeopl opened this issue Jun 15, 2021 · 4 comments
Closed

Relevance embedding #42

taeyeopl opened this issue Jun 15, 2021 · 4 comments

Comments

@taeyeopl
Copy link

taeyeopl commented Jun 15, 2021

R_lv3 = torch.bmm(refsr_lv3_unfold, lrsr_lv3_unfold) #[N, Hr*Wr, H*W]
R_lv3_star, R_lv3_star_arg = torch.max(R_lv3, dim=1) #[N, H*W]

As I understood related to the equation 4 (in the main paper), your relevance matrix is calculating normalized inner product. r_{i,j} = norm-inner{q_i,k_j}. ( Query is from the up-sampled low-resolution image and Key is from the down/up-sampled reference image. )

My understanding is like the below code.
Q1. Can you explain why your code is opposed?? (Usually, transformer makes the scores using the equation scores = (Q, K^T)).

R_lv3 = torch.bmm(lrsr_lv3_unfold, refsr_lv3_unfold) #[N, H*W, Hr*Wr] 
R_lv3_star, R_lv3_star_arg = torch.max(R_lv3, dim=2) #[N, H*W]
@FuzhiYang
Copy link
Member

It is ok to change the parameter position of lrsr_lv3_unfold and refsr_lv3_unfold. You can just instead permute lrsr_lv3_unfold in this line:

refsr_lv3_unfold = refsr_lv3_unfold.permute(0, 2, 1)
.
And then you can apply your code above to get the equal results.

@taeyeopl
Copy link
Author

taeyeopl commented Jun 30, 2021

Due to my limited understanding, I do not clearly understand your points.
My understanding is matrix multiplication is not permutation invariant.
Therefore, those operations will make a different relation matrix, even it considers the permute.
Can you explain why at the end of the results you get equal results?
Am I missing something??

R_lv3 = torch.bmm(lrsr_lv3_unfold, refsr_lv3_unfold) #[N, H*W, Hr*Wr] (Oirginal)
R_lv3 = torch.bmm(refsr_lv3_unfold, lrsr_lv3_unfold) #[N, Hr*Wr, H*W] (My Understanding)

@FuzhiYang
Copy link
Member

FuzhiYang commented Jul 1, 2021

I mean the key point is to get "R_lv3_star_arg" and "R_lv3_star" in

R_lv3_star, R_lv3_star_arg = torch.max(R_lv3, dim=1) #[N, H*W]

Therefore, how to permute the tensor is not important. But you need to adjust "dim" parameter to get the correct "R_lv3_star_arg" and "R_lv3_star" in this line:

R_lv3_star, R_lv3_star_arg = torch.max(R_lv3, dim=1) #[N, H*W]

@taeyeopl
Copy link
Author

taeyeopl commented Jul 6, 2021

I see, thanks for the detailed explanation !!

@taeyeopl taeyeopl closed this as completed Jul 6, 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