in isc/descriptor_matching.py [0:0]
def knn_match_and_make_predictions(xq, query_image_ids, xb, db_image_ids, k, ngpu=-1, metric=faiss.METRIC_L2):
if faiss.get_num_gpus() == 0 or ngpu == 0:
D, I = faiss.knn(xq, xb, k, metric)
else:
d = xq.shape[1]
index = faiss.IndexFlat(d, metric)
index.add(xb)
index = faiss.index_cpu_to_all_gpus(index)
D, I = index.search(xq, k=k)
nq = len(xq)
if metric == faiss.METRIC_L2:
# use negated distances as scores
D = -D
predictions = [
PredictedMatch(
query_image_ids[i],
db_image_ids[I[i, j]],
D[i, j]
)
for i in range(nq)
for j in range(k)
]
return predictions