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])
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