Export network to ONNX model format



exportONNXNetwork(net,filename) exports the deep learning network net with weights to the ONNX™ format file filename. If filename exists, then exportONNXNetwork overwrites the file.

This function requires the Deep Learning Toolbox™ Converter for ONNX Model Format support package. If this support package is not installed, then the function provides a download link.

exportONNXNetwork(net,filename,Name,Value) exports a network using additional options specified by one or more name-value pair arguments.


collapse all

Load a pretrained SqueezeNet convolutional neural network.

net = squeezenet
  DAGNetwork with properties:

         Layers: [68×1 nnet.cnn.layer.Layer]
    Connections: [75×2 table]
     InputNames: {'data'}
    OutputNames: {'ClassificationLayer_predictions'}

Export the network as an ONNX format file in the current folder called squeezenet.onnx. If the Deep Learning Toolbox Converter for ONNX Model Format support package is not installed, then the function provides a link to the required support package in the Add-On Explorer. To install the support package, click the link, and then click Install.

filename = 'squeezenet.onnx';

Now, you can import the squeezenet.onnx file into any deep learning framework that supports ONNX import.

Input Arguments

collapse all

Trained network, specified as a SeriesNetwork or a DAGNetwork object. You can get a trained network by importing a pretrained network (for example, by using the googlenet function) or by training your own network using trainNetwork.

Name of file, specified as a character vector or string scalar.

Example: 'network.onnx'

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: exportONNXNetwork(net,filename,'NetworkName','my_net') exports a network and specifies 'my_net' as the network name in the saved ONNX network.

Name of ONNX network to store in the saved file, specified as a character vector or a string scalar.

Example: 'my_squeezenet'

Version of ONNX operator set to use in the exported model. If the default operator set does not support the network you are trying to export, then try using a later version. If you import the exported network to another framework and you used an operator set during export that the importer does not support, then the import can fail.

Example: 6



[1] Open Neural Network Exchange. https://github.com/onnx/.

[2] ONNX. https://onnx.ai/.

Introduced in R2018a