-
Notifications
You must be signed in to change notification settings - Fork 25
/
panda_plots.py
206 lines (180 loc) · 7.1 KB
/
panda_plots.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
import numpy as np
import ipdb
import sys
import cPickle as pickle
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(font_scale=1.5)
# dicts for converting layer name to num
vgg19_num = {'conv4_4': 1,
'conv5_3': 2, 'conv5_4': 3}
googlenet_num = {'3a': 1, '3b': 2, '4a': 3, '4b': 4, '4c': 5, '4d': 6, '4e': 7, '5a': 8, '5b': 9}
fname = 'filter_res_all.p'
data = pickle.load(open(fname, 'rb'))
results = pd.DataFrame()
for name in data.keys():
if 'googlenet' in name:
net_type = 'GoogLeNet'
if 'full' in name:
layer_name = name[40:42]
layer_num = layer_name#googlenet_num[layer_name]
else:
layer_name = name[25:30]
layer_num = layer_name[-1]
elif 'overfeat' in name:
net_type = 'OverFeat'
layer_name = name[29:-3]
layer_num = int(layer_name)
elif 'vgg19' in name:
net_type = 'VGG19'
layer_name = name[26:-3]
layer_num = vgg19_num[layer_name]
elif ('caffenet' in name) or ('alexnet' in name):
net_type = 'AlexNet'
if 'full' in name:
layer_name = name[29:-3]
else:
layer_name = name[24:-3]
layer_num = int(layer_name[4:])
elif 'cifar10full' in name:
net_type = 'Cifar10'
layer_name = 'cifar_' + name[32:-3]
layer_num = int(layer_name[10:])
elif 'average' in name:
net_type = 'Average'
layer_name = 'average'
layer_num = 1
else:
net_type = 'NOTFOUND'
layer_name = 'notfound'
results = results.append({'Name': name, # TODO: get rid of conf_mat crap
'Network': net_type,
'Layer': layer_name,
'Layer #': layer_num,
'Precision': data[name][0],
'Recall': data[name][1],
'F1 Score': data[name][2],
'Boosted': False,
'AVG':False,
}, ignore_index=True)
results = results.append({'Name': name, # TODO: get rid of conf_mat crap
'Network': net_type,
'Layer': layer_name,
'Layer #': layer_num,
'Precision': data[name][3],
'Recall': data[name][4],
'F1 Score': data[name][5],
'Boosted': True,
'AVG':False,
}, ignore_index=True)
# Get the average data
fname = 'filter_res_avg.p'
data = pickle.load(open(fname, 'rb'))
for name in data.keys():
layer_name = None
layer_num = None
if 'googlenet' in name:
net_type = 'GoogLeNet'
elif 'overfeat' in name:
net_type = 'OverFeat'
elif 'vgg19' in name:
net_type = 'VGG19'
elif ('caffenet' in name) or ('alexnet' in name):
net_type = 'AlexNet'
elif 'cifar10' in name:
net_type = 'Cifar10'
elif 'all_net' in name:
net_type = 'NetworkAverage'
continue
elif 'all_layer' in name:
net_type = 'LayerAverage'
net_type = 'Combined'
else:
net_type = 'NOTFOUND'
layer_name = 'notfound'
continue
results = results.append({'Name': name, # TODO: get rid of conf_mat crap
'Network': net_type,
'Layer': layer_name,
'Layer #': layer_num,
'Precision': data[name][0],
'Recall': data[name][1],
'F1 Score': data[name][2],
'Boosted': False,
'AVG':True,
}, ignore_index=True)
results = results.append({'Name': name, # TODO: get rid of conf_mat crap
'Network': net_type,
'Layer': layer_name,
'Layer #': layer_num,
'Precision': data[name][3],
'Recall': data[name][4],
'F1 Score': data[name][5],
'Boosted': True,
'AVG':True,
}, ignore_index=True)
if True:#fname == 'filter_res_avg.p':
kind = 'bar'
title = 'Layer Averages'
order = ['Cifar10', 'AlexNet', 'OverFeat', 'GoogLeNet', 'VGG19', 'Combined']
if True: # Show max and boosted only
results = results[(results['Boosted'] == True)]
for metric in ['F1 Score', 'Precision', 'Recall']:
# Only look at non-averages for max
max_val = results[(results['AVG'] == False)]
max_val = max_val.groupby(['Network'], sort=False)['F1 Score'].max()
max_add = pd.DataFrame()
for name, value in max_val.iteritems():
max_add = max_add.append({'Network':name,
metric:value,
'AVG':False,
}, ignore_index=True)
avg_results = results[(results['AVG'] == True)]
avg_results = pd.concat([max_add, avg_results])
bar = sns.factorplot('Network', metric, 'AVG', data=avg_results, kind=kind, size=6,
legend=False, order=order)
bar.axes[0,0].set_title(title)
handles, labels = bar.axes[0,0].get_legend_handles_labels()
bar.axes[0,0].legend(handles, ['Max', 'Average'], loc='center left', bbox_to_anchor=(1, 0.5))
else: # show boosted and non-boosted and not max
results = results[(results['AVG'] == True)]
bar = sns.factorplot('Network', 'F1 Score', 'Boosted', data=results, kind=kind, size=6,
legend=True, order=order)
bar.axes[0,0].set_title(title)
bar = sns.factorplot('Network', 'Precision', 'Boosted', data=results,
kind=kind, size=6, legend=True, order=order)
bar.axes[0,0].set_title(title)
bar = sns.factorplot('Network', 'Recall', 'Boosted', data=results, kind=kind, size=6,
legend=True, order=order)
bar.axes[0,0].set_title(title)
else:
results = results[(results['AVG'] == False)]
kind = 'point'
network_names = ['GoogLeNet', 'OverFeat', 'Cifar10', 'AlexNet', 'VGG19']
# Silly things because Python is weird
tmp = range(22)
tmp.remove(1)
order = {'GoogLeNet':['1', '2', '3a','3b','4a','4b','4c','4d','4e','5a','5b'],
'OverFeat':tmp,
'Cifar10':[1,2,3],
'AlexNet':[1,2,3,4],
'VGG19':[1,2,3]
}
for name in network_names:
net = results[(results['Network'] == name)]
bar = sns.factorplot('Layer #', 'F1 Score', 'Boosted', data=net,
kind=kind, size=8, legend=False, order=order[name])
bar.axes[0,0].set_title(name)
if name != 'GoogLeNet':
labels = [int(item.get_text()) for item in bar.axes[0,0].get_xticklabels()]
bar.axes[0,0].set_xticklabels(labels)
handles, labels = bar.axes[0,0].get_legend_handles_labels()
bar.axes[0,0].legend(handles, ['Regular', 'Boosted'], loc='center left', bbox_to_anchor=(1, 0.5))
"""
kind = 'bar'
bar = sns.factorplot('Layer', 'F1 Score', 'Boosted', data=results, kind=kind, size=6,
legend=True)
bar.axes[0,0].set_title('All Layers')
"""
plt.show()