52 def query(self, query_img_list, gallery_img_list, topK=5):
53 query_features_list = []
54 for q
in query_img_list:
55 query_features_list.append(self.
infer(q))
56 query_features = np.concatenate(query_features_list, axis=0)
57 query_norm = np.linalg.norm(query_features, ord=2, axis=1, keepdims=
True)
58 query_arr = query_features / (query_norm + np.finfo(np.float32).eps)
60 gallery_features_list = []
61 for g
in gallery_img_list:
62 gallery_features_list.append(self.
infer(g))
63 gallery_features = np.concatenate(gallery_features_list, axis=0)
64 gallery_norm = np.linalg.norm(gallery_features, ord=2, axis=1, keepdims=
True)
65 gallery_arr = gallery_features / (gallery_norm + np.finfo(np.float32).eps)
67 dist = np.matmul(query_arr, gallery_arr.T)
68 idx = np.argsort(-dist, axis=1)
69 return [i[0:topK]
for i
in idx]