Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def search():
n_query = len(queries)
diffusion = Diffusion(np.vstack([queries, gallery]), args.cache_dir)
offline = diffusion.get_offline_results(args.truncation_size, args.kd)
features = preprocessing.normalize(offline, norm="l2", axis=1)
scores = features[:n_query] @ features[n_query:].T
ranks = np.argsort(-scores.todense())
evaluate(ranks)
def search_old(gamma=3):
diffusion = Diffusion(gallery, args.cache_dir)
offline = diffusion.get_offline_results(args.truncation_size, args.kd)
time0 = time.time()
print('[search] 1) k-NN search')
sims, ids = diffusion.knn.search(queries, args.kq)
sims = sims ** gamma
qr_num = ids.shape[0]
print('[search] 2) linear combination')
all_scores = np.empty((qr_num, args.truncation_size), dtype=np.float32)
all_ranks = np.empty((qr_num, args.truncation_size), dtype=np.int)
for i in tqdm(range(qr_num), desc='[search] query'):
scores = sims[i] @ offline[ids[i]]
parts = np.argpartition(-scores, args.truncation_size)[:args.truncation_size]
ranks = np.argsort(-scores[parts])
all_scores[i] = scores[parts][ranks]