forked from pfnet-research/menoh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_test_data.py
265 lines (226 loc) · 10.1 KB
/
gen_test_data.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import sys
import subprocess
def call(cmd):
""" call command line.
"""
print(cmd)
p = subprocess.Popen(cmd, shell=True)
ret = p.wait()
print('')
pyexe = sys.executable
# Generate input data
call(
pyexe +
' test/script/make_random_data.py 3 4096 --output data/random_input_3_4096.txt'
) # 4096 = 4*32*32
call(
pyexe +
' test/script/make_random_data.py 3 4 32 32 --output data/random_input_3_4_32_32.txt'
)
call(
pyexe +
' test/script/make_random_data.py 3 4096 --output data/random_positive_input_3_4096.txt --positive'
)
call(
pyexe +
' test/script/make_random_data.py 3 4 32 32 --output data/random_positive_input_3_4_32_32.txt --positive'
)
# Generate weight and bias data
call(
pyexe +
' test/script/make_random_data.py 5 4 1 1 --output data/random_weight_5_4_1_1.txt'
)
call(
pyexe +
' test/script/make_random_data.py 5 4 2 2 --output data/random_weight_5_4_2_2.txt'
)
call(
pyexe +
' test/script/make_random_data.py 5 4 3 3 --output data/random_weight_5_4_3_3.txt'
)
call(
pyexe +
' test/script/make_random_data.py 4 5 1 1 --output data/random_weight_4_5_1_1.txt'
)
call(
pyexe +
' test/script/make_random_data.py 4 5 2 2 --output data/random_weight_4_5_2_2.txt'
)
call(
pyexe +
' test/script/make_random_data.py 4 5 3 3 --output data/random_weight_4_5_3_3.txt'
)
call(pyexe +
' test/script/make_random_data.py 5 --output data/random_bias_5.txt')
call(pyexe +
' test/script/make_random_data.py 5 --output data/random_bias_4.txt')
call(
pyexe +
' test/script/make_random_data.py 256 4096 --output data/random_weight_256_4096.txt'
)
call(pyexe +
' test/script/make_random_data.py 256 --output data/random_bias_256.txt')
call(pyexe +
' test/script/make_random_data.py 4 --output data/random_gamma_4.txt')
call(pyexe +
' test/script/make_random_data.py 4 --output data/random_beta_4.txt')
call(pyexe +
' test/script/make_random_data.py 4 --output data/random_mean_4.txt')
call(pyexe +
' test/script/make_random_data.py 4 --output data/random_var_4.txt')
# Operators
## Relu
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4096.txt --output data/relu_1d.txt ' \
'--op relu')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/relu_2d.txt ' \
'--op relu')
## LeakyRelu
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4096.txt --output data/leaky_relu_1d.txt ' \
'--op leaky_relu --slope 0.001')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/leaky_relu_2d.txt ' \
'--op leaky_relu --slope 0.001')
## Elu
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4096.txt --output data/elu_1d.txt ' \
'--op elu --alpha 1.1')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/elu_2d.txt ' \
'--op elu --alpha 1.1')
## Abs
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4096.txt --output data/abs_1d.txt ' \
'--op absolute')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/abs_2d.txt ' \
'--op absolute')
## Tanh
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4096.txt --output data/tanh_1d.txt ' \
'--op tanh')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/tanh_2d.txt ' \
'--op tanh')
## Sqrt
call(pyexe + ' test/script/gen_op_result.py --input data/random_positive_input_3_4096.txt --output data/sqrt_1d.txt ' \
'--op sqrt')
call(pyexe + ' test/script/gen_op_result.py --input data/random_positive_input_3_4_32_32.txt --output data/sqrt_2d.txt ' \
'--op sqrt')
## Softmax
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4096.txt --output data/softmax_1d.txt ' \
'--op softmax')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/softmax_2d.txt ' \
'--op softmax')
## FC and Gemm
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4096.txt ' \
'--output data/linear_1d_w256_4096_b_256.txt ' \
'--op linear --W data/random_weight_256_4096.txt --b data/random_bias_256.txt')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt ' \
'--output data/linear_2d_w256_4096_b_256.txt ' \
'--op linear --W data/random_weight_256_4096.txt --b data/random_bias_256.txt')
## MaxPool2d
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/max_pooling_2d_k2_s2_p0.txt ' \
'--op max_pooling_2d --ksize 2 --stride 2 --pad 0 --cover_all 0')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/max_pooling_2d_k3_s2_p0.txt ' \
'--op max_pooling_2d --ksize 3 --stride 2 --pad 0 --cover_all 0')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/max_pooling_2d_k3_s2_p1.txt ' \
'--op max_pooling_2d --ksize 3 --stride 2 --pad 1 --cover_all 0')
## AveragePool2d
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/average_pooling_2d_k2_s2_p0.txt ' \
'--op average_pooling_2d --ksize 2 --stride 2 --pad 0')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/average_pooling_2d_k3_s2_p0.txt ' \
'--op average_pooling_2d --ksize 3 --stride 2 --pad 0')
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/average_pooling_2d_k3_s2_p1.txt ' \
'--op average_pooling_2d --ksize 3 --stride 2 --pad 1')
## GlobalMaxPool
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/global_max_pooling_2d.txt ' \
'--op max_pooling_2d --ksize 32 --stride 1 --pad 0 --cover_all 0')
## GlobalAveragePool
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/global_average_pooling_2d.txt ' \
'--op average_pooling_2d --ksize 32 --stride 1 --pad 0')
## Conv2d
def conv_data(v1, v2, v3):
ksize = str(v1)
stride = str(v2)
pad = str(v3)
# Without bias
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt ' \
'--output data/convolution_2d_w5_4_'+ksize+'_'+ksize+'_k'+ksize+'_s'+stride+'_p'+pad+'.txt ' \
'--op convolution_2d --ksize '+ksize+' --stride '+stride+' --pad '+pad+' ' \
'--W data/random_weight_5_4_'+ksize+'_'+ksize+'.txt')
# With bias
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt ' \
'--output data/convolution_2d_w5_4_'+ksize+'_'+ksize+'_k'+ksize+'_s'+stride+'_p'+pad+'_with_bias.txt ' \
'--op convolution_2d --ksize '+ksize+' --stride '+stride+' --pad '+pad+' ' \
'--W data/random_weight_5_4_'+ksize+'_'+ksize+'.txt ' \
'--b data/random_bias_5.txt')
conv_data(1, 1, 0)
conv_data(2, 1, 0)
conv_data(2, 1, 1)
conv_data(2, 2, 0)
conv_data(2, 2, 1)
conv_data(3, 1, 1)
conv_data(3, 2, 0)
conv_data(3, 2, 1)
## BatchNorm
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/batch_normalization.txt ' \
'--op fixed_batch_normalization --gamma data/random_gamma_4.txt --beta data/random_beta_4.txt ' \
'--mean data/random_mean_4.txt --var data/random_var_4.txt --eps 1e-5')
## Add
call(
pyexe +
' test/script/gen_add_result.py --input_a data/random_input_3_4096.txt --input_b data/random_input_3_4096.txt --output data/add_1d.txt'
)
call(
pyexe +
' test/script/gen_add_result.py --input_a data/random_input_3_4_32_32.txt --input_b data/random_input_3_4_32_32.txt --output data/add_2d.txt'
)
## Concat
call(
pyexe +
' test/script/gen_concat_result.py --inputs data/random_input_3_4096.txt data/random_input_3_4096.txt --axis 0 --output data/concat_1d_6_4096.txt'
)
call(
pyexe +
' test/script/gen_concat_result.py --inputs data/random_input_3_4096.txt data/random_input_3_4096.txt --axis 1 --output data/concat_1d_3_8192.txt'
)
call(
pyexe +
' test/script/gen_concat_result.py --inputs data/random_input_3_4096.txt data/random_input_3_4096.txt data/random_input_3_4096.txt --axis 0 --output data/concat_1d_9_4096.txt'
)
call(
pyexe +
' test/script/gen_concat_result.py --inputs data/random_input_3_4096.txt data/random_input_3_4096.txt data/random_input_3_4096.txt --axis 1 --output data/concat_1d_3_12288.txt'
)
## Deconv
def deconv_data(v1, v2, v3):
ksize = str(v1)
stride = str(v2)
pad = str(v3)
# Without bias
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt ' \
'--output data/deconvolution_2d_w4_5_'+ksize+'_'+ksize+'_k'+ksize+'_s'+stride+'_p'+pad+'.txt ' \
'--op deconvolution_2d --W data/random_weight_4_5_'+ksize+'_'+ksize+'.txt ' \
'--ksize '+ksize+' --stride '+stride+' --pad '+pad+' --cover_all 0')
# With bias
call(pyexe + ' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt ' \
'--output data/deconvolution_2d_w4_5_'+ksize+'_'+ksize+'_k'+ksize+'_s'+stride+'_p'+pad+'_with_bias.txt ' \
'--op deconvolution_2d --W data/random_weight_4_5_'+ksize+'_'+ksize+'.txt ' \
'--ksize '+ksize+' --stride '+stride+' --pad '+pad+' --cover_all 0 ' \
'--b data/random_bias_4.txt')
deconv_data(1, 1, 0)
deconv_data(2, 1, 0)
deconv_data(2, 1, 1)
deconv_data(2, 2, 0)
deconv_data(2, 2, 1)
deconv_data(3, 1, 1)
deconv_data(3, 2, 0)
deconv_data(3, 2, 1)
## LRN
def lrn_data(alpha, beta, bias, size):
call(
pyexe +
' test/script/gen_op_result.py --input data/random_input_3_4_32_32.txt --output data/lrn_alpha{alpha}_beta{beta}_bias{bias}_size{size}.txt --op local_response_normalization --alpha {alpha} --beta {beta} --n {size} --k {bias}'.
format(
alpha=str(alpha), beta=str(beta), bias=str(bias), size=str(size)))
lrn_data(0.0001, 0.75, 1, 1)
lrn_data(0.0001, 0.75, 1, 2)
lrn_data(0.0001, 0.75, 1, 3)
lrn_data(0.0001, 0.75, 1, 4)
lrn_data(0.0001, 0.75, 2, 1)
lrn_data(0.0001, 0.75, 2, 2)
lrn_data(0.0001, 0.75, 2, 3)
lrn_data(0.0001, 0.75, 2, 4)