Import pretrainedONNXnetwork
imports a pretrained network from the ONNX™ (Open Neural Network Exchange) filenet
= importONNXNetwork(modelfile
,'OutputLayerType',outputtype
)modelfile
and specifies the output layer type of the imported network.
This function requires theDeep Learning Toolbox™ Converter for ONNX Model Formatsupport 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 thatDeep Learning Toolbox Converter for ONNX Model Formatdoes not support, then the function returns an error message. In this case, you can still useimportONNXLayers
to import the network architecture and weights.
importONNXNetwork
supports the following ONNX layers, with some limitations:
ONNX Layer | Deep Learning Toolbox Layer |
---|---|
|
additionLayer 或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 或nnet.onnx.layer.Flatten3dLayer |
|
eluLayer |
|
fullyConnectedLayer if ONNX network is recurrent, otherwisennet.onnx.layer.FlattenLayer followed byconvolution2dLayer |
|
globalAveragePooling2dLayer |
|
globalMaxPooling2dLayer |
|
gruLayer |
|
nnet.onnx.layer.IdentityLayer |
|
nnet.onnx.layer.ElementwiseAffineLayer |
|
groupNormalizationLayer withnumGroups specified as"channel-wise" |
|
leakyReluLayer |
|
CrossChannelNormalizationLayer |
|
lstmLayer 或bilstmLayer |
|
fullyConnectedLayer if ONNX network is recurrent, otherwiseconvolution2dLayer |
|
maxPooling2dLayer |
|
multiplicationLayer |
|
nnet.onnx.layer.PReluLayer |
|
reluLayer 或clippedReluLayer |
|
nnet.onnx.layer.FlattenLayer |
|
sigmoidLayer |
|
|
|
nnet.onnx.layer.ElementwiseAffineLayer |
|
additionLayer |
|
tanhLayer |
ONNX Layer | Computer Vision Toolbox Layer |
---|---|
|
spaceToDepthLayer (计算机视觉Toolbox) |
ONNX Layer | Image Processing Toolbox™ |
---|---|
Resize |
resize2dLayer (Image Processing Toolbox)或resize3dLayer (Image Processing Toolbox) |
Upsample |
resize2dLayer (Image Processing Toolbox)或resize3dLayer (Image Processing Toolbox) |
You can import an ONNX network with multiple inputs and a single output usingimportONNXNetwork
. If the network has multiple outputs, useimportONNXLayers
. TheimportONNXLayers
function inserts placeholder layers for the outputs. After importing, you can find and replace the placeholder layers by usingfindPlaceholderLayers
andreplaceLayer
, respectively. For an example, seeImport ONNX Network with Multiple Outputs. To learn about a deep learning network with multiple inputs and multiple outputs, seeMultiple-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, seePreprocess Images for Deep Learning.
exportONNXNetwork
|importCaffeLayers
|importCaffeNetwork
|importKerasLayers
|importKerasNetwork
|importONNXFunction
|importONNXLayers