Multiple ONNX files into a single ONNX file

Hi All,
I want to merge two onnx files into a single onnx file where I need to pass different inputs and get the oupts separtely. Ideally there is no conncetion between the two modles but want to have a single onnx file.

I have tried the following.

import onnx

Load the first model

model1 = onnx.load(“tad.onnx”)

Load the second model

model2 = onnx.load(“adj.onnx”)
graph1 = model1.graph
graph2 = model2.graph

Combine the two models

#combined_model = onnx.helper.make_model([model1, model2])
combined_graph = onnx.helper.make_graph([graph1, graph2],‘combined_graph’,[model1.graph.input,model2.graph.input],[model1.graph.output,model2.graph.output])

Save the combined model to a file

onnx.save(combined_model, “combined_model.onnx”)

but got the below error

TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_8212\808156341.py in
11 # Combine the two models
12 #combined_model = onnx.helper.make_model([model1, model2])
—> 13 combined_graph = onnx.helper.make_graph([graph1, graph2],‘combined_graph’,[model1.graph.input,model2.graph.input],[model1.graph.output,model2.graph.output])
14
15 # Save the combined model to a file

~\Anaconda3\lib\site-packages\onnx\helper.py in make_graph(nodes, name, inputs, outputs, initializer, doc_string, value_info, sparse_initializer)
172 value_info =
173 graph = GraphProto()
→ 174 graph.node.extend(nodes)
175 graph.name = name
176 graph.input.extend(inputs)

TypeError: Parameter to MergeFrom() must be instance of same class: expected onnx.NodeProto got onnx.GraphProto.

  • List item

This is not a topic for TAO. Please search the network to check further. Thanks.