@@ -1456,17 +1456,14 @@ def fill_op(ctx, node, name, args):
1456
1456
# both shape and value in tensorflow are passed as tensor.
1457
1457
# In onnx the value is an attribute so we need to fetch the value as const which
1458
1458
# sooner or later will be a problem for tensorflow-onnx.
1459
- shape = ctx .get_shape (node .output [0 ])
1460
- utils .make_sure (all (i >= 0 for i in shape ), "shape attr should not be less than zero" )
1461
- value = node .inputs [1 ].get_tensor_value ()
1462
- value_proto = numpy_helper .from_array (node .inputs [1 ].get_tensor_value (as_list = False ))
1463
- dtype = value_proto .data_type
1464
- # onnx spec says value MUST be float.
1465
- node .set_attr ("value" , float (value ))
1466
- node .set_attr ("shape" , shape )
1467
- node .set_attr ("dtype" , dtype )
1468
- del node .input [:]
1469
- return node
1459
+ # ConstantOfShape in onnxruntime only support int64, so insert cast op
1460
+ cast_node = ctx .insert_new_node_on_input (node , "Cast" , node .input [0 ], to = onnx_pb .TensorProto .INT64 )
1461
+ dtype = ctx .get_dtype (node .output [0 ])
1462
+ value = np .array ([node .inputs [1 ].get_tensor_value ()]).astype (utils .ONNX_TO_NUMPY_DTYPE [dtype ])
1463
+ value_proto = numpy_helper .from_array (value )
1464
+ node .set_attr ("value" , value_proto )
1465
+ del node .input [1 ]
1466
+ return [node , cast_node ]
1470
1467
1471
1468
1472
1469
def reverse_op8 (ctx , node , name , args ):
0 commit comments