-
Notifications
You must be signed in to change notification settings - Fork 16
/
eval.py
58 lines (50 loc) · 2.17 KB
/
eval.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
import os
import argparse
import logging
from lib import evaluation
logging.basicConfig()
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--dataset', default='coco',
help='coco or f30k')
parser.add_argument('--data_path', default='/tmp/data/coco')
parser.add_argument('--save_results', action='store_true')
parser.add_argument('--evaluate_cxc', action='store_true')
opt = parser.parse_args()
if opt.dataset == 'coco':
weights_bases = [
'runs/release_weights/coco_butd_region_bert',
'runs/release_weights/coco_butd_grid_bert',
'runs/release_weights/coco_wsl_grid_bert',
]
elif opt.dataset == 'f30k':
weights_bases = [
'runs/release_weights/f30k_butd_region_bert',
'runs/release_weights/f30k_butd_grid_bert',
'runs/release_weights/f30k_wsl_grid_bert',
]
else:
raise ValueError('Invalid dataset argument {}'.format(opt.dataset))
for base in weights_bases:
logger.info('Evaluating {}...'.format(base))
model_path = os.path.join(base, 'model_best.pth')
if opt.save_results: # Save the final results for computing ensemble results
save_path = os.path.join(base, 'results_{}.npy'.format(opt.dataset))
else:
save_path = None
if opt.dataset == 'coco':
if not opt.evaluate_cxc:
# Evaluate COCO 5-fold 1K
evaluation.evalrank(model_path, data_path=opt.data_path, split='testall', fold5=True)
# Evaluate COCO 5K
evaluation.evalrank(model_path, data_path=opt.data_path, split='testall', fold5=False, save_path=save_path)
else:
# Evaluate COCO-trained models on CxC
evaluation.evalrank(model_path, data_path=opt.data_path, split='testall', fold5=True, cxc=True)
elif opt.dataset == 'f30k':
# Evaluate Flickr30K
evaluation.evalrank(model_path, data_path=opt.data_path, split='test', fold5=False, save_path=save_path)
if __name__ == '__main__':
main()