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

something miss with sort and match? #96

Open
nickbp760 opened this issue Dec 15, 2020 · 1 comment
Open

something miss with sort and match? #96

nickbp760 opened this issue Dec 15, 2020 · 1 comment

Comments

@nickbp760
Copy link

nickbp760 commented Dec 15, 2020

a = torch.tensor([[0.9, 0.01],[0.8,0.02],[-2.3, -2.4], [-2.4, -1.5]]) #gallery
print(a.size())
b = torch.tensor([[2.1, 0.4],[-2.1,-3.2],[-2.2,-0.3]]) #query
print(b.size())
dismat = torch.cdist(b, a)
print(dismat)
m,n=dismat.shape

Result
torch.Size([4, 2])
torch.Size([3, 2])
tensor([[1.2618, 1.3544, 5.2154, 4.8847],
[4.3936, 4.3334, 0.8246, 1.7263],
[3.1155, 3.0170, 2.1024, 1.2166]])
torch.Size([3, 4])

import numpy as np
gallery_ids= np.array([1,1,2,2]) #gallery
query_ids = np.array([1,2,2]) #query

print(n[:, np.newaxis])
indices=np.argsort(dismat,axis=1)
print(indices)
print(n[indices])
matches = (gallery_ids[indices] == query_ids[:, np.newaxis])
print(matches)

Result
[[1]
[2]
[2]]
tensor([[0, 1, 3, 2],
[2, 3, 1, 0],
[3, 2, 1, 0]])
[[1 1 2 2]
[2 2 1 1]
[2 2 1 1]]
[[ True True False False]
[ True True False False]
[ True True False False]]

It's strange when your algorithm detect that true for index [1][0],[1][1] and index [2][0],[2][1]?
because the euclidan said that minimum distance is [1][2],[1][3] and index [2][2],[2][3] like my index that I made
i just want to have an idea about your code in

Sort and find correct matches

indices = np.argsort(distmat, axis=1)
matches = (gallery_ids[indices] == query_ids[:, np.newaxis]) 
@nickbp760
Copy link
Author

finally i understood that
[[1 1 2 2]
[2 2 1 1]
[2 2 1 1]]
it's the prediction

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

1 participant