Main Content

Select Function to Import ONNX Pretrained Network

Deep Learning Toolbox™ Converter for ONNX™ Model Format provides three functions to import a pretrained ONNX (Open Neural Network Exchange) network: importONNXNetwork, importONNXLayers, and importONNXFunction.

This flow chart illustrates which import function best suits different scenarios.

Flow chart for selecting ONNX import function

Decisions

This table describes each decision in the workflow for selecting an ONNX import function.

DecisionDescription
Does the ONNX network have multiple outputs?
  • You can import an ONNX network with multiple inputs and a single output using importONNXNetwork. If the network has multiple outputs, use importONNXLayers or importONNXFunction.

  • importONNXLayers inserts placeholder layers for the outputs. For an example, see Import and Assemble ONNX Network with Multiple Outputs.

  • importONNXFunction supports importing ONNX networks with multiple inputs and outputs.

Are all the ONNX network layers supported?
  • If the ONNX network contains a layer that the Deep Learning Toolbox Converter for ONNX Model Format support package does not support (see Supported ONNX Layers), then importONNXNetwork returns an error message.

  • If the ONNX network contains an unsupported layer, then importONNXLayers inserts a placeholder layer in place of the unsupported layer.

  • importONNXFunction supports most ONNX layers. For more information, see Supported ONNX Layers by importONNXFunction.

Will you deploy the imported network?If you use importONNXNetwork or importONNXLayers, you can generate code for the imported network. To create a DAGNetwork object for code generation, see Load Pretrained Networks for Code Generation (MATLAB Coder).
Will you load the imported network with Deep Network Designer?If you use importONNXNetwork or importONNXLayers, you can load the imported network with the Deep Network Designer app.
If you retrain the imported network, will you use a custom training loop?

Actions

This table describes each action in the workflow for selecting an ONNX import function.

ActionDescription
Use importONNXNetworkimportONNXNetwork returns a DAGNetwork object that is ready to use for prediction. Use classify to perform predictions.
Use importONNXLayersimportONNXLayers returns a layerGraph object with placeholder layers in the place of unsupported layers. Find and replace the placeholder layers. Assemble the layer graph using assembleNetwork, which returns a DAGNetwork object.
Use importONNXFunctionimportONNXFunction returns an ONNXParameters object, which contains the network parameters, and a model function (see Imported ONNX Model Function), which contains the network architecture. The ONNXParameters object and the model function are ready to use for prediction. For an example, see Predict Using Imported ONNX Function.
Find and replace the placeholder layersTo find the names and indices of the unsupported layers in the network, use the findPlaceholderLayers function. You then can replace a placeholder layer with a new layer that you define. To replace a layer, use replaceLayer.

See Also

| | | | |

Related Topics