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
)
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 |
| nnet.onnx.layer.FlattenLayer and fullyConnectedLayer if ONNX network is recurrent, otherwise
fullyConnectedLayer |
| globalAveragePooling2dLayer |
| globalMaxPooling2dLayer |
| gruLayer |
| nnet.onnx.layer.IdentityLayer |
| nnet.onnx.layer.ElementwiseAffineLayer |
| leakyReluLayer |
| CrossChannelNormalizationLayer |
| lstmLayer or bilstmLayer |
| fullyConnectedLayer |
| maxPooling2dLayer |
| nnet.onnx.layer.ElementwiseAffineLayer |
| nnet.onnx.layer.PReluLayer |
| reluLayer or clippedReluLayer |
| nnet.onnx.layer.FlattenLayer |
| nnet.onnx.layer.SigmoidLayer |
| |
| nnet.onnx.layer.ElementwiseAffineLayer |
| additionLayer |
| tanhLayer |
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
| importONNXLayers