-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_res.py
60 lines (50 loc) · 1.56 KB
/
extract_res.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 json
keys = ['s_nce', 'length', 'grad_adv', 'hard']
def get_acc_agg_lp(lines, dict):
acc = eval(lines[-2].strip().split(' ')[-1])
lp = eval(lines[-1].strip().split('/t')[-1].split(' ')[-1])
agg = eval(lines[-1].strip().split('/t')[0].split(' ')[-1])
dict['acc'].append(acc)
dict['agg'].append(agg)
dict['lp'].append(lp)
return dict
def get_other(line, dict):
line = line.strip()
if line.split(' ')[-2][:-1] in keys:
dict[line.split(' ')[-2][:-1]].append(eval(line.split(' ')[-1]))
return dict
def split_files(root):
files = os.listdir(root)
file_list = []
for f in files:
if f.startswith('log') and f.split('_')[-1].startswith('0'):
file_list.append(os.path.join(root, f))
return file_list
if __name__ == "__main__":
root = '/data1/lijingru/DFKD/checkpoints/datafree-adadfkd/'
lists = split_files(root)
dict = {
'teacher':[],
'student':[],
's_nce':[],
'hard':[],
'length':[],
'grad_adv':[],
'acc':[],
'agg':[],
'lp':[],
}
for f in lists:
print(f)
path = f.split('/')[-1]
dict['teacher'].append(path.split('-')[2])
dict['student'].append(path.split('-')[3])
lines = open(f, 'r').readlines()
for line in lines:
if line.split(' ')[3] == 'INFO:':
dict = get_other(line, dict)
dict = get_acc_agg_lp(lines, dict)
with open('output_res.json', 'w') as f:
res = json.dumps(dict)
f.write(res)