Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling onnx model opset after creating Graph #125

Merged
merged 3 commits into from
Jun 15, 2020
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
13 changes: 10 additions & 3 deletions onnxconverter_common/onnx_fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
###############################################################################
import copy
import onnx
from onnx import onnx_pb as onnx_proto
import logging
import numpy as np

from . import onnx_ops
from . import onnx_ops, utils
from .registration import register_converter
from .topology import Topology, convert_topology
from .oopb import OnnxOperatorBuilder
from .onnx_ex import get_maximum_opset_supported
from .onnx_ex import OPSET_TO_IR_VERSION, get_maximum_opset_supported
from .data_types import (DoubleTensorType, FloatTensorType,
Int64TensorType, Int32TensorType, BooleanTensorType)

Expand Down Expand Up @@ -170,7 +171,6 @@ def _build_graph(self, f, input_types=None, output_types=None, outputs=None):
arg_names, _ = _get_python_function_arguments(f)
raw_model = _SimpleRawModelContainer(arg_names, outputs)
topo = Topology(raw_model)
topo.target_opset = Graph.opset
top_level = topo.declare_scope(f_name)
graph_opname = f_name
op_whole = top_level.declare_local_operator(graph_opname, f)
Expand All @@ -188,6 +188,13 @@ def _build_graph(self, f, input_types=None, output_types=None, outputs=None):
op_whole.outputs.append(vo_)

oxml = convert_topology(topo, f_name, "onnx.fn: {}".format(f_name), target_opset=Graph.opset)
if oxml.opset_import[0].domain == '':
oxml.opset_import[0].version = Graph.opset
opv = Graph.opset
irv = OPSET_TO_IR_VERSION.get(opv, onnx_proto.IR_VERSION)
oxml.ir_version = irv
oxml.model_version = utils.get_model_version()
_logger.warning('The maximum opset needed by this model is updated to %d.' % Graph.opset)
self._bind(oxml, arg_names, outputs)
return self

Expand Down
2 changes: 0 additions & 2 deletions onnxconverter_common/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,6 @@ def convert_topology(topology, model_name, doc_string, target_opset, targeted_on
else:
# Convert the selected operator into some ONNX objects and save them into the container
get_converter(operator.type)(scope, operator, container)
if operator.target_opset is not None:
container.node_domain_version_pair_sets.add(('', operator.target_opset))

# When calling ModelComponentContainer's add_initializer(...), nothing is added into the input list.
# However, for ONNX target opset < 9, initializers should also be model's (GraphProto) inputs.
Expand Down