-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
executable file
·383 lines (331 loc) · 21.8 KB
/
test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
import argparse
import os
import time
import pickle
import numpy as np
import torch
from torch.utils.model_zoo import load_url
from torchvision import transforms
from lib.networks.imageretrievalnet import init_network, extract_vectors
from lib.datasets.datahelpers import cid2filename
from lib.datasets.testdataset import configdataset
from lib.utils.download import download_train, download_test
from lib.utils.whiten import whitenlearn, whitenapply
from lib.utils.evaluate import compute_map_and_print
from lib.utils.general import get_data_root, htime
PRETRAINED = {
'retrievalSfM120k-vgg16-gem' : 'http://cmp.felk.cvut.cz/cnnimageretrieval/data/networks/retrieval-SfM-120k/retrievalSfM120k-vgg16-gem-b4dcdc6.pth',
'retrievalSfM120k-resnet101-gem' : 'http://cmp.felk.cvut.cz/cnnimageretrieval/data/networks/retrieval-SfM-120k/retrievalSfM120k-resnet101-gem-b80fb85.pth',
# new networks with whitening learned end-to-end
'rSfM120k-tl-resnet50-gem-w' : 'http://cmp.felk.cvut.cz/cnnimageretrieval/data/networks/retrieval-SfM-120k/rSfM120k-tl-resnet50-gem-w-97bf910.pth',
'rSfM120k-tl-resnet101-gem-w' : 'http://cmp.felk.cvut.cz/cnnimageretrieval/data/networks/retrieval-SfM-120k/rSfM120k-tl-resnet101-gem-w-a155e54.pth',
'rSfM120k-tl-resnet152-gem-w' : 'http://cmp.felk.cvut.cz/cnnimageretrieval/data/networks/retrieval-SfM-120k/rSfM120k-tl-resnet152-gem-w-f39cada.pth',
'gl18-tl-resnet50-gem-w' : 'http://cmp.felk.cvut.cz/cnnimageretrieval/data/networks/gl18/gl18-tl-resnet50-gem-w-83fdc30.pth',
'gl18-tl-resnet101-gem-w' : 'http://cmp.felk.cvut.cz/cnnimageretrieval/data/networks/gl18/gl18-tl-resnet101-gem-w-a4d43db.pth',
'gl18-tl-resnet152-gem-w' : 'http://cmp.felk.cvut.cz/cnnimageretrieval/data/networks/gl18/gl18-tl-resnet152-gem-w-21278d5.pth',
# pretrained studnet models without teacher:
'efficientnet-b3-gem-contr_2048' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_2048.pth.tar',
'efficientnet-b3-gem-contr_512' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_512.pth.tar',
'mobilenet-v2-gem-contr-2048' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_2048.pth.tar',
'mobilenet-v2-gem-contr-512' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_512.pth.tar',
# pretrained studnet models with teacher:
'efficientnet-b3-gem-contr-plus-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_plus_resnet101.pth.tar',
'efficientnet-b3-gem-contr-plus-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_plus_vgg16.pth.tar',
'efficientnet-b3-gem-reg-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_reg_resnet101.pth.tar',
'efficientnet-b3-gem-reg-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_reg_vgg16.pthaa.tar',
'efficientnet-b3-gem-contr-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_resnet101.pth.tar',
'efficientnet-b3-gem-contr-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_vgg16.pth.tar',
'efficientnet-b3-gem-dark-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_dark_resnet101.pth.tar',
'efficientnet-b3-gem-dark-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_dark_vgg16.pth.tar',
'efficientnet-b3-gem-ms-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_ms_resnet101.pth.tar',
'efficientnet-b3-gem-ms-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_ms_vgg16.pth.tar',
'efficientnet-b3-gem-rkd-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_rkd_resnet101.pth.tar',
'efficientnet-b3-gem-rkd-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_rkd_vgg16.pth.tar',
'efficientnet-b3-gem-triplet-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_triplet_resnet101.pth.tar',
'efficientnet-b3-gem-triplet-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_triplet_vgg16.pth.tar',
'mobilenet-v2-gem-contr-plus-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_plus_resnet101.pth.tar',
'mobilenet-v2-gem-contr-plus-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_plus_vgg16.pth.tar',
'mobilenet-v2-gem-reg-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_reg_resnet101.pth.tar',
'mobilenet-v2-gem-reg-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_reg_vgg16.pth.tar',
'mobilenet-v2-gem-contr-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_resnet101.pth.tar',
'mobilenet-v2-gem-contr-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_vgg16.pth.tar',
'mobilenet-v2-gem-dark-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_dark_resnet101.pth.tar',
'mobilenet-v2-gem-dark-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_dark_vgg16.pth.tar',
'mobilenet-v2-gem-ms-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_ms_resnet101.pth.tar',
'mobilenet-v2-gem-ms-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_ms_vgg16.pth.tar',
'mobilenet-v2-gem-rkd-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_rkd_resnet101.pth.tar',
'mobilenet-v2-gem-rkd-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_rkd_vgg16.pth.tar',
'mobilenet-v2-gem-triplet-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_triplet_resnet101.pth.tar',
'mobilenet-v2-gem-triplet-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_triplet_vgg16.pth.tar'
}
PRETRAINED_WHITENING = {
# pretrained whitening for studnet models without teacher:
'efficientnet-b3-gem-contr_2048' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_2048_whitening.pth',
'efficientnet-b3-gem-contr_512' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_512_whitening.pth',
'mobilenet-v2-gem-contr-2048' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_2048_whitening.pth',
'mobilenet-v2-gem-contr-512' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_512_whitening.pth',
# pretrained whitening for studnet models with teacher:
'efficientnet-b3-gem-contr-plus-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_plus_resnet101_whitening.pth',
'efficientnet-b3-gem-contr-plus-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_plus_vgg16_whitening.pth',
'efficientnet-b3-gem-reg-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_reg_resnet101_whitening.pth',
'efficientnet-b3-gem-reg-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_reg_vgg16_whitening.pth',
'efficientnet-b3-gem-contr-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_resnet101_whitening.pth',
'efficientnet-b3-gem-contr-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_contr_vgg16_whitening.pth',
'efficientnet-b3-gem-dark-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_dark_resnet101_whitening.pth',
'efficientnet-b3-gem-dark-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_dark_vgg16_whitening.pth',
'efficientnet-b3-gem-ms-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_ms_resnet101_whitening.pth',
'efficientnet-b3-gem-ms-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_ms_vgg16_whitening.pth',
'efficientnet-b3-gem-rkd-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_rkd_resnet101_whitening.pth',
'efficientnet-b3-gem-rkd-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_rkd_vgg16_whitening.pth',
'efficientnet-b3-gem-triplet-resnet101' : 'http://files.inria.fr/aml/efficientnet_b3_gem_triplet_resnet101_whitening.pth',
'efficientnet-b3-gem-triplet-vgg16' : 'http://files.inria.fr/aml/efficientnet_b3_gem_triplet_vgg16_whitening.pth',
'mobilenet-v2-gem-contr-plus-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_plus_resnet101_whitening.pth',
'mobilenet-v2-gem-contr-plus-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_plus_vgg16_whitening.pth',
'mobilenet-v2-gem-reg-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_reg_resnet101_whitening.pth',
'mobilenet-v2-gem-reg-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_reg_vgg16_whitening.pth',
'mobilenet-v2-gem-contr-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_resnet101_whitening.pth',
'mobilenet-v2-gem-contr-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_contr_vgg16_whitening.pth',
'mobilenet-v2-gem-dark-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_dark_resnet101_whitening.pth',
'mobilenet-v2-gem-dark-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_dark_vgg16_whitening.pth',
'mobilenet-v2-gem-ms-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_ms_resnet101_whitening.pth',
'mobilenet-v2-gem-ms-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_ms_vgg16_whitening.pth',
'mobilenet-v2-gem-rkd-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_rkd_resnet101_whitening.pth',
'mobilenet-v2-gem-rkd-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_rkd_vgg16_whitening.pth',
'mobilenet-v2-gem-triplet-resnet101' : 'http://files.inria.fr/aml/mobilenet_v2_gem_triplet_resnet101_whitening.pth',
'mobilenet-v2-gem-triplet-vgg16' : 'http://files.inria.fr/aml/mobilenet_v2_gem_triplet_vgg16_whitening.pth'
}
datasets_names = ['oxford5k', 'paris6k', 'roxford5k', 'rparis6k', 'retrieval-SfM-120k', 'instre']
whitening_names = ['retrieval-SfM-30k', 'retrieval-SfM-120k']
parser = argparse.ArgumentParser(description='PyTorch CNN Image Retrieval Testing')
# network
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--network-path', '-npath', metavar='NETWORK',
help="pretrained network or network path (destination where network is saved)")
group.add_argument('--network-offtheshelf', '-noff', metavar='NETWORK',
help="off-the-shelf network, in the format 'ARCHITECTURE-POOLING' or 'ARCHITECTURE-POOLING-{reg-lwhiten-whiten}'," +
" examples: 'resnet101-gem' | 'resnet101-gem-reg' | 'resnet101-gem-whiten' | 'resnet101-gem-lwhiten' | 'resnet101-gem-reg-whiten'")
# test options
parser.add_argument('--datasets', '-d', metavar='DATASETS', default='roxford5k,rparis6k',
help="comma separated list of test datasets: " +
" | ".join(datasets_names) +
" (default: 'oxford5k,paris6k')")
parser.add_argument('--image-size', '-imsize', default=1024, type=int, metavar='N',
help="maximum size of longer image side used for testing (default: 1024)")
parser.add_argument('--multiscale', '-ms', metavar='MULTISCALE', default='[1]',
help="use multiscale vectors for testing, " +
" examples: '[1]' | '[1, 1/2**(1/2), 1/2]' | '[1, 2**(1/2), 1/2**(1/2)]' (default: '[1]')")
parser.add_argument('--whitening', '-w', metavar='WHITENING', default=None, choices=whitening_names,
help="dataset used to learn whitening for testing: " +
" | ".join(whitening_names) +
" (default: None)")
parser.add_argument('--workers', '-j', default=8, type=int, metavar='N',
help='number of data loading workers (default: 8)')
# GPU ID
parser.add_argument('--gpu-id', '-g', default='0', metavar='N',
help="gpu id used for testing (default: '0')")
parser.add_argument('--teacher', '-t', default='vgg16', metavar='TEACHER',
help="The teacher used for training of the student model.")
parser.add_argument('--asym', dest='asym', action='store_true',
help='Runs symmetric testing by default')
def main():
args = parser.parse_args()
# check if there are unknown datasets
for dataset in args.datasets.split(','):
if dataset not in datasets_names:
raise ValueError('Unsupported or unknown dataset: {}!'.format(dataset))
# check if test dataset are downloaded
# and download if they are not
data_root = get_data_root()
#download_train(get_data_root())
download_test(data_root)
model_path = os.path.join(data_root, 'model')
# setting up the visible GPU
os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id
if args.asym:
t_name = 'retrievalSfM120k-%s-gem' % (args.teacher)
state = load_url(PRETRAINED[t_name], model_dir=model_path)
net_params_teacher = {}
net_params_teacher['architecture'] = state['meta']['architecture']
net_params_teacher['pooling'] = state['meta']['pooling']
net_params_teacher['local_whitening'] = state['meta'].get('local_whitening', False)
net_params_teacher['regional'] = state['meta'].get('regional', False)
net_params_teacher['whitening'] = state['meta'].get('whitening', False)
net_params_teacher['mean'] = state['meta']['mean']
net_params_teacher['std'] = state['meta']['std']
net_params_teacher['pretrained'] = True
net_teacher = init_network(net_params_teacher)
net_teacher.load_state_dict(state['state_dict'])
if 'Lw' in state['meta']:
net_teacher.meta['Lw'] = state['meta']['Lw']
# loading network from path
if args.network_path is not None:
print(">> Loading network:\n>>>> '{}'".format(args.network_path))
if args.network_path in PRETRAINED:
# pretrained networks (downloaded automatically)
#state = load_url(PRETRAINED[args.network_path], model_dir=os.path.join(get_data_root(), 'networks'))
state = load_url(PRETRAINED[args.network_path], model_dir=model_path)
else:
# fine-tuned network from path
state = torch.load(args.network_path)
# parsing net params from meta
# architecture, pooling, mean, std required
# the rest has default values, in case that is doesnt exist
net_params = {}
net_params['architecture'] = state['meta']['architecture']
net_params['pooling'] = state['meta']['pooling']
net_params['local_whitening'] = state['meta'].get('local_whitening', False)
net_params['regional'] = state['meta'].get('regional', False)
net_params['whitening'] = state['meta'].get('whitening', False)
net_params['mean'] = state['meta']['mean']
net_params['std'] = state['meta']['std']
net_params['pretrained'] = False
if args.teacher == 'resnet101':
net_params['teacher'] = 'resnet101'
else:
net_params['teacher'] = 'vgg16'
# load network
net = init_network(net_params)
#pdb.set_trace()
net.load_state_dict(state['state_dict'])
# if whitening is precomputed
if 'Lw' in state['meta']:
net.meta['Lw'] = state['meta']['Lw']
print(">>>> loaded network: ")
print(net.meta_repr())
# loading offtheshelf network
elif args.network_offtheshelf is not None:
# parse off-the-shelf parameters
offtheshelf = args.network_offtheshelf.split('-')
net_params = {}
net_params['architecture'] = offtheshelf[0]
net_params['pooling'] = offtheshelf[1]
net_params['local_whitening'] = 'lwhiten' in offtheshelf[2:]
net_params['regional'] = 'reg' in offtheshelf[2:]
net_params['whitening'] = 'whiten' in offtheshelf[2:]
net_params['pretrained'] = True
# load off-the-shelf network
print(">> Loading off-the-shelf network:\n>>>> '{}'".format(args.network_offtheshelf))
net = init_network(net_params)
print(">>>> loaded network: ")
print(net.meta_repr())
# setting up the multi-scale parameters
ms = list(eval(args.multiscale))
if len(ms)>1 and net.meta['pooling'] == 'gem' and not net.meta['regional'] and not net.meta['whitening']:
msp = net.pool.p.item()
print(">> Set-up multiscale:")
print(">>>> ms: {}".format(ms))
print(">>>> msp: {}".format(msp))
else:
msp = 1
# moving network to gpu and eval mode
net.cuda()
net.eval()
# set up the transform
normalize = transforms.Normalize(
mean=net.meta['mean'],
std=net.meta['std']
)
transform = transforms.Compose([
transforms.ToTensor(),
normalize
])
if args.asym:
log_out = './log_test_asym.txt'
else:
log_out = './log_test.txt'
log = open(log_out,'a')
# compute whitening
if args.whitening is not None:
start = time.time()
if args.asym:
net_wh = net_teacher
else:
net_wh = net
if 'Lw' in net_wh.meta and args.whitening in net_wh.meta['Lw']:
print('>> {}: Whitening is precomputed, loading it...'.format(args.whitening))
if len(ms)>1:
Lw = net_wh.meta['Lw'][args.whitening]['ms']
else:
Lw = net_wh.meta['Lw'][args.whitening]['ss']
else:
# if we evaluate networks from path we should save/load whitening
# not to compute it every time
if args.network_path is not None and args.network_path in PRETRAINED_WHITENING:
whiten_fn = args.network_path.split('.')[0] + '_whitening.pth'
elif args.network_path is not None:
whiten_fn = args.network_path + '_{}_whiten'.format(args.whitening)
if len(ms) > 1:
whiten_fn += '_ms'
whiten_fn += '.pth'
else:
whiten_fn = None
if args.network_path in PRETRAINED_WHITENING:
Lw = load_url(PRETRAINED_WHITENING[args.network_path], model_dir=model_path)
elif whiten_fn is not None and os.path.isfile(whiten_fn):
print('>> {}: Whitening is precomputed, loading it...'.format(args.whitening))
Lw = torch.load(whiten_fn)
else:
print('>> {}: Learning whitening...'.format(args.whitening))
# loading db
db_root = os.path.join(get_data_root(), 'train', args.whitening)
ims_root = os.path.join(db_root, 'ims')
db_fn = os.path.join(db_root, '{}-whiten.pkl'.format(args.whitening))
with open(db_fn, 'rb') as f:
db = pickle.load(f)
images = [cid2filename(db['cids'][i], ims_root) for i in range(len(db['cids']))]
# extract whitening vectors
print('>> {}: Extracting...'.format(args.whitening))
wvecs = extract_vectors(net_wh, images, args.image_size, transform, ms=ms, msp=msp, workers=args.workers)
# learning whitening
print('>> {}: Learning...'.format(args.whitening))
wvecs = wvecs.numpy()
m, P = whitenlearn(wvecs, db['qidxs'], db['pidxs'])
Lw = {'m': m, 'P': P}
# saving whitening if whiten_fn exists
if whiten_fn is not None:
print('>> {}: Saving to {}...'.format(args.whitening, whiten_fn))
torch.save(Lw, whiten_fn)
print('>> {}: elapsed time: {}'.format(args.whitening, htime(time.time()-start)))
else:
Lw = None
# evaluate on test datasets
datasets = args.datasets.split(',')
for dataset in datasets:
start = time.time()
print('>> {}: Extracting...'.format(dataset))
# prepare config structure for the test dataset
cfg = configdataset(dataset, os.path.join(get_data_root(), 'test'))
#cfg = configdataset(dataset,data_path)
images = [cfg['im_fname'](cfg,i) for i in range(cfg['n'])]
qimages = [cfg['qim_fname'](cfg,i) for i in range(cfg['nq'])]
try:
bbxs = [tuple(cfg['gnd'][i]['bbx']) for i in range(cfg['nq'])]
except:
bbxs = None # for holidaysmanrot and copydays
# extract database and query vectors
print('>> {}: database images...'.format(dataset))
if args.asym:
vecs = extract_vectors(net_teacher, images, args.image_size, transform, ms=ms, msp=msp)
else:
vecs = extract_vectors(net, images, args.image_size, transform, ms=ms, msp=msp, workers=args.workers)
print('>> {}: query images...'.format(dataset))
qvecs = extract_vectors(net, qimages, args.image_size, transform, bbxs=bbxs, ms=ms, msp=msp, workers=args.workers)
print('>> {}: Evaluating...'.format(dataset))
# convert to numpy
vecs = vecs.numpy()
qvecs = qvecs.numpy()
# search, rank, and print
scores = np.dot(vecs.T, qvecs)
ranks = np.argsort(-scores, axis=0)
compute_map_and_print(dataset, ranks, cfg['gnd'], log)
if Lw is not None:
# whiten the vectors
vecs_lw = whitenapply(vecs, Lw['m'], Lw['P'])
qvecs_lw = whitenapply(qvecs, Lw['m'], Lw['P'])
# search, rank, and print
scores = np.dot(vecs_lw.T, qvecs_lw)
ranks = np.argsort(-scores, axis=0)
compute_map_and_print(dataset + ' + whiten', ranks, cfg['gnd'], log)
print('>> {}: elapsed time: {}'.format(dataset, htime(time.time()-start)))
if __name__ == '__main__':
main()