forked from DingXiaoH/ACNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
display_hdf5.py
49 lines (44 loc) · 1.64 KB
/
display_hdf5.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
from utils.misc import read_hdf5
import sys
import numpy as np
di = read_hdf5(sys.argv[1])
num_kernel_params = 0
conv_kernel_cnt = 0
matrix_param_cnt = 0
vec_param_cnt = 0
bias_cnt = 0
beta_cnt = 0
gamma_cnt = 0
mu_cnt = 0
var_cnt = 0
for name, array in di.items():
if array.ndim in [2, 4]:
num_kernel_params += array.size
print(name, array.shape, np.mean(array), np.std(array), ' positive {}, negative {}, zeros {}'.format(np.sum(array > 0), np.sum(array < 0), np.sum(array == 0)))
if 'res' in name:
print(array[:4, :4])
elif 'diag' in name:
print(array)
if array.ndim == 2:
matrix_param_cnt += array.size
elif array.ndim == 1:
vec_param_cnt += array.size
elif array.ndim == 4:
conv_kernel_cnt += array.size
if 'running_mean' in name or 'moving_mean' in name:
mu_cnt += array.size
elif 'running_var' in name or 'moving_var' in name:
var_cnt += array.size
elif ('weight' in name and 'bn' in name.lower()) or 'gamma' in name:
gamma_cnt += array.size
elif ('bias' in name and 'bn' in name.lower()) or 'beta' in name:
beta_cnt += array.size
elif 'bias' in name:
bias_cnt += array.size
# if 'resmat' in name:
# print(np.transpose(array).dot(array))
# exit()
print('number of kernel params: ', num_kernel_params)
print('vec {}, matrix {}, conv {}, total {}'.format(vec_param_cnt, matrix_param_cnt, conv_kernel_cnt,
vec_param_cnt + matrix_param_cnt + conv_kernel_cnt))
print('mu {}, var {}, gamma {}, beta {}, bias {}'.format(mu_cnt, var_cnt, gamma_cnt, beta_cnt, bias_cnt))