Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci_build/azure_pipelines/templates/job_generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ parameters:
python_versions: ['3.7']
tf_versions: ['']
onnx_versions: ['']
onnx_opsets: ['12', '11', '10', '9', '8', '7']
onnx_backends: {onnxruntime: ['1.4.0']}
onnx_opsets: ['13', '12', '11', '10', '9', '8', '7']
onnx_backends: {onnxruntime: ['1.6.0']}
job: {}
run_setup: 'True'
report_coverage: 'False'
Expand Down
2 changes: 1 addition & 1 deletion ci_build/azure_pipelines/templates/unit_test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Run unit test

parameters:
onnx_opsets: ['12', '11', '10', '9', '8', '7']
onnx_opsets: ['13', '12', '11', '10', '9', '8', '7']

steps:
- ${{ each onnx_opset in parameters.onnx_opsets }}:
Expand Down
2 changes: 1 addition & 1 deletion tf2onnx/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@
# Mapping opset to IR version.
# Note: opset 7 and opset 8 came out with IR3 but we need IR4 because of PlaceholderWithDefault
OPSET_TO_IR_VERSION = {
1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3, 7: 4, 8: 4, 9: 4, 10: 5, 11: 6, 12: 7
1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3, 7: 4, 8: 4, 9: 4, 10: 5, 11: 6, 12: 7, 13: 7
}
3 changes: 3 additions & 0 deletions tf2onnx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,9 @@ def make_model(self, graph_doc, optimize=False, graph_name="tf2onnx", external_t
kwargs["opset_imports"] = opsets
model_proto = helper.make_model(graph, **kwargs)

utils.make_sure(self.opset in constants.OPSET_TO_IR_VERSION,
"Opset %s is not supported yet. Please use a lower opset" % self.opset)

# set the IR version based on opset
try:
model_proto.ir_version = constants.OPSET_TO_IR_VERSION.get(self.opset, model_proto.ir_version)
Expand Down
5 changes: 5 additions & 0 deletions tf2onnx/onnx_opset/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def version_13(cls, ctx, node, **kwargs):
node.set_attr("noop_with_empty_axes", 1)
if ctx.get_dtype(node.input[1]) != onnx_pb.TensorProto.INT64:
ctx.insert_new_node_on_input(node, "Cast", node.input[1], to=onnx_pb.TensorProto.INT64)
input_shape = ctx.get_shape(node.input[1])
input_rank = len(input_shape) if input_shape is not None else None
if input_rank != 1:
new_shape = ctx.make_const(utils.make_name("reshape_const"), np.array([-1], np.int64))
ctx.insert_new_node_on_input(node, "Reshape", [node.input[1], new_shape.output[0]])
else:
cls.version_11(ctx, node, **kwargs)

Expand Down
8 changes: 5 additions & 3 deletions tf2onnx/onnx_opset/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,8 @@ def version_1(cls, ctx, node, **kwargs):
# for each output we need to squeeze axis
for n in node.output:
op_name = utils.make_name(node.name)
squeeze_node = ctx.insert_new_node_on_output("Squeeze", n, name=op_name, axes=[axis])
squeeze_node = GraphBuilder(ctx).make_squeeze({'data': n, 'axes': [axis]}, name=op_name, return_node=True)
ctx.insert_node_on_output(squeeze_node, n)
ctx.copy_shape(n, squeeze_node.output[0])
ctx.copy_dtype(n, squeeze_node.output[0])

Expand Down Expand Up @@ -1637,8 +1638,9 @@ def any_version(cls, opset, ctx, node, **kwargs):
# add valid_outputs count
output_idx = 2 if node.type in ["NonMaxSuppressionV5"] else 1
shape_op = ctx.make_node("Shape", inputs=[nms_output.output[0]])
reduce_op = ctx.make_node("ReduceSum", inputs=shape_op.output, attr={"axes": [0], "keepdims": 0})
ctx.make_node("Cast", inputs=[reduce_op.output[0]], attr={"to": onnx_pb.TensorProto.INT32},
reduce_op = GraphBuilder(ctx).make_reduce_sum(
{"data": shape_op.output[0], "axes": [0], "keepdims": 0, "noop_with_empty_axes": 1})
ctx.make_node("Cast", inputs=[reduce_op], attr={"to": onnx_pb.TensorProto.INT32},
outputs=[node.output[output_idx]], dtypes=dtypes[output_idx], shapes=shapes[output_idx],
op_name_scope=node.name)

Expand Down