-
Notifications
You must be signed in to change notification settings - Fork 5
/
parse_digit.py
71 lines (58 loc) · 2.1 KB
/
parse_digit.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
import os
import pandas as pd
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import click
@click.command()
@click.option('--mark', type=str, default=None, help='只显示名字包含mark的实验')
@click.option('--root', type=str, default='./saved-digit', help='要显示的实验路径')
@click.option('--select', type=str, default=None, help='指定第几个tgtdomain')
def show(mark, root, select):
name_list = os.listdir(root)
# 过滤
if mark is not None:
name_list = [name for name in name_list if mark in name]
name_list = sorted(name_list)
rst = None
for i, name in enumerate(name_list):
logpath = os.path.join(root, name, 'test.log')
if select is not None:
logpath_ = os.path.join(root, name, select)
if os.path.exists(logpath_):
logpath = logpath_
if os.path.exists(logpath):
df = pd.read_csv(logpath, index_col=0)
if rst is None:
rst = pd.DataFrame(columns=df.columns)
rst.loc[name] = df.values[0]
rst['mean'] = rst.values[:,1:].mean(1) # 第1列是 mnist,不参与计算
#print(rst)
df2 = avg_run(rst)
print(df2)
def avg_run(df):
''' 同一组实验参数重复跑了n次,该函数负责把这个n平均掉
stn_H_0.3_0.1_run0 ---> stn_H_0.3_0.1
'''
src_index = df.index
new_index = [i.split('_run')[0] for i in src_index]
obj_index = sorted(list(set(new_index)))
columns = df.columns
init = np.zeros([len(obj_index), len(columns)])
df2 = pd.DataFrame(init, index=obj_index, columns=columns)
obj_index_count = {}
for index in new_index:
obj_index_count.update({index:0})
for srcidx, objidx in zip(src_index, new_index):
src_row = df.loc[srcidx]
df2.loc[objidx] += src_row
obj_index_count[objidx] += 1
count = []
for objidx in obj_index:
df2.loc[objidx] /= obj_index_count[objidx]
count.append(obj_index_count[objidx])
df2['N'] = count
return df2
if __name__=='__main__':
show()