-
Notifications
You must be signed in to change notification settings - Fork 1
/
captaincook4d_results.py
105 lines (82 loc) · 3.44 KB
/
captaincook4d_results.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
# This script is used to calculate the mean and standard deviation of the results obtained from the experiments
# It also generate some json files with the results obtained (you can compare them with Table 1 of the paper).
import os
import json
import numpy as np
import matplotlib.pyplot as plt
def main():
tgl = "./Experiments"
tgl_list = os.listdir(tgl)
tgl_list = sorted(tgl_list)
if len(tgl_list) < 24:
print("There are missing experiments")
print("Plese run: python train_all.py --more_seeds")
return
output_results = {}
for folder in tgl_list:
scenario = folder
output_results[scenario] = {}
file = os.path.join(tgl, folder)
for file in os.listdir(file):
if file.endswith(".json"):
output_results[scenario][file.split(".")[0] + "_tgl"] = json.load(open(os.path.join(tgl, folder, file)))
keys = list(output_results["blenderbananapancakes"].keys())
output_results_mean = {}
for key in keys:
output_results_mean[key] = {
"Precision": 0,
"Recall": 0,
"F1": 0
}
for scenario in output_results.keys():
output_results_mean[key]["Precision"] += output_results[scenario][key]["Precision"]
output_results_mean[key]["Recall"] += output_results[scenario][key]["Recall"]
output_results_mean[key]["F1"] += output_results[scenario][key]["F1"]
output_results_mean[key]["Precision"] /= len(output_results.keys())
output_results_mean[key]["Recall"] /= len(output_results.keys())
output_results_mean[key]["F1"] /= len(output_results.keys())
# Take all the metrics for tgl
tgl_metrics = []
for key in output_results_mean.keys():
tgl_metrics.append(
[
output_results_mean[key]["Precision"],
output_results_mean[key]["Recall"],
output_results_mean[key]["F1"]
]
)
tgl_metrics = np.array(tgl_metrics)
mean_errors = np.mean(tgl_metrics, axis=0)
# 2.776 -> 95% confidence interval
std_errors = ((np.std(tgl_metrics, ddof=1, axis=0) / np.sqrt(len(tgl_metrics))) * 2.776)
x = np.arange(len(mean_errors))
os.makedirs("./Table_1", exist_ok=True)
plt.bar(x, mean_errors, yerr=std_errors, capsize=5)
plt.xlabel('Error Metric Index')
plt.ylabel('Error Value')
plt.title('Mean Errors with Standard Deviation')
plt.xticks(x, ['Precision', 'Recall', 'F1'])
plt.savefig("./Table_1/captaincook4d_errors_tgl.png")
plt.show()
std_errors = std_errors * 100
# Save the errors in a JSON file
errors = {
"Precision": std_errors[0],
"Recall": std_errors[1],
"F1": std_errors[2]
}
means = {
"Precision": mean_errors[0],
"Recall": mean_errors[1],
"F1": mean_errors[2]
}
# Create JSON file with the mean results using DO
json.dump(means, open("./Table_1/captaincook4d_means_do.json", "w"), indent=4)
# Create JSON file with the errors using DO
json.dump(errors, open("./Table_1/captaincook4d_errors_do.json", "w"), indent=4)
# Create JSON file with the mean results
json.dump(output_results_mean, open("./Table_1/captaincook4d_results_mean.json", "w"), indent=4)
# Create a JSON file with the results
json.dump(output_results, open("./Table_1/captaincook4d_results.json", "w"), indent=4)
if __name__ == "__main__":
main()