@@ -1105,12 +1105,22 @@ def create_graph_from_onnx_model(onnx_model_proto):
1105
1105
# apply shape inference on the model
1106
1106
inferred_model = shape_inference .infer_shapes (onnx_model_proto )
1107
1107
graph_proto = inferred_model .graph
1108
- opset_version = onnx_model_proto .opset_import [0 ].version
1109
- main_graph = GraphUtil .create_graph_from_onnx_graph (graph_proto , opset_version )
1108
+
1109
+ opset_version = None
1110
+ extra_opset = []
1111
+ for opset in onnx_model_proto .opset_import :
1112
+ if not opset .domain :
1113
+ # domain field is None or empty means it is onnx domain
1114
+ opset_version = opset .version
1115
+ else :
1116
+ extra_opset .append (opset )
1117
+
1118
+ utils .make_sure (opset_version is not None , "opset version is not specified for onnx domain" )
1119
+ main_graph = GraphUtil .create_graph_from_onnx_graph (graph_proto , opset_version , extra_opset )
1110
1120
return main_graph
1111
1121
1112
1122
@staticmethod
1113
- def create_graph_from_onnx_graph (graph_proto , opset_version = None ):
1123
+ def create_graph_from_onnx_graph (graph_proto , opset_version = None , extra_opset = None ):
1114
1124
"""Create Graph loading onnx graph proto."""
1115
1125
output_shapes = {}
1116
1126
output_dtypes = {}
@@ -1137,15 +1147,15 @@ def create_graph_from_onnx_graph(graph_proto, opset_version=None):
1137
1147
for n in graph_proto .output :
1138
1148
output_names .append (n .name )
1139
1149
1140
- g = Graph (nodes_to_append , output_shapes , output_dtypes , None , opset_version , None , output_names )
1150
+ g = Graph (nodes_to_append , output_shapes , output_dtypes , None , opset_version , extra_opset , output_names )
1141
1151
const_nodes = GraphUtil ._parse_graph_initializer (g , graph_proto )
1142
1152
GraphUtil ._parse_graph_input (g , graph_proto , [n .name for n in const_nodes ])
1143
1153
1144
1154
for n in g .get_nodes ():
1145
1155
for attr_name , attr_val in n .attr .items ():
1146
1156
if attr_val .HasField ('g' ):
1147
1157
# it was assumed that the a.g has inferred shapes/dtypes.
1148
- sub_g = GraphUtil .create_graph_from_onnx_graph (attr_val .g , opset_version )
1158
+ sub_g = GraphUtil .create_graph_from_onnx_graph (attr_val .g , opset_version , extra_opset )
1149
1159
n .set_body_graph_as_attr (attr_name , sub_g )
1150
1160
return g
1151
1161
0 commit comments