-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_cmu.py
113 lines (104 loc) · 2.89 KB
/
main_cmu.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
import argparse
import dd_utils
from dataset import CMUDataset
from trainer import CMUTrainer
TEST_SLICES = [2, 3, 4, 5, 6, 13, 14, 15, 16, 17, 18, 19, 20, 21]
def run_function(
ds_dir,
local_desc_model,
retrieval_model,
local_desc_dim,
global_desc_dim,
using_global_descriptors,
convert,
lambda_val,
):
encoder, conf_ns, encoder_global, conf_ns_retrieval = dd_utils.prepare_encoders(
local_desc_model, retrieval_model, global_desc_dim
)
if using_global_descriptors:
print(f"Using {local_desc_model} and {retrieval_model}-{global_desc_dim}")
else:
print(f"Using {local_desc_model}")
results = []
for slice_ in TEST_SLICES:
print(f"Processing slice {slice_}")
train_ds_ = CMUDataset(ds_dir=f"{ds_dir}/slice{slice_}")
test_ds_ = CMUDataset(ds_dir=f"{ds_dir}/slice{slice_}", train=False)
trainer_ = CMUTrainer(
train_ds_,
test_ds_,
local_desc_dim,
global_desc_dim,
encoder,
encoder_global,
conf_ns,
conf_ns_retrieval,
using_global_descriptors,
convert_to_db_desc=convert,
lambda_val=lambda_val,
)
query_results = trainer_.evaluate()
results.extend(query_results)
trainer_.clear()
del trainer_
train_ds_.clear()
if using_global_descriptors:
result_file = open(
f"output/cmu/CMU_eval_{local_desc_model}_{retrieval_model}_{global_desc_dim}_{convert}.txt",
"w",
)
else:
result_file = open(
f"output/cmu/CMU_eval_{local_desc_model}.txt",
"w",
)
for line in results:
print(line, file=result_file)
result_file.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--dataset",
type=str,
default="datasets/datasets/cmu_extended",
help="Path to the dataset, default: %(default)s",
)
parser.add_argument("--use_global", type=int, default=1)
parser.add_argument("--convert", type=int, default=1)
parser.add_argument(
"--lambda_val",
type=float,
default=0.3,
)
parser.add_argument(
"--local_desc",
type=str,
default="d2net",
)
parser.add_argument(
"--local_desc_dim",
type=int,
default=512,
)
parser.add_argument(
"--global_desc",
type=str,
default="eigenplaces",
)
parser.add_argument(
"--global_desc_dim",
type=int,
default=2048,
)
args = parser.parse_args()
run_function(
args.dataset,
args.local_desc,
args.global_desc,
int(args.local_desc_dim),
int(args.global_desc_dim),
bool(args.use_global),
bool(args.convert),
float(args.lambda_val),
)