Skip to content

Commit c0581f6

Browse files
committed
fix bug
if as_list is set to be true, then get_tensor_value will remain the dtype info; while if it's false then dtype info is removed. this will trigger a bug sometimes
1 parent db9ee29 commit c0581f6

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

tf2onnx/graph_builder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ def make_slice(self, kwargs, name=None, shapes=None, dtypes=None):
7070
while inputs[-1] == "":
7171
inputs = inputs[:-1]
7272

73+
if self.graph.opset >= 10:
74+
dtype = self.graph.get_dtype(inputs[1])
75+
for input_data in inputs[1:]:
76+
utils.make_sure(dtype == self.graph.get_dtype(input_data), "dtype should be same")
77+
7378
return self.graph.make_node(op_type="Slice", inputs=inputs, attr=attr, name=name,
7479
outputs=outputs, shapes=shapes, dtypes=dtypes).output[0]
7580

tf2onnx/onnx_opset/tensor.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,12 @@ def version_4(cls, ctx, node, **kwargs):
532532
attr = node.get_attr(attr_name)
533533
if attr is not None and attr.i != 0:
534534
raise ValueError("StridedSlice: attribute " + attr_name + " not supported")
535-
input_shape = ctx.get_shape(node.input[0])
536-
begin = node.inputs[1].get_tensor_value(as_list=False)
537-
end = node.inputs[2].get_tensor_value(as_list=False)
538-
strides = node.inputs[3].get_tensor_value(as_list=False)
539-
max_size = np.iinfo(begin.dtype).max
535+
onnx_dtype = ctx.get_dtype(node.input[1])
536+
np_dtype = utils.ONNX_TO_NUMPY_DTYPE[onnx_dtype]
537+
max_size = np.iinfo(np_dtype).max
538+
begin = node.inputs[1].get_tensor_value()
539+
end = node.inputs[2].get_tensor_value()
540+
strides = node.inputs[3].get_tensor_value()
540541
end_mask = node.get_attr("end_mask")
541542
end_mask = end_mask.i if end_mask is not None else 0
542543
begin_mask = node.get_attr("begin_mask")

0 commit comments

Comments
 (0)