Import pretrained ONNX network
imports a pretrained network from the ONNX™ (Open Neural Network Exchange) file net
= importONNXNetwork(modelfile
,'OutputLayerType',outputtype
)modelfile
and specifies
the output layer type of the imported network.
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.
additionally specifies the classes for a classification network.net
= importONNXNetwork(modelfile
,'OutputLayerType',outputtype
,'Classes',classes
)
importONNXNetwork
supports ONNX versions as follows:
importONNXNetwork
supports ONNX intermediate representation version 6.
importONNXNetwork
fully supports ONNX operator sets 6, 7, 8, and 9.
importONNXNetwork
offers limited support for ONNX operator sets 10 and 11.
Note
If you import an exported network, layers of the reimported network might differ from the original network and might not be supported.
If the ONNX network contains a layer that Deep Learning Toolbox Converter for ONNX Model Format does not support, then the function returns an error message. In this
case, you can still use importONNXLayers
to import the network architecture and weights.
importONNXNetwork
supports the following ONNX
layers, with some limitations:
ONNX Layer | Deep Learning Toolbox Layer |
---|---|
| additionLayer or
nnet.onnx.layer.ElementwiseAffineLayer |
| averagePooling2dLayer |
| batchNormalizationLayer |
| nnet.onnx.layer.ClipLayer |
| concatenationLayer |
| None (Imported as weights) |
| convolution2dLayer |
| transposedConv2dLayer |
| nnet.onnx.layer.ElementwiseAffineLayer |
| dropoutLayer |
| nnet.onnx.layer.FlattenLayer or
nnet.onnx.layer.Flatten3dLayer |
| eluLayer |
| fullyConnectedLayer if ONNX network is recurrent, otherwise
nnet.onnx.layer.FlattenLayer followed by convolution2dLayer |
| globalAveragePooling2dLayer |
| globalMaxPooling2dLayer |
| gruLayer |
| nnet.onnx.layer.IdentityLayer |
| nnet.onnx.layer.ElementwiseAffineLayer |
| groupNormalizationLayer with numGroups
specified as "channel-wise" |
| leakyReluLayer |
| CrossChannelNormalizationLayer |
| lstmLayer or bilstmLayer |
| fullyConnectedLayer if ONNX network is recurrent, otherwise
convolution2dLayer |
| maxPooling2dLayer |
| multiplicationLayer |
| nnet.onnx.layer.PReluLayer |
| reluLayer or clippedReluLayer |
| nnet.onnx.layer.FlattenLayer |
| sigmoidLayer |
| |
| nnet.onnx.layer.ElementwiseAffineLayer |
| additionLayer |
| tanhLayer |
ONNX Layer | Computer Vision Toolbox Layer |
---|---|
| spaceToDepthLayer (Computer Vision Toolbox) |
ONNX Layer | Image Processing Toolbox™ |
---|---|
Resize | resize2dLayer (Image Processing Toolbox) or resize3dLayer (Image Processing Toolbox) |
Upsample | resize2dLayer (Image Processing Toolbox) or resize3dLayer (Image Processing Toolbox) |
You can import an ONNX network with multiple inputs and a single output using
importONNXNetwork
. If the network has multiple outputs, use
importONNXLayers
. The importONNXLayers
function
inserts placeholder layers for the outputs. After importing, you can find and replace
the placeholder layers by using findPlaceholderLayers
and replaceLayer
,
respectively. For an example, see Import ONNX Network with Multiple Outputs. To learn about a deep
learning network with multiple inputs and multiple outputs, see Multiple-Input and Multiple-Output Networks.
To use a pretrained network for prediction or transfer learning on new images, you must preprocess your images in the same way the images that were used to train the imported model were preprocessed. Most common preprocessing steps are resizing images, subtracting image average values, and converting the images from BGR images to RGB.
For more information on preprocessing images for training and prediction, see Preprocess Images for Deep Learning.
exportONNXNetwork
| importCaffeLayers
| importCaffeNetwork
| importKerasLayers
| importKerasNetwork
| importONNXFunction
| importONNXLayers