Walid Hanafy
Walid Hanafy

Reputation: 1609

How to merge two ONNX deep learning models

I have two models that are in ONNX format. Both models are similar (both are pre-trained deep learning models, ex. ResNet50 models). The only difference between them is that the last layers are optimized/retrained for different data sets.

I want to merge the first k layers of these two models, as shown below. This should enhance the performance of inference.

To make my case clearer these are examples from other machine learning tools to implement this feature Ex. Pytorch, Keras.

Merge

Upvotes: 1

Views: 6960

Answers (4)

Robin maltaros
Robin maltaros

Reputation: 341

I purposed an answer here. The main concepts of fusing inputs/outputs, transferring weights and changing names for unicity can be useful for you to adapt it to your structure. fuse_onnx_models

Upvotes: 0

FurkanCoskun
FurkanCoskun

Reputation: 106

sclblonnx package does not support dynamic size inputs.

For dynamic size inputs, one solution would be writing your own code using ONNX API as stated earlier.Another solution would be converting the two ONNX models to a framework(Tensorflow or PyTorch) using tools like onnx-tensorflow or onnx2pytorch. You could manipulate the networks in the Tensorflow or Pytorch and export the whole network to Onnx format.

Upvotes: 0

Maurits Kaptein
Maurits Kaptein

Reputation: 21

The sclblonnx package provides a number of higher level functions to edit ONNX graphs, including the ability to merge two subgraphs.

Upvotes: 2

Hariharan Seshadri
Hariharan Seshadri

Reputation: 106

You can use the ONNX package and the APIs it exposes (https://github.com/onnx/onnx/blob/master/docs/PythonAPIOverview.md) to mutate models/graphs.

Upvotes: 3

Related Questions