-
Notifications
You must be signed in to change notification settings - Fork 25
/
build_average.py
168 lines (145 loc) · 3.9 KB
/
build_average.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
# make conf_mat files with averages
import numpy as np
import h5py
import sys
from copy import deepcopy
dname = 'dataset'
prefix = 'conf_mat_smush_full_googlenet_inception_'
fnames = ['3a-output.h5', '3b-output.h5',
'4a-output.h5', '4b-output.h5',
'4c-output.h5', '4d-output.h5',
'4e-output.h5',
'5a-output.h5', '5b-output.h5'
]
data = None
data_all = None
data_net = None
for fname in fnames:
print(prefix + fname)
h5f = h5py.File(prefix + fname, 'r')
if data is None:
data = h5f[dname][:]
data_all = h5f[dname][:]
else:
data += h5f[dname][:]
data_all += h5f[dname][:]
h5f.close()
prefix = 'conf_mat_smush_googlenet_'
fnames = ['pool1-norm1.h5', 'conv2-norm2.h5']
for fname in fnames:
print(prefix + fname)
h5f = h5py.File(prefix + fname, 'r')
data_all[0:4789,4789:9575] += h5f[dname][:]
data[0:4789,4789:9575] += h5f[dname][:]
h5f.close()
data_net = data/11.0
h5f = h5py.File('googlenet_avg.h5', 'w')
h5f.create_dataset('dataset', data=data/11.0)
h5f.close()
data = None
prefix = 'conf_mat_smush_full_overfeat_'
fnames = [
'0.h5', '2.h5', '3.h5', #TODO: 1 layer missing
'4.h5', '5.h5',
'6.h5', '7.h5',
'8.h5', '9.h5',
'10.h5', '11.h5',
'10.h5', '11.h5',
'12.h5', '13.h5',
'14.h5', '15.h5',
'16.h5', '17.h5',
]
for fname in fnames:
print(prefix + fname)
h5f = h5py.File(prefix + fname, 'r')
if data is None:
data = h5f[dname][:]
data_all += h5f[dname][:]
else:
data += h5f[dname][:]
data_all += h5f[dname][:]
h5f.close()
data_net += data/21.0
h5f = h5py.File('overfeat_avg.h5', 'w')
h5f.create_dataset('dataset', data=data/21.0)
h5f.close()
data = None
prefix = 'conf_mat_smush_full_caffenet_'
fnames = ['conv3.h5', 'conv4.h5',
]
for fname in fnames:
print(prefix + fname)
h5f = h5py.File(prefix + fname, 'r')
if data is None:
data = h5f[dname][:]
data_all += h5f[dname][:]
else:
data += h5f[dname][:]
data_all += h5f[dname][:]
h5f.close()
prefix = 'conf_mat_smush_caffenet_'
fnames = ['conv1.h5', 'conv1.h5',
]
for fname in fnames:
print(prefix + fname)
h5f = h5py.File(prefix + fname, 'r')
data_all[0:4789,4789:9575] += h5f[dname][:]
data[0:4789,4789:9575] += h5f[dname][:]
h5f.close()
data_net += data/4.0
h5f = h5py.File('alexnet_avg.h5', 'w')
h5f.create_dataset('dataset', data=data/4.0)
h5f.close()
data = None
prefix = 'conf_mat_smush_full_vgg19_'
fnames = ['conv4_4.h5',
'conv5_3.h5', 'conv5_4.h5',
]
for fname in fnames:
print(prefix + fname)
h5f = h5py.File(prefix + fname, 'r')
if data is None:
data = h5f[dname][:]
data_all += h5f[dname][:]
else:
data += h5f[dname][:]
data_all += h5f[dname][:]
h5f.close()
data_net += data/2.0
h5f = h5py.File('vgg19_avg.h5', 'w')
h5f.create_dataset('dataset', data=data/2.0)
h5f.close()
# Without Cifar10 averages
h5f = h5py.File('all_net_avg_no_cifar.h5', 'w')
h5f.create_dataset('dataset', data=data_net/4.0)
h5f.close()
h5f = h5py.File('all_layer_avg_no_cifar.h5', 'w')
h5f.create_dataset('dataset', data=data_all/33.0)
h5f.close()
data = None
prefix = 'conf_mat_smush_full_cifar10full_'
fnames = ['conv1.h5', 'conv2.h5', 'conv3.h5',
]
for fname in fnames:
print(prefix + fname)
h5f = h5py.File(prefix + fname, 'r')
if data is None:
data = h5f[dname][:]
data_all += h5f[dname][:]
else:
data += h5f[dname][:]
data_all += h5f[dname][:]
h5f.close()
data_net += data/3.0
h5f = h5py.File('cifar10_avg.h5', 'w')
h5f.create_dataset('dataset', data=data/3.0)
h5f.close()
print(data)
h5f = h5py.File('all_net_avg.h5', 'w')
h5f.create_dataset('dataset', data=data_net/5.0)
h5f.close()
h5f = h5py.File('all_layer_avg.h5', 'w')
h5f.create_dataset('dataset', data=data_all/36.0)
h5f.close()
# TODO: do one looking at averaging only the top 2 layers of each net
# (and skipping Cifar10)