-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_log.py
More file actions
43 lines (34 loc) · 1.23 KB
/
read_log.py
File metadata and controls
43 lines (34 loc) · 1.23 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
import numpy as np
import os
def read_a_log(file_path):
'''read files that end with .log. e.g., log20220105_0.log'''
with open(file_path, 'r') as f:
lines = f.readlines()
content = eval(lines[-2].rstrip()) # get the last line and transform it into a dict object
acc = content['uniform holdout']['acc']
return acc
def process_dir(current_dir):
'''process a directory. e.g., grid(2,5)'''
accs = []
for log_file in sorted(os.listdir(current_dir)):
file_path = os.path.join(current_dir, log_file)
acc = read_a_log(file_path)
accs.append(acc)
acc_mean = np.mean(accs) # mean
acc_std = np.std(accs) # standard deviation
acc_sem = acc_std / np.sqrt(10) # standard error of the mean
return acc_mean, acc_sem
def main():
res = {}
result_dir = "./results/"
dir_list = os.listdir(result_dir)
dir_list.sort(key = lambda x: int(x[:5]))
for name in sorted(dir_list):
tmp_dir = os.path.join(result_dir, name)
acc_mean, acc_sem = process_dir(tmp_dir)
tmp = {"acc_mean": acc_mean, "acc_sem": acc_sem}
res[name] = tmp
#print(f"{name} 'mean': {acc_mean} | 'sem': {acc_sem}")
print(res)
if __name__ == "__main__":
main()