@@ -399,22 +399,17 @@ def conv_convert_inputs(ctx, node, with_kernel=False, new_kernel_shape=None,
399
399
# kernel must to be transposed
400
400
if with_kernel :
401
401
parent = node .inputs [1 ]
402
- if node .inputs [1 ].is_const ():
403
- # kernel is const - transpose the const
404
- if not parent .data_format :
405
- val = parent .get_tensor_value (as_list = False )
406
- val = val .transpose (HWCN_TO_NCHW )
407
- parent .set_tensor_value (val )
408
- else :
409
- # kernel comes from op, insert transpose op
410
- input_name = node .input [1 ]
411
- transpose = ctx .insert_new_node_on_input (node , "Transpose" , input_name )
412
- transpose .set_attr ("perm" , HWCN_TO_NCHW )
413
- transpose .inserted_nchw = True
414
- ctx .copy_shape (input_name , transpose .output [0 ])
415
- new_shape = spatial_map (ctx .get_shape (input_name ), HWCN_TO_NCHW )
416
- ctx .set_shape (transpose .output [0 ], new_shape )
417
- nodes .append (transpose )
402
+ # note: kernel may be used by multiple nodes,
403
+ # so even kernel is a const, transposing kernel can't be done statically.
404
+ # so "transpose" op is inserted here and will consider to remove it in later optimization phase if possible.
405
+ input_name = node .input [1 ]
406
+ transpose = ctx .insert_new_node_on_input (node , "Transpose" , input_name )
407
+ transpose .set_attr ("perm" , HWCN_TO_NCHW )
408
+ transpose .inserted_nchw = True
409
+ ctx .copy_shape (input_name , transpose .output [0 ])
410
+ new_shape = spatial_map (ctx .get_shape (input_name ), HWCN_TO_NCHW )
411
+ ctx .set_shape (transpose .output [0 ], new_shape )
412
+ nodes .append (transpose )
418
413
parent .data_format = "NCHW"
419
414
420
415
# some onnx conv ops require the reshape the kernel (ie. depthwise_conv2d)
@@ -1227,6 +1222,12 @@ def minmax_op(ctx, node, name, args):
1227
1222
1228
1223
1229
1224
def pack_op (ctx , node , name , args ):
1225
+ # in tf, "pack" can accept one input tensor which means doing nothing,
1226
+ # so remove the node in ONNX
1227
+ if len (node .inputs ) == 1 :
1228
+ ctx .replace_all_inputs (ctx .get_nodes (), node .output [0 ], node .input [0 ])
1229
+ return None
1230
+
1230
1231
# hack to make up for the missing onnx pack op
1231
1232
axis = node .get_attr ("axis" ).i
1232
1233
if axis < 0 :
@@ -1436,7 +1437,7 @@ def fill_op7(ctx, node, name, args):
1436
1437
1437
1438
1438
1439
def fill_op (ctx , node , name , args ):
1439
- node .type = "ConstantLike "
1440
+ node .type = "ConstantOfShape "
1440
1441
# both shape and value in tensorflow are passed as tensor.
1441
1442
# In onnx the value is an attribute so we need to fetch the value as const which
1442
1443
# sooner or later will be a problem for tensorflow-onnx.
0 commit comments