-
Notifications
You must be signed in to change notification settings - Fork 0
/
painting_retrieval_evaluation.py
49 lines (38 loc) · 2.06 KB
/
painting_retrieval_evaluation.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
import argparse
import os
from estensi.painting_detection.evaluation import get_test_set_dict, create_test_set
from estensi.painting_retrieval.evaluation import eval_test_set
def arg_parse():
parser = argparse.ArgumentParser(description='Vision and Cognitive Systems project: Gallerie Estensi')
parser.add_argument('--mode', dest='mode', help='select between classification or retrieval evaluation mode',
type=str, choices=['classification', 'retrieval'], required=True)
parser.add_argument('--rank_scope', dest='rank_scope',
help='scope of the ranking list where a relevant item can be found. '
'It will be ignored in classification mode.',
type=int, choices=range(1, 96), required=False)
return parser.parse_args()
def main():
args = arg_parse()
path = os.path.abspath(os.path.dirname(__file__))
# Create test set from selected videos
dataset_dir_path = os.path.join(path, "dataset")
test_set_dict = get_test_set_dict(dataset_dir_path=dataset_dir_path)
test_set_dir_path = os.path.join(path, "dataset", "test_set")
create_test_set(test_set_dict=test_set_dict, test_set_dir_path=test_set_dir_path)
ground_truth_set_dir_path = os.path.join(path, "dataset", "ground_truth")
db_dir_path = os.path.join(path, "dataset", "paintings_db")
# Evaluate painting retrieval on test set
mode = args.mode
rank_scope = args.rank_scope
if rank_scope is None:
rank_scope = 5
mean_avg_precision = eval_test_set(test_set_dir_path=test_set_dir_path,
ground_truth_set_dir_path=ground_truth_set_dir_path,
db_dir_path=db_dir_path,
files_dir_path=dataset_dir_path,
mode=mode,
rank_scope=rank_scope,
verbose=True)
print("map = {:.2f}".format(mean_avg_precision))
if __name__ == '__main__':
main()