MCPcopy Create free account
hub / github.com/MetaSLAM/SphereVLAD / val

Function val

eval/evaluate_pitt.py:30–85  ·  view source on GitHub ↗
(config, type, noise, trans_noise, rot_noise, log)

Source from the content-addressed store, hash-verified

28
29
30def val(config, type, noise, trans_noise, rot_noise, log):
31 #! Log
32 if log:
33 save_dir = 'log/{}/{}/'.format(config.MODEL.NAME, config.DATA.DATASET_NAME)
34 if not os.path.exists(save_dir):
35 os.makedirs(save_dir)
36 #! Define Model
37 model, gpu_conf = set_lcd_model(config)
38 [_, device, gpu_ids] = gpu_conf
39 #! Define Evaluation Class
40 valPitt = EvaluationPitts(config, model, device)
41 #! Evaluation
42 if type == "recall":
43 total_recalls = []
44 total_time = 0
45 for traj_num in range(21, 22):
46 recalls, _, running_time = valPitt.get_features_recall(traj_num, trans_noise, rot_noise, noise)
47 total_recalls.append(recalls)
48 total_time += running_time
49 total_recalls = np.array(total_recalls).sum(axis=0)
50 log_print('Total Top One Recall is {}'.format(total_recalls[0]/total_recalls[-1]), 'r')
51 log_print('Total Running Time is {}'.format(total_time/total_recalls[-1]), 'r')
52 if log:
53 stats = total_recalls[:-1]/total_recalls[-1]
54 save_file = save_dir + 'recall.txt'
55 file_tosave = open(save_file, 'w+')
56 file_tosave.write('Average recall @1 is: {}\n'.format(stats[0]))
57 file_tosave.write('Average recall @1% is: {}\n'.format(stats[-1]))
58 file_tosave.write('\n')
59 for index, item in enumerate(stats[:-1]):
60 file_tosave.write("Average recall @{} is: {}\n".format(index+1, item))
61 file_tosave.write('\t\n\t\n')
62 file_tosave.close()
63 elif type == "rot":
64 for trans in [1,2,3]:
65 for rot in [30,60,90,120,150,180]:
66 total_recalls = []
67 total_time = 0
68 for traj_num in range(21, 22):
69 recalls, _, running_time = valPitt.get_features_recall(traj_num, trans, rot, noise)
70 total_recalls.append(recalls)
71 total_time += running_time
72 total_recalls = np.array(total_recalls).sum(axis=0)
73 log_print('Total Top One Recall is {}'.format(total_recalls[0]/total_recalls[-1]), 'r')
74 log_print('Total Running Time is {}'.format(total_time/total_recalls[-1]), 'r')
75 if log:
76 stats = total_recalls[:-1]/total_recalls[-1]
77 save_file = save_dir + f'rot_{trans}_{rot}.txt'
78 file_tosave = open(save_file, 'w+')
79 file_tosave.write('Average recall @1 is: {}\n'.format(stats[0]))
80 file_tosave.write('Average recall @1% is: {}\n'.format(stats[-1]))
81 file_tosave.write('\n')
82 for index, item in enumerate(stats[:-1]):
83 file_tosave.write("Average recall @{} is: {}\n".format(index+1, item))
84 file_tosave.write('\t\n\t\n')
85 file_tosave.close()
86
87

Callers 1

evaluate_pitt.pyFile · 0.85

Calls 4

get_features_recallMethod · 0.95
set_lcd_modelFunction · 0.90
EvaluationPittsClass · 0.90
log_printFunction · 0.90

Tested by

no test coverage detected