@@ -184,12 +184,12 @@ def test_transpose_max(self):
184
184
const_1 = helper .make_tensor ("const_1" , TensorProto .FLOAT , (1 ,), const_1_val )
185
185
const_1_node = helper .make_node ("Constant" , [], ["const_1" ], value = const_1 , name = "const_1" )
186
186
187
- const_2_val = np .random .randn (2 , 4 , 5 , 3 ).astype (np .float32 ). reshape ( 120 ). tolist ()
188
- const_2 = helper .make_tensor ("const_2" , TensorProto .FLOAT , (2 , 4 , 5 , 3 ), const_2_val )
187
+ const_2_val = np .random .randn (2 , 4 , 5 , 3 ).astype (np .float32 )
188
+ const_2 = helper .make_tensor ("const_2" , TensorProto .FLOAT , (2 , 4 , 5 , 3 ), const_2_val . flatten () )
189
189
const_2_node = helper .make_node ("Constant" , [], ["const_2" ], value = const_2 , name = "const_2" )
190
190
191
- const_3_val = np .random .randn (2 , 4 , 5 , 3 ).astype (np .float32 ). reshape ( 120 ). tolist ()
192
- const_3 = helper .make_tensor ("const_3" , TensorProto .FLOAT , (2 , 4 , 5 , 3 ), const_3_val )
191
+ const_3_val = np .random .randn (2 , 4 , 5 , 3 ).astype (np .float32 )
192
+ const_3 = helper .make_tensor ("const_3" , TensorProto .FLOAT , (2 , 4 , 5 , 3 ), const_3_val . flatten () )
193
193
const_3_node = helper .make_node ("Constant" , [], ["const_3" ], value = const_3 , name = "const_3" )
194
194
195
195
node1 = helper .make_node ("Transpose" , ["X" ], ["Y" ], perm = [0 , 2 , 3 , 1 ], name = "trans_1" )
@@ -212,8 +212,8 @@ def test_transpose_max_input_non_const(self):
212
212
const_1 = helper .make_tensor ("const_1" , TensorProto .FLOAT , (1 ,), const_1_val )
213
213
const_1_node = helper .make_node ("Constant" , [], ["const_1" ], value = const_1 , name = "const_1" )
214
214
215
- const_2_val = np .random .randn (2 , 4 , 5 , 3 ).astype (np .float32 ). reshape ( 120 ). tolist ()
216
- const_2 = helper .make_tensor ("const_2" , TensorProto .FLOAT , (2 , 4 , 5 , 3 ), const_2_val )
215
+ const_2_val = np .random .randn (2 , 4 , 5 , 3 ).astype (np .float32 )
216
+ const_2 = helper .make_tensor ("const_2" , TensorProto .FLOAT , (2 , 4 , 5 , 3 ), const_2_val . flatten () )
217
217
const_2_node = helper .make_node ("Constant" , [], ["const_2" ], value = const_2 , name = "const_2" )
218
218
219
219
node1 = helper .make_node ("Transpose" , ["X" ], ["Y" ], perm = [0 , 2 , 3 , 1 ], name = "trans_1" )
@@ -465,8 +465,8 @@ def test_transpose_add_with_input_non_const(self):
465
465
model_proto , remaining_transpose_num = 0 )
466
466
467
467
def test_transpose_add_with_input_const (self ):
468
- const_1_val = np .random .randn (1 , 3 , 3 , 1 ).astype (np .float32 ). reshape ( 9 ). tolist ()
469
- const_1 = helper .make_tensor ("const_1" , TensorProto .FLOAT , (1 , 3 , 3 , 1 ), const_1_val )
468
+ const_1_val = np .random .randn (1 , 3 , 3 , 1 ).astype (np .float32 )
469
+ const_1 = helper .make_tensor ("const_1" , TensorProto .FLOAT , (1 , 3 , 3 , 1 ), const_1_val . flatten () )
470
470
const_1_node = helper .make_node ("Constant" , [], ["const_1" ], value = const_1 , name = "const_1" )
471
471
472
472
node0 = helper .make_node ("Transpose" , ["X" ], ["Y" ], perm = [0 , 2 , 3 , 1 ], name = "trans_1" )
@@ -485,8 +485,9 @@ def test_transpose_add_with_input_const(self):
485
485
model_proto , remaining_transpose_num = 0 )
486
486
487
487
def test_transpose_add_with_conv_1 (self ):
488
- const_b_val = np .random .randn (1 , 1 , 1 , 16 ).astype (np .float32 ).reshape (16 ).tolist ()
489
- const_b = helper .make_tensor ("const_b" , TensorProto .FLOAT , (1 , 1 , 1 , 16 ), const_b_val )
488
+ # case where bias's dim is 1D and can be merged into Conv
489
+ const_b_val = np .random .randn (1 , 1 , 1 , 16 ).astype (np .float32 )
490
+ const_b = helper .make_tensor ("const_b" , TensorProto .FLOAT , (1 , 1 , 1 , 16 ), const_b_val .flatten ())
490
491
const_b_node = helper .make_node ("Constant" , [], ["const_b" ], value = const_b , name = "const_b" )
491
492
492
493
node0 = helper .make_node ("Conv" , ["x" , "W" ], ["X" ], name = "conv" , pads = [0 , 0 , 0 , 0 ])
@@ -508,8 +509,10 @@ def test_transpose_add_with_conv_1(self):
508
509
model_proto , remaining_transpose_num = 0 )
509
510
510
511
def test_transpose_add_with_conv_2 (self ):
511
- const_b_val = np .random .randn (1 , 3 , 3 , 1 ).astype (np .float32 ).reshape (9 ).tolist ()
512
- const_b = helper .make_tensor ("const_b" , TensorProto .FLOAT , (1 , 3 , 3 , 1 ), const_b_val )
512
+ # case where bias's dim is not 1D and can't be merged into Conv
513
+ # add handler just remove the transpose around Add node
514
+ const_b_val = np .random .randn (1 , 3 , 3 , 1 ).astype (np .float32 )
515
+ const_b = helper .make_tensor ("const_b" , TensorProto .FLOAT , (1 , 3 , 3 , 1 ), const_b_val .flatten ())
513
516
const_b_node = helper .make_node ("Constant" , [], ["const_b" ], value = const_b , name = "const_b" )
514
517
515
518
node0 = helper .make_node ("Conv" , ["x" , "W" ], ["X" ], name = "conv" , pads = [0 , 0 , 0 , 0 ])
0 commit comments