-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
75 lines (66 loc) · 2.66 KB
/
example.py
File metadata and controls
75 lines (66 loc) · 2.66 KB
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
import os
import numpy as np
import pandas as pd
def method_command_config(method):
if method == "CGA-dHash":
return "--method CGA-dHash --cga_n_gen 100"
elif method == "CGA-DFT":
return "--method CGA-DFT --cga_n_gen 100"
elif method == "aHash":
return "--method aHash"
elif method == "dHash":
return "--method dHash"
elif method == "MinMax":
return "--method MinMax"
elif method == "DFT":
return "--method DFT"
elif method == "ITQ":
return "--method ITQ"
elif method == "LBP":
return "--method LBP"
elif method == "LSH":
return "--method LSH"
elif method == "DHN":
return "--method DHN"
elif method == "DSH":
return "--method DSH"
elif method == "DTSH":
return "--method DTSH"
elif method == "CSQ":
return "--method CSQ"
elif method == "DPSH":
return "--method DPSH"
elif method == "Quantization":
return "--method Quantization"
else:
raise ValueError(f"Method {method} not found")
if __name__ == "__main__":
dataset = "tcga_pulmonary_densenet121"
feature_selection = ""
num_runs = 5
methods = ["aHash", "dHash", "MinMax", "DFT", "ITQ", "LBP", "LSH", "DHN", "DSH", "DTSH", "CSQ", "DPSH", "Quantization", "CGA-dHash", "CGA-DFT"]
for run in range(num_runs):
random_seed = np.random.randint(0, 1000000)
for method in methods:
if os.path.exists(os.path.join("results", f"{dataset}_{feature_selection}_{method}.csv")):
df = pd.read_csv(os.path.join("results", f"{dataset}_{feature_selection}_{method}.csv"))
if df.shape[0] == num_runs:
print(f"Skipping {method} because all runs are completed")
continue
command = f"python main.py"
command += f" --seed {random_seed} "
command += f" --dataset {dataset} "
command += f" --download "
command += f" --k 10 "
command += method_command_config(method)
os.system(command)
comparison_df = pd.DataFrame()
for method in methods:
df = pd.read_csv(os.path.join("results", f"{dataset}_{feature_selection}_{method}.csv"))
comparison_df[method] = df.mean(axis=0)
comparison_df = comparison_df.transpose()
comparison_df.columns = ["F1", "Precision@10", "mAP"]
comparison_df["Method"] = methods
comparison_df = comparison_df[["Method", "F1", "Precision@10", "mAP"]]
# comparison_df = comparison_df.sort_values(by="F1", ascending=False)
comparison_df.to_csv(os.path.join("results",f"{dataset}_{feature_selection}_summary.csv"), index=False)