forked from wkentaro/pytorch-fcn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarize_logs.py
executable file
·55 lines (47 loc) · 1.38 KB
/
summarize_logs.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
#!/usr/bin/env python
import os
import os.path as osp
import pandas as pd
import tabulate
import yaml
def main():
logs_dir = 'logs'
headers = [
'name',
'model',
'git_hash',
'pretrained_model',
'epoch',
'iteration',
'valid/mean_iu',
]
rows = []
for log in os.listdir(logs_dir):
log_dir = osp.join(logs_dir, log)
if not osp.isdir(log_dir):
continue
try:
log_file = osp.join(log_dir, 'log.csv')
df = pd.read_csv(log_file)
columns = [c for c in df.columns if not c.startswith('train')]
df = df[columns]
df = df.set_index(['epoch', 'iteration'])
index_best = df['valid/mean_iu'].idxmax()
row_best = df.loc[index_best].dropna()
with open(osp.join(log_dir, 'config.yaml')) as f:
config = yaml.load(f)
except Exception:
continue
rows.append([
osp.join(logs_dir, log),
config['model'],
config['git_hash'],
config.get('pretrained_model', None),
row_best.index[0][0],
row_best.index[0][1],
100 * row_best['valid/mean_iu'].values[0],
])
rows.sort(key=lambda x: x[-1], reverse=True)
print(tabulate.tabulate(rows, headers=headers))
if __name__ == '__main__':
main()