-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_log.py
60 lines (49 loc) · 1.55 KB
/
read_log.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
import os
import argparse
# def max_test(path):
# f = open(path)
# print(path)
# acc_list = []
# line = f.readline()
# while line:
# if 'Global Test Class Acc' in line:
# # import pdb; pdb.set_trace()
# acc_list.append(float(line.split('Global Test Class Acc: ')[1].replace('\n','')))
# line = f.readline()
# f.close()
# print(max(acc_list))
# return max(acc_list)
def max_test(path):
f = open(path)
print(path)
best_acc = 0
incomplete_flag = True
line = f.readline()
line_pre = ''
while line:
if 'Saving current best checkpoints to' in line:
# import pdb; pdb.set_trace()
best_acc = float(line_pre.split('Global Test Class Acc: ')[1].replace('\n',''))
if 'Global iter is 499' in line:
incomplete_flag = False
line_pre = line
line = f.readline()
f.close()
print(best_acc)
if incomplete_flag:
print('Incomplete!')
return best_acc
# dirpath = '/home/cjm/disk1/research/DG4FL/logs/fedavg_adain_overall_multi_resnet50_RSC'
parser = argparse.ArgumentParser()
parser.add_argument('--path', type = str, help ='log dir path')
args = parser.parse_args()
dirpath = args.path
acc_list = []
for subdir, dirs, files in os.walk(dirpath):
for filename in files:
filepath = subdir + os.sep + filename
# if filepath.endswith("fedavg.log"):
if filepath.endswith(".log"):
acc_list.append(max_test(filepath))
import numpy as np
print(f'Average: {np.mean(acc_list)}')