-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoutputprocessor.py
220 lines (168 loc) · 6.1 KB
/
outputprocessor.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import classification_report, confusion_matrix
import pandas as pd
import sys
from timeit import default_timer as timer
from keras import backend as K
from keras.callbacks import CSVLogger
import json
import keras.applications as keras_applications
import os
theader='''
\\begin{table}[h!]
\\begin{center}
\\begin{tabular}{ | p {1.5cm} |c |c| }
\\hline
'''
tfooter='''
\\end{tabular}
\\caption{ Analysis}
\\label{tbl:pic}
\\end{center}
\\end{table}
'''
names=['ResNet50', 'MobileNet', 'MobileNetV2', 'NASNetMobile', 'NASNetLarge', 'VGG16', 'VGG19', 'Xception', 'InceptionResNetV2', 'DenseNet121', 'DenseNet201']
m=[keras_applications.ResNet50, keras_applications.MobileNet, keras_applications.MobileNetV2, keras_applications.NASNetMobile, keras_applications.NASNetLarge, keras_applications.VGG16, keras_applications.VGG19, keras_applications.Xception, keras_applications.InceptionResNetV2,
keras_applications.DenseNet121,keras_applications.DenseNet201]
def summarypage():
data=""
directory=["binary","binarydense",
"binaryhnonsym", "binaryhv","binaryvnonsym","multi", "multirefrottarAll" ]
history=[]
global names
i =0
data=""
hf="\multicolumn{2}{|c|}{}"
for m in names:
data=data + m
header=""
for e in directory:
header=header + " \\multicolumn{2}{|c|}{"+e+"} & "
print(m, e)
modelname= str(i)+"_"+ names[i]
f="outputs/" + e +"/output/"+ modelname + 'log.csv'
if os.path.exists(f)==False:
data=data + " , , "
continue
b_history=pd.read_csv(f, sep=";")
b_val_acc=round(max(b_history['val_acc']),2)
b_tr_acc=round(max(b_history['acc']),2)
data=data + " , " + str(b_tr_acc) + " , " +str(b_val_acc)
data=data+ "\n"
i =i +1
fi=open("outputs/summary.csv","w")
fi.write(header + "\n" + data)
def getParameterdetails(logdir,outdir, cls):
global names
global m
global tfooter
input_shape=(200,200,1)
if cls=="binary":
classes=2
else:
classes=4
theader='''
\\begin{table}[h!]
\\begin{center}
\\begin{tabular}{ | l |c |c| c |c |c| c |c |c|}
\\hline
'''
header= '''
\\multicolumn{3}{|c}{Model} & \\multicolumn{3}{|c|}{binary classification} & \\multicolumn{3}{c|}{multi classification} \\\ \\hline \n
Name & parameters & layers & train accuracy & valid accuracy & training time & train accuracy & valid accuracy & training time\\\ \\hline \n
'''
data=theader + header
for i in range( 0, len(names)):
modelname= str(i)+"_"+ names[i]
print(modelname)
b_history=pd.read_csv("output/"+ modelname+ 'log.csv', sep=";")
b_val_acc=round(max(b_history['val_acc']),2)
b_tr_acc=round(max(b_history['acc']),2)
m_history=pd.read_csv("multi_output/"+ modelname+ 'log.csv', sep=";")
m_val_acc=round(max(m_history['val_acc']),2)
m_tr_acc=round(max(m_history['acc']),2)
#data=data + str(tr_acc) + " & " +str(val_acc) + " \\ \n"
#model=m[i](weights=None, input_shape=input_shape,classes=classes)
#p=model.count_params()
# p=str(round(p / 1000000,2)) + 'M'
#l=len(model.layers)
b_trtime=""
m_trtime=""
data=data + names[i] + " & " + str(p) + " & " + str(l) + " & " + str(b_tr_acc) + " & " +str(b_val_acc) + " & " +str(b_trtime)+ " & " + str(m_tr_acc) + " & " +str(m_val_acc) + " & " +str(m_trtime) + "\\\ \\hline \n"
#data=data+ tfooter
print(data )
f=open(cls+"_summary.txt","w")
f.write(data)
f.close()
return ""
def draw(logdir,outdir, cls):
global theader
global tfooter
global names
latexcode=open(outdir+ cls+ "_results.tex","w")
tbody=theader
fig = plt.figure()
fig.subplots_adjust(hspace=0.4, wspace=0.4)
fig.set_size_inches(8,11)
#fig.ylabel('accuracy')
#fig.xlabel('epoch')
for i in range( 0, len(names)):
modelname= str(i)+"_"+ names[i]
print(modelname)
history=pd.read_csv(logdir+ modelname+ 'log.csv', sep=";")
#fig = plt.figure()
plt.subplot( 4,3, i+1)
acc,=plt.plot(history['acc'])
val_acc,=plt.plot(history['val_acc'])
loss,=plt.plot(history['loss'])
val_loss,=plt.plot(history['val_loss'])
plt.title(names[i])
#plt.title(names[i]+' model accuracy')
#plt.ylabel('accuracy')
#plt.xlabel('epoch')
#plt.legend(['train', 'test'], loc='upper left')
f1= modelname+"_accuracy.png"
#plt.savefig(outdir+f1)
f2=modelname+"_los.png"
'''
# summarize history for loss
fig = plt.figure()
plt.plot(history['loss'])
plt.plot(history['val_loss'])
plt.title(names[i]+' model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.savefig(outdir+f2)
'''
rec= names[i] +" & \\includegraphics[width=0.4\\textwidth]{figures/"+cls+"/"+f1+"} & \\includegraphics[width=0.4\\textwidth]{figures/"+cls+"/"+f2+"} \\\ \hline "
tbody=tbody+ rec +"\n"
fig.legend([acc, val_acc,loss,val_loss],['training accuracy', 'validation accuracy', 'training loss','validation loss'], loc='lower right')
plt.savefig(outdir+cls+"_total.png")
latexcode.write(tbody)
latexcode.write(tfooter)
#logdir="outputs/binary/output/"
#outdir="outputs/binary/drawing/"
#draw(logdir,outdir, "binary")
#logdir="outputs/binarydense/output/"
#outdir="outputs/binarydense/drawing/"
#draw(logdir,outdir, "binarydense")
#logdir="outputs/multi/output/"
#outdir="outputs/multi/drawing/"
#draw(logdir,outdir, "multi")
expprefix=sys.argv[1]
logdir="outputs/"+expprefix+"/output/"
outdir="outputs/"+expprefix+"/drawing/"
draw(logdir,outdir, expprefix)
'''
logdir="output/"
outdir="drawing/"
getParameterdetails(logdir,outdir, "binary")
'''
#logdir="multi_output/"
#outdir="multi_drawing/"
#getParameterdetails(logdir,outdir, "multi")
#getParameterdetails(logdir,outdir, "multi")