Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

exportONNXNetwork

Export network to ONNX model format

Export a trained Neural Network Toolbox™ deep learning network to the ONNX™ (Open Neural Network Exchange) model format [1][2]. You can then import the ONNX model to other deep learning frameworks, such as TensorFlow®, that support ONNX model import. This function requires the Neural Network Toolbox Converter for ONNX Model Format support package. To download and install the support package, use the Add-On Explorer. You can also download the support package from MathWorks Neural Network Toolbox Team.

Syntax

exportONNXNetwork(net,filename)
exportONNXNetwork(net,filename,'NetworkName',netName)

Description

example

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

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

Examples

collapse all

Download and install the Neural Network Toolbox Converter for ONNX Model Format support package using the Add-On Explorer. You can also download the support package from MathWorks Neural Network Toolbox Team.

Load a pretrained SqueezeNet convolutional neural network.

net = squeezenet
net = 
  DAGNetwork with properties:

         Layers: [68×1 nnet.cnn.layer.Layer]
    Connections: [75×2 table]

Export the network to an ONNX format file called squeezenet.onnx in the current folder.

filename = 'squeezenet.onnx';
exportONNXNetwork(net,filename)

You can now import the squeezenet.onnx file to another deep learning framework that supports import from ONNX. You can also visualize the ONNX model structure in Python® [3].

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 alexnet function) or by training your own network using trainNetwork.

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

Example: 'network.onnx'

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

Example: 'network_name'

Limitations

  • exportONNXNetwork does not export settings or properties related to network training such as training options, learning rate factors, or regularization factors.

  • If the network that you want to export contains a layer that the ONNX format does not support, then exportONNXNetwork saves a placeholder ONNX operator in place of the unsupported layer and returns a warning. It is not possible to import the ONNX model to other deep learning frameworks, but you can still visualize the model structure in Python [3].

  • exportONNXNetwork does not support networks containing recurrent layers such as LSTM or BiLSTM layers.

References

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

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

Introduced in R2018a

Was this topic helpful?