-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
184 lines (159 loc) · 6.66 KB
/
test.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
"""
Testing script for model stats collection about
runtime characteristics.
"""
# Testing module
import tensorflow as tf
import os
import profile_tf as profiler
import mobilenet_v1 as mobile
import squeezenet as squeeze
import shufflenet as shuffle
import report as report
import explorer as ex
def test_mobilenet():
mobilenet_creator = mobile.Model("mobilenet_v1")
mg = ex.model_generator(name = 'mobilenet_profile')
mg.set_creator(mobilenet_creator.model_creator)
mg.set_stats_updater(mobilenet_creator.stat_updater)
param_list = []
stat_list = []
for res in [1, 0.858, 0.715, 0.572]:
for width in [1, 0.75, 0.5]:
for depth in [1, 2]:
param = {'resolution_multiplier': res,
'width_multiplier': width,
'depth_multiplier': depth}
param_list.append(param)
stat_list.append(mg.set_and_stats(param))
param_fields = ['resolution_multiplier', 'width_multiplier',
'depth_multiplier']
stat_fields = ['param','flops','single_thread_mean','single_thread_var',
'multi_thread_mean','multi_thread_var', 'file_size']
report.write_data_to_csv(param_list, param_fields, 'model_parameters_mobilenet')
report.write_data_to_csv(stat_list, stat_fields, 'model_behaviour_mobilenet')
# Prepare for execution graph plotting
x_label = []
y_single_mean = []
y_multi_mean = []
y_single_error = []
y_multi_error = []
def create_label(d):
ret = ""
for key, value in d.items():
if ret=="":
ret = str(value)
else:
ret = ret+"_"+str(value)
return ret
for i in range(len(stat_list)):
x_label.append(create_label(param_list[i]))
y_single_mean.append(stat_list[i]['single_thread_mean'])
y_multi_mean.append(stat_list[i]['multi_thread_mean'])
y_single_error.append(stat_list[i]['single_thread_var'])
y_multi_error.append(stat_list[i]['multi_thread_var'])
name = ['single', 'multi']
y_data_mean = [y_single_mean, y_multi_mean]
y_data_var = [y_single_error, y_multi_error]
report.graph_data_bar(x_label, y_data_mean, y_data_var, name, multi=True)
def test_squeezenet():
squeezenet_creator = squeeze.Model("squeezenet")
mg = ex.model_generator(name = 'squeezenet_profile')
mg.set_creator(squeezenet_creator.model_creator)
mg.set_stats_updater(squeezenet_creator.stat_updater)
param_list = []
stat_list = []
for base_expand_kernels in [128]:
for expansion_increment in [128]:
for pct in [0.5]:
for freq in [2]:
for SR in [0.125]:
param = {'base_expand': base_expand_kernels,
'expansion_increment': expansion_increment,
'expansion_filter_ratio': pct,
'filter_expansion_freq': freq,
'squeeze_ratio': SR}
param_list.append(param)
stat_list.append(mg.set_and_stats(param))
param_fields = ['base_expand', 'expansion_increment',
'expansion_filter_ratio', 'filter_expansion_freq',
'squeeze_ratio']
stat_fields = ['param','flops','single_thread_mean','single_thread_var',
'multi_thread_mean','multi_thread_var', 'file_size']
report.write_data_to_csv(param_list, param_fields, 'model_parameters_squeezenet')
report.write_data_to_csv(stat_list, stat_fields, 'model_behaviour_squeezenet')
# Prepare for execution graph plotting
x_label = []
y_single_mean = []
y_multi_mean = []
y_single_error = []
y_multi_error = []
def create_label(d):
ret = ""
for key, value in d.items():
if ret=="":
ret = str(value)
else:
ret = ret+"_"+str(value)
return ret
for i in range(len(stat_list)):
x_label.append(create_label(param_list[i]))
y_single_mean.append(stat_list[i]['single_thread_mean'])
y_multi_mean.append(stat_list[i]['multi_thread_mean'])
y_single_error.append(stat_list[i]['single_thread_var'])
y_multi_error.append(stat_list[i]['multi_thread_var'])
name = ['single', 'multi']
y_data_mean = [y_single_mean, y_multi_mean]
y_data_var = [y_single_error, y_multi_error]
report.graph_data_bar(x_label, y_data_mean, y_data_var, name, multi=True)
def test_shufflenet():
shufflenet_creator = shuffle.Model("shufflenet")
mg = ex.model_generator(name = 'shufflenet_profile')
mg.set_creator(shufflenet_creator.model_creator)
mg.set_stats_updater(shufflenet_creator.stat_updater)
# Mapping out_channel with nr_group
out_ch_map = {1: 144, 2: 200, 3: 240, 4: 272, 8:384}
param_list = []
stat_list = []
for filter_group in [1,2,3,4,8]:
for complexity_scale_factor in [0.25, 0.5, 1.0]:
param = {'filter_group': filter_group,
'complexity_scale_factor': complexity_scale_factor,
'out_channel': out_ch_map[filter_group]}
param_list.append(param)
stat_list.append(mg.set_and_stats(param))
param_fields = ['filter_group', 'complexity_scale_factor', 'out_channel']
stat_fields = ['param','flops','single_thread_mean','single_thread_var',
'multi_thread_mean','multi_thread_var', 'file_size']
report.write_data_to_csv(param_list, param_fields, 'model_parameters_shufflenet')
report.write_data_to_csv(stat_list, stat_fields, 'model_behaviour_shufflenet')
# Prepare for execution graph plotting
x_label = []
y_single_mean = []
y_multi_mean = []
y_single_error = []
y_multi_error = []
def create_label(d):
ret = ""
for key, value in d.items():
if ret=="":
ret = str(value)
else:
ret = ret+"_"+str(value)
return ret
for i in range(len(stat_list)):
x_label.append(create_label(param_list[i]))
y_single_mean.append(stat_list[i]['single_thread_mean'])
y_multi_mean.append(stat_list[i]['multi_thread_mean'])
y_single_error.append(stat_list[i]['single_thread_var'])
y_multi_error.append(stat_list[i]['multi_thread_var'])
name = ['single', 'multi']
y_data_mean = [y_single_mean, y_multi_mean]
y_data_var = [y_single_error, y_multi_error]
report.graph_data_bar(x_label, y_data_mean, y_data_var, name, multi=True)
def main():
test_mobilenet()
test_squeezenet()
test_shufflenet()
if __name__ == "__main__":
main()