-
Notifications
You must be signed in to change notification settings - Fork 8
/
ensemble_dist.py
51 lines (38 loc) · 1.44 KB
/
ensemble_dist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import numpy as np
import os
import json
base_dir = '../model/'
query_1 = np.load(base_dir + '1229-a-1/query_path_1.npy')
gallery_1 = np.load(base_dir + '1229-a-1/gallery_path_1.npy')
print(len(query_1), len(gallery_1))
query_2 = np.load(base_dir + '1229-a-1/query_path_2.npy')
gallery_2 = np.load(base_dir + '1229-a-1/gallery_path_2.npy')
print(len(query_2), len(gallery_2))
distmat_1 = np.load(base_dir + '1229-a-1/dist_mat_1.npy')
distmat_1 += np.load(base_dir + '0102-b-2/dist_mat_1.npy')
distmat_1 += np.load(base_dir + '0102-a-se-1/dist_mat_1.npy')
print(distmat_1.shape)
indexes = np.argsort(distmat_1, axis=1)
res_1 = {}
for idx, index in enumerate(indexes):
query = os.path.basename(query_1[idx])
gallery = [os.path.basename(i) for i in gallery_1[index][:200].tolist()]
res_1[query] = gallery
distmat_2 = np.load(base_dir + '1229-a-1/dist_mat_2.npy')
distmat_2 += np.load(base_dir + '0102-b-2/dist_mat_2.npy')
distmat_2 += np.load(base_dir + '0102-a-se-1/dist_mat_2.npy')
print(distmat_2.shape)
indexes = np.argsort(distmat_2, axis=1)
res_2 = {}
for idx, index in enumerate(indexes):
query = os.path.basename(query_2[idx])
gallery = [os.path.basename(i) for i in gallery_2[index][:200].tolist()]
res_2[query] = gallery
data = dict()
for k, v in res_1.items():
data[k] = v
for k, v in res_2.items():
data[k] = v
save_path = 'submit_final.json'
print("Writing to {}".format(save_path))
json.dump(data, open(save_path, 'w'))