Main Content

选择要导入的函数ONNX Pretrained网络

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

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

Flow chart for selecting ONNX import function

Note

By default,importONNXNetworkandimportONNXLayerstry to generate a custom layer when the software cannot convert an ONNX operator into an equivalent built-in MATLAB®layer. For a list of operators for which the software supports conversion, seeONNX Operators Supported for Conversion into Built-In MATLAB Layers.

importONNXNetworkandimportONNXLayerssave the generated custom layers in the package+PackageNamein the current folder.

importONNXNetworkandimportONNXLayersdo not automatically generate a custom layer for each ONNX operator that is not supported for conversion into a built-in MATLAB layer.

Decisions

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

Decision Description
Are all the ONNX operators supported for conversion into equivalent built-in MATLAB layers or can the software automatically generate custom layers?
  • If the imported network contains an ONNX operator not supported for conversion into a built-in MATLAB layer (seeONNX Operators Supported for Conversion into Built-In MATLAB Layers) andimportONNXNetworkdoes not generate a custom layer, thenimportONNXNetwork返回一个n error.

  • If the imported network contains an ONNX operator not supported for conversion into a built-in MATLAB layer andimportONNXLayersdoes not generate a custom layer, thenimportONNXLayersinserts a placeholder layer in place of the unsupported layer.

  • importONNXFunctionsupports most ONNX operators. For more information, seeONNX Operators That importONNXFunction Supports.

Will you deploy the imported network? If you useimportONNXNetworkorimportONNXLayers, you can generate code for the imported network. To create aDAGNetworkobject for code generation, seeLoad Pretrained Networks for Code Generation(MATLAB Coder).
Will you load the imported network with Deep Network Designer? If you useimportONNXNetworkorimportONNXLayers, you can load the imported network with theDeep Network Designer应用程序。
If you retrain the imported network, will you use a custom training loop?
  • If you useimportONNXFunction, you can retrain the imported network only with a custom training loop. For an example, seeTrain Imported ONNX Function Using Custom Training Loop.

  • UseimportONNXNetworkwithTargetNetworkspecified as"dlnetwork"to import the network as adlnetworkobject. Adlnetworkenables support for custom training loops using automatic differentiation.

  • UseimportONNXLayerswithTargetNetworkspecified as"dlnetwork"to import the network as aLayerGraphobject compatible with adlnetworkobject. Then convert the layer graph to adlnetworkby usingdlnetwork.

  • For more information about training options, seeTrain Deep Learning Model in MATLAB.

Actions

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

Action Description
UseimportONNXNetwork importONNXNetwork返回一个DAGNetworkordlnetworkobject that is ready to use for prediction (for more information, see theTargetNetworkname-value argument). Predict class labels by using theclassifyfunction on theDAGNetworkobject or thepredictfunction on thedlnetworkobject.
UseimportONNXLayers importONNXLayers返回一个LayerGraphobject compatible with aDAGNetworkordlnetworkobject (for more information, see theTargetNetworkname-value argument).importONNXLayers插入占位符p层lace of unsupported layers. Find and replace the placeholder layers. Then, you can assemble the layer graph by usingassembleNetwork, which returns aDAGNetworkobject, or convert the layer graph to adlnetworkobject by usingdlnetwork.
UseimportONNXFunction importONNXFunction返回一个nONNXParametersobject, which contains the network parameters, and a model function (seeImported ONNX Model Function), which contains the network architecture. TheONNXParametersobject and the model function are ready to use for prediction. For an example, seePredict Using Imported ONNX Function.
Find and replace the placeholder layers To find the names and indices of the placeholder layers in the imported network, use thefindPlaceholderLayersfunction. You then can replace a placeholder layer with a new layer that you define. To replace a layer, usereplaceLayer.

See Also

||||||

Related Topics