@@ -371,11 +371,26 @@ def _add_handler(self, trans, node):
371
371
# if Conv or ConvTranspose's bias input is not set, then we set, otherwise, we don't set
372
372
# todo: maybe we can add already set bias with the input??? try later
373
373
374
+ if not self ._nodes_has_single_consumer_node ([t_p ]):
375
+ self .logger .debug ("Conv does not have single consumer, can not merge Conv and Add" )
376
+ return self ._handle_node_having_branches (node )
377
+
378
+ if not self ._nodes_has_single_consumer_node ([trans ]):
379
+ self .logger .debug ("input transpose does not have single consumer, skipping..." )
380
+ return False
381
+
374
382
target_node = node .inputs [1 ]
375
383
numpy_val = target_node .get_tensor_value (as_list = False )
376
384
# Optional 1D bias to be added to the convolution, has size of M
377
385
if len (numpy_val .shape ) - numpy_val .shape .count (1 ) > 1 :
378
386
return self ._handle_node_having_branches (node )
387
+
388
+ rank = len (numpy_val .shape )
389
+ utils .make_sure (rank in (1 , 4 ), "only support bias rank = 4 or 1" )
390
+ # to make rank = 4
391
+ if rank == 1 :
392
+ numpy_val = numpy_val .reshape ((1 , 1 , 1 , numpy_val .shape [0 ]))
393
+
379
394
transposed_val = np .transpose (numpy_val , (0 , 3 , 1 , 2 ))
380
395
target_node .set_tensor_value (transposed_val )
381
396
0 commit comments