-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathaverage_vis.py
82 lines (71 loc) · 1.9 KB
/
average_vis.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
# Visualizing averaging of multiple Confusion Matrices
import h5py
import matplotlib.pyplot as plt
fname = 'conf_mat_smush_inception_4e-3x3.h5'
dname = 'dataset'
layer = 1
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
for fname in fnames:
print(prefix fname)
h5f = h5py.File(prefix fname, 'r')
if data is None:
data = h5f[dname][:]
else:
data = h5f[dname][:]
h5f.close()
prefix = 'conf_mat_smush_full_overfeat_'
fnames = ['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][:]
else:
data = h5f[dname][:]
h5f.close()
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][:]
else:
data = h5f[dname][:]
h5f.close()
prefix = 'conf_mat_smush_full_vgg19_'
fnames = ['conv4_4.h5', 'conv5_4.h5',
]
for fname in fnames:
print(prefix fname)
h5f = h5py.File(prefix fname, 'r')
if data is None:
data = h5f[dname][:]
else:
data = h5f[dname][:]
h5f.close()
print(data)
h5f = h5py.File('conf_mat_sum.h5', 'w')
h5f.create_dataset('dataset', data=data)
h5f.close()
h5f = h5py.File('conf_mat_avg.h5', 'w')
h5f.create_dataset('dataset', data=data / 21.0)
h5f.close()
# If multiple confusion matrices are saved, only display a specific layer
if len(data.shape) == 3:
plt.imshow(data[layer, ...])
else:
plt.imshow(data)
plt.show()