-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats_from_txt.py
62 lines (46 loc) · 1.86 KB
/
stats_from_txt.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
from stats import Statistics, CNNParameters
"""
Used parse a txt file into Statistics of trained network
"""
def get_stats(filename):
file = open(filename, "r")
stats = []
while True:
line = file.readline()
while line == '\n':
line = file.readline()
if not line:
break
splits = line.split(', ')
resnet = int(splits[0][6:])
lr = float(splits[1][5:])
batch_size = int(splits[2][13:])
trained_layers = int(splits[3][17:])
n_outputs = int(splits[4][12:])
stat = Statistics()
stat.cnn_parameters = CNNParameters(resnet, batch_size, trained_layers, n_outputs, lr)
x = "train"
while True:
line = file.readline()
if line[:5] != x:
break
splits = line.split(' ')
stat.epochs[x].append(int(splits[4]))
stat.accuracies[x].append(float(splits[7][:len(splits[7]) - 1]))
stat.times[x].append(float(splits[9][:len(splits[9]) - 1]) * 60 + float(splits[10][:len(splits[10]) - 2]))
x = "val"
while True:
if line[:3] != x:
break
splits = line.split(' ')
stat.epochs[x].append(float(splits[4]))
stat.accuracies[x].append(float(splits[7][:len(splits[7]) - 1]))
stat.times[x].append(float(splits[9][:len(splits[9]) - 1]) * 60 + float(splits[10][:len(splits[10]) - 2]))
line = file.readline()
splits = line.split(' ')
stat.time_elapsed = float(splits[3][:len(splits[3]) - 1]) * 60 + float(splits[4][:len(splits[4]) - 1])
splits = file.readline().split(' ')
stat.best_acc = float(splits[3])
stats.append(stat)
file.close()
return stats