Export network to ONNX model format
Export a trained Deep Learning Toolbox™ network to the ONNX™ (Open Neural Network Exchange) model format. You can then import the ONNX model to other deep learning frameworks that support ONNX model import, such as TensorFlow™, Caffe2, Microsoft® Cognitive Toolkit, Core ML, and Apache MXNet™.
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.
Load a pretrained SqueezeNet convolutional neural network. If Deep Learning
Toolbox Model for SqueezeNet Network is not installed, then
squeezenet function provides a download link.
net = squeezenet
net = DAGNetwork with properties: Layers: [68×1 nnet.cnn.layer.Layer] Connections: [75×2 table]
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'; exportONNXNetwork(net,filename)
Now, you can import the
squeezenet.onnx file into any deep
learning framework that supports ONNX
filename— Name of file
Name of file, specified as a character vector or string.
comma-separated pairs of
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
exportONNXNetwork(net,filename,'NetworkName','my_net')exports a network and specifies
'my_net'as the network name in the saved ONNX network.
'NetworkName'— Name of ONNX network
'Network'(default) | character vector | string
Name of ONNX network to store in the saved file, specified as a character vector or string.
'OpsetVersion'— Version of ONNX operator set
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.
exportONNXNetwork does not export settings or properties related to
network training such as training options, learning rate factors, or regularization
If you export a network that 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. You cannot import an ONNX network with a placeholder operator into other deep learning
exportONNXNetwork can export the following layers:
All layers in Deep Learning Toolbox except
All custom layers created when importing networks from ONNX or TensorFlow-Keras using Deep Learning Toolbox Converter for ONNX Model Format or Deep Learning Toolbox Importer for TensorFlow-Keras Models.