From f24944395177bbeb49ebbf3f977065faf0bd7e87 Mon Sep 17 00:00:00 2001 From: Guenther Schmuelling Date: Tue, 31 Mar 2020 11:04:17 -0700 Subject: [PATCH 1/2] cherry pick fix to set IR based on opset --- tf2onnx/constants.py | 5 +++++ tf2onnx/graph.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/tf2onnx/constants.py b/tf2onnx/constants.py index 5c73c4949..d89a0f069 100644 --- a/tf2onnx/constants.py +++ b/tf2onnx/constants.py @@ -37,3 +37,8 @@ # Environment variables ENV_TF2ONNX_DEBUG_MODE = "TF2ONNX_DEBUG_MODE" + +# Mapping opset to IR version. +OPSET_TO_IR_VERSION = { + 1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3, 7: 3, 8: 4, 9: 4, 10: 5, 11: 6, 12: 7 +} diff --git a/tf2onnx/graph.py b/tf2onnx/graph.py index cbc8dd6b1..c01f5a090 100644 --- a/tf2onnx/graph.py +++ b/tf2onnx/graph.py @@ -990,6 +990,12 @@ def make_model(self, graph_doc, optimize=False, graph_name="tf2onnx", **kwargs): kwargs["opset_imports"] = opsets model_proto = helper.make_model(graph, **kwargs) + # set the IR version based on opset + try: + model_proto.ir_version = constants.OPSET_TO_IR_VERSION.get(self.opset, model_proto.ir_version) + except: # pylint: disable=bare-except + logger.error("ir_version override failed - install the latest onnx version") + # optimize the model proto. # TODO: this is disabled by default because of bugs in fuse_consecutive_transposes if optimize: From 3939afb3c3edd02e5479b21acd690c2e324a6c9c Mon Sep 17 00:00:00 2001 From: Guenther Schmuelling Date: Tue, 31 Mar 2020 12:11:51 -0700 Subject: [PATCH 2/2] PlaceholderWithDefault needs IR4: --- tf2onnx/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf2onnx/constants.py b/tf2onnx/constants.py index d89a0f069..3993980d7 100644 --- a/tf2onnx/constants.py +++ b/tf2onnx/constants.py @@ -40,5 +40,5 @@ # Mapping opset to IR version. OPSET_TO_IR_VERSION = { - 1: 3, 2: 3, 3: 3, 4: 3, 5: 3, 6: 3, 7: 3, 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 }