-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRankNetworks.py
161 lines (151 loc) · 6.95 KB
/
RankNetworks.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import numpy as np
from numpy import inf
import keras
import matplotlib
import math
import matplotlib.pyplot as plt
from sklearn import preprocessing
from sklearn.metrics import roc_auc_score, roc_curve, auc
from sklearn.model_selection import train_test_split
from IPython.display import FileLink, FileLinks
from keras.models import Sequential
from keras.layers import Dense, Dropout, BatchNormalization
from keras.utils import to_categorical, plot_model
from keras.callbacks import History, ModelCheckpoint, ReduceLROnPlateau
from keras.optimizers import Adam
from keras import metrics
import pickle
import os
from functions import *
def RankNetworks(outputfolder):
# Get all the model folders
modellist = os.listdir(outputfolder)
# Loop over them, open the correct file
modelresults_lumiweighted = {}
modelresults_equallyweighted = {}
for tag in modellist:
if not os.path.isdir(outputfolder+tag): continue
try:
infile = open(outputfolder+tag+'/ModelPerformance.txt','r')
except:
print 'couldn\'t open file %s, skipping this one.' % (outputfolder+tag+'/ModelPerformance.txt')
continue
# print 'found file "%s"' % (outputfolder+tag+'/ModelPerformance.txt')
if not 'runonfraction_100' in tag: continue
if not 'epochs_500' in tag: continue
if not 'layers_512_512__' in tag: continue
# if not 'regrate_080000' in tag: continue
lines = infile.readlines()
# vallossclosest = -1
for line in lines:
"""if 'Tag:' == line[0:4]:
tag = line.split(' ')[1]
el"""
if ' ' == line[0:4]:
line = line.replace(' ','')
vallosses = line.split('--')[1]
vallossmin = vallosses.split(',')[0].replace('(','')
vallossfin = vallosses.split(',')[1].replace(')','')
# print line
elif 'Validation loss in point of closest approach' in line:
line = line.split(':')[1]
line = line.replace(' ','')
vallossclosest = line.split(',')[0]
if vallossclosest == -1:
continue
if ('eqweight_False' in tag) or ('equallyweighted_False' in tag):
print tag
# print vallossmin, vallossfin
modelresults_lumiweighted[tag] = [float(vallossclosest), float(vallossmin), float(vallossfin)]
# modelresults_lumiweighted[tag] = [float(vallossmin), float(vallossfin)]
print modelresults_lumiweighted[tag]
print len(modelresults_lumiweighted)
elif ('eqweight_True') in tag or ('equallyweighted_True' in tag):
modelresults_equallyweighted[tag] = [float(vallossclosest), float(vallossmin), float(vallossfin)]
# modelresults_equallyweighted[tag] = [float(vallossmin), float(vallossfin)]
else:
raise ValueError('the part "eqweight_(True|False)" is not in the tag.')
infile.close()
for tag in modelresults_lumiweighted.keys():
print modelresults_lumiweighted[tag]
outfile = open(outputfolder + 'ModelRanking_lumiweighted.txt', 'w')
idx = 0
print len(modelresults_lumiweighted)
for tag in sorted(modelresults_lumiweighted, key=modelresults_lumiweighted.get, reverse=False):
text = 'Rank: ' + str(idx) + '\nTag: ' + tag + '\nLosses: ' + str(modelresults_lumiweighted[tag]) + '\n\n'
print text
outfile.write(text)
idx=idx+1
outfile.close()
outfile = open(outputfolder + 'ModelRanking_equallyweighted.txt', 'w')
idx = 0
for tag in sorted(modelresults_equallyweighted, key=modelresults_equallyweighted.get, reverse=False):
text = 'Rank: ' + str(idx) + '\nTag: ' + tag + 'Losses: ' + str(modelresults_equallyweighted[tag]) + '\n\n'
outfile.write(text)
idx=idx+1
outfile.close()
def RankNetworksReduced(outputfolder):
# Get all the model folders
modellist = os.listdir(outputfolder)
# Loop over them, open the correct file
modelresults_lumiweighted = {}
modelresults_equallyweighted = {}
for tag in modellist:
if not os.path.isdir(outputfolder+tag): continue
try:
infile = open(outputfolder+tag+'/ModelPerformance.txt','r')
except:
print 'couldn\'t open file %s, skipping this one.' % (outputfolder+tag+'/ModelPerformance.txt')
continue
# print 'found file "%s"' % (outputfolder+tag+'/ModelPerformance.txt')
if not 'runonfraction_100' in tag: continue
# if not 'regrate_080000' in tag: continue
lines = infile.readlines()
# vallossclosest = -1
for line in lines:
"""if 'Tag:' == line[0:4]:
tag = line.split(' ')[1]
el"""
if ' ' == line[0:4]:
line = line.replace(' ','')
vallosses = line.split('--')[1]
vallossmin = vallosses.split(',')[0].replace('(','')
vallossfin = vallosses.split(',')[1].replace(')','')
# print line
elif 'Validation loss in point of closest approach' in line:
line = line.split(':')[1]
line = line.replace(' ','')
vallossclosest = line.split(',')[0]
if vallossclosest == -1:
continue
if ('eqweight_False' in tag) or ('equallyweighted_False' in tag):
print tag
# print vallossmin, vallossfin
modelresults_lumiweighted[tag] = [float(vallossclosest), float(vallossmin), float(vallossfin)]
# modelresults_lumiweighted[tag] = [float(vallossmin), float(vallossfin)]
print modelresults_lumiweighted[tag]
print len(modelresults_lumiweighted)
elif ('eqweight_True') in tag or ('equallyweighted_True' in tag):
modelresults_equallyweighted[tag] = [float(vallossclosest), float(vallossmin), float(vallossfin)]
# modelresults_equallyweighted[tag] = [float(vallossmin), float(vallossfin)]
else:
raise ValueError('the part "eqweight_(True|False)" is not in the tag.')
infile.close()
for tag in modelresults_lumiweighted.keys():
print modelresults_lumiweighted[tag]
outfile = open(outputfolder + 'ModelRanking_lumiweighted.txt', 'w')
idx = 0
print len(modelresults_lumiweighted)
for tag in sorted(modelresults_lumiweighted, key=modelresults_lumiweighted.get, reverse=False):
text = 'Rank: ' + str(idx) + '\nTag: ' + tag + '\nLosses: ' + str(modelresults_lumiweighted[tag]) + '\n\n'
print text
outfile.write(text)
idx=idx+1
outfile.close()
outfile = open(outputfolder + 'ModelRanking_equallyweighted.txt', 'w')
idx = 0
for tag in sorted(modelresults_equallyweighted, key=modelresults_equallyweighted.get, reverse=False):
text = 'Rank: ' + str(idx) + '\nTag: ' + tag + 'Losses: ' + str(modelresults_equallyweighted[tag]) + '\n\n'
outfile.write(text)
idx=idx+1
outfile.close()