Main Content

importNetworkFromONNX

Import ONNX network as MATLAB network

Since R2023b

    Description

    example

    net = importNetworkFromONNX(modelfile) imports a pretrained Open Neural Network Exchange (ONNX™) network from the file modelfile. The function returns the network net as an initialized dlnetwork object.

    importNetworkFromONNX requires the Deep Learning Toolbox™ Converter for ONNX Model Format support package. If this support package is not installed, then importNetworkFromONNX provides a download link.

    Note

    The importNetworkFromONNX function can generate a custom layer when importing an ONNX layer. For more information, see Algorithms. The function saves the generated custom layers in the +modelfile namespace.

    example

    net = importNetworkFromONNX(modelfile,Name=Value) imports a pretrained ONNX network with additional options specified by one or more name-value arguments. For example, Namespace="CustomLayers" saves any generated custom layers and associated functions in the +CustomLayers namespace in the current folder.

    Examples

    collapse all

    Import a pretrained ONNX network as a dlnetwork object and use the imported network to classify an image.

    Generate an ONNX model of the SqueezeNet convolution neural network.

    [squeezeNet,ClassNames] = imagePretrainedNetwork("squeezenet");
    exportONNXNetwork(squeezeNet,"squeezeNet.onnx");

    Import the pretrained squeezeNet.onnx model.

    net = importNetworkFromONNX("squeezeNet.onnx")
    net = 
      dlnetwork with properties:
    
             Layers: [70x1 nnet.cnn.layer.Layer]
        Connections: [77x2 table]
         Learnables: [52x3 table]
              State: [0x3 table]
         InputNames: {'data'}
        OutputNames: {'prob_flatten_ReshapeOutput'}
        Initialized: 1
    
      View summary with summary.
    
    

    Read the image you want to classify and display the size of the image. The image has a size of 384-by-512 pixels and has three color channels (RGB).

    I = imread("peppers.png");
    size(I)
    ans = 1×3
    
       384   512     3
    
    

    Resize the image to the input size of the network. Show the image.

    net.Layers(1).InputSize
    ans = 1×3
    
       227   227     3
    
    
    I = imresize(I,[227 227]);
    imshow(I)

    Convert the image to a dlarray object. Format the images with the dimensions "SSCB" (spatial, spatial, channel, batch). In this case, the batch size is 1 and you can omit it ("SSC").

    I_dlarray = dlarray(single(I),"SSC");

    Classify the sample image and find the predicted label.

    prob = predict(net,I_dlarray);
    [~,label] = max(prob);

    Display the classification result.

    ClassNames(label)
    ans = 
    "bell pepper"
    

    Import a pretrained ONNX network that results in an uninitialized network. Then initialize the network.

    Specify the model file and import the model using the importNetworkFromONNX function. Since this model has an input layer with an unknown format or size, the function imports the model as an uninitialized dlnetwork object. The software displays a warning that describes how to initialize the network.

    ScalarOutputModel = 'dScalarGraphOutput.onnx';
    net = importNetworkFromONNX(ScalarOutputModel);
    Warning: Returning an uninitialized dlnetwork because some input layers have unknown data formats or undetermined image sizes. Initialize the network by passing example input data to the initialize object function.
    
    net.Initialized
    ans = logical
       0
    
    

    The custom input layer describes how to find the required input information.

    net.Layers
    ans = 
      4x1 Layer array with layers:
    
         1   'input_1'                         Custom input ('UUU')                               See the InputInformation property to find the required input dimension ordering for this layer.
         2   'Transpose_To_SoftmaxLayer1016'   dScalarGraphOutput.Transpose_To_SoftmaxLayer1016   dScalarGraphOutput.Transpose_To_SoftmaxLayer1016
         3   'x16Output'                       Custom output ('UUU')                              See the OutputInformation property to find the output dimension ordering that is produced by this layer.
         4   'x19Output'                       Custom output ('UU')                               See the OutputInformation property to find the output dimension ordering that is produced by this layer.
    
    net.Layers(1).InputInformation
    ans = 
        "Layer input must be a labeled dlarray with the dimension order shown in the ONNX model file.
         You must pass the size:
             (1, 1, 320)
         The dlarray must have a format string consisting of one 'U' for each dimension: 'dlarray(data, 'UUU')'"
    
    

    Create a labelled dlarray example input with the required size and initialize the network.

    X = dlarray(rand(1, 1, 320), 'UUU');
    net = initialize(net, X);
    summary(net)
       Initialized: true
    
       Number of learnables: 53.7k
    
       Inputs:
          1   'input_1'   Initialized using data of size 1x1x320 (UUU)
    

    Import a pretrained ONNX network as a dlnetwork object and use the imported network to classify a preprocessed image.

    Specify the model file to import as shufflenet with operator set 9 from the ONNX Model Zoo. shufflenet is a convolutional neural network that is trained on more than a million images from the ImageNet database. As a result, the network has learned rich feature representations for a wide range of images. The network can classify images into 1000 object categories, such as keyboard, mouse, pencil, and many animals.

    modelfile = "shufflenet-9.onnx";

    Import the class names from SqueezeNet, which is also trained with images from the ImageNet database.

    [~,ClassNames] = imagePretrainedNetwork("squeezenet");

    Import shufflenet. By default, importNetworkFromONNX imports the network as a dlnetwork object. Specify the namespace to save custom layers in as shufflenet_9.

    net = importNetworkFromONNX(modelfile,Namespace="shufflenet_9")
    net = 
      dlnetwork with properties:
    
             Layers: [174×1 nnet.cnn.layer.Layer]
        Connections: [189×2 table]
         Learnables: [198×3 table]
              State: [98×3 table]
         InputNames: {'gpu_0_data_0'}
        OutputNames: {'gpu_0_softmax_1Output'}
        Initialized: 1
    
      View summary with summary.
    
    

    Read the image you want to classify and display the size of the image. The image has a size of 792-by-1056 pixels and has three color channels (RGB).

    I = imread("peacock.jpg");
    size(I)
    ans = 1×3
    
             792        1056           3
    
    

    Check the input size of the network and resize the input image. Show the resized image.

    net.Layers(1).InputSize
    ans = 1×3
    
       224   224     3
    
    
    I = imresize(I,[224 224]);
    imshow(I)

    The inputs to shufflenet require further preprocessing (for details, see ShuffleNet in ONNX Model Zoo). Rescale the image. Normalize the image by subtracting the mean of the training images and dividing by the standard deviation of the training images.

    I = rescale(I,0,1);
    
    meanIm = [0.485 0.456 0.406];
    stdIm = [0.229 0.224 0.225];
    I = (I - reshape(meanIm,[1 1 3]))./reshape(stdIm,[1 1 3]);
    
    imshow(I)

    Classify the image using the imported network.

    prob = predict(net,I);
    [~,label] = max(prob);
    ClassNames{label}
    ans = 
    'peacock'
    

    Import a pretrained ONNX network, which contains operators that the software cannot convert to built-in MATLAB layers. The software automatically generates custom layers when you import this network.

    This example uses the findCustomLayers helper function. To view the code for this function, see Helper Function.

    Specify the model file to import as shufflenet with operator set 9 from the ONNX Model Zoo. shufflenet is a convolutional neural network that is trained on more than a million images from the ImageNet database. As a result, the network has learned rich feature representations for a wide range of images. The network can classify images into 1000 object categories, such as keyboard, mouse, pencil, and many animals.

    modelfile = "shufflenet-9.onnx";

    Import shufflenet. By default, importNetworkFromONNX imports the network as a dlnetwork object. importNetworkFromONNX saves each generated custom layer to a separate M file in the +shufflenet_9 namespace in the current folder.

    net = importNetworkFromONNX(modelfile,Namespace="shufflenet_9")
    net = 
      dlnetwork with properties:
    
             Layers: [174×1 nnet.cnn.layer.Layer]
        Connections: [189×2 table]
         Learnables: [198×3 table]
              State: [98×3 table]
         InputNames: {'gpu_0_data_0'}
        OutputNames: {'gpu_0_softmax_1Output'}
        Initialized: 1
    
      View summary with summary.
    
    

    Find the indices of the automatically generated custom layers by using the findCustomLayers helper function and display the custom layers.

    ind = findCustomLayers(net.Layers,'+shufflenet_9');
    net.Layers(ind)
    ans = 
      16×1 Layer array with layers:
    
         1   'Reshape_To_ReshapeLayer1285'   shufflenet_9.Reshape_To_ReshapeLayer1285   shufflenet_9.Reshape_To_ReshapeLayer1285
         2   'Reshape_To_ReshapeLayer1290'   shufflenet_9.Reshape_To_ReshapeLayer1290   shufflenet_9.Reshape_To_ReshapeLayer1290
         3   'Reshape_To_ReshapeLayer1295'   shufflenet_9.Reshape_To_ReshapeLayer1295   shufflenet_9.Reshape_To_ReshapeLayer1295
         4   'Reshape_To_ReshapeLayer1300'   shufflenet_9.Reshape_To_ReshapeLayer1300   shufflenet_9.Reshape_To_ReshapeLayer1300
         5   'Reshape_To_ReshapeLayer1305'   shufflenet_9.Reshape_To_ReshapeLayer1305   shufflenet_9.Reshape_To_ReshapeLayer1305
         6   'Reshape_To_ReshapeLayer1310'   shufflenet_9.Reshape_To_ReshapeLayer1310   shufflenet_9.Reshape_To_ReshapeLayer1310
         7   'Reshape_To_ReshapeLayer1315'   shufflenet_9.Reshape_To_ReshapeLayer1315   shufflenet_9.Reshape_To_ReshapeLayer1315
         8   'Reshape_To_ReshapeLayer1320'   shufflenet_9.Reshape_To_ReshapeLayer1320   shufflenet_9.Reshape_To_ReshapeLayer1320
         9   'Reshape_To_ReshapeLayer1325'   shufflenet_9.Reshape_To_ReshapeLayer1325   shufflenet_9.Reshape_To_ReshapeLayer1325
        10   'Reshape_To_ReshapeLayer1330'   shufflenet_9.Reshape_To_ReshapeLayer1330   shufflenet_9.Reshape_To_ReshapeLayer1330
        11   'Reshape_To_ReshapeLayer1335'   shufflenet_9.Reshape_To_ReshapeLayer1335   shufflenet_9.Reshape_To_ReshapeLayer1335
        12   'Reshape_To_ReshapeLayer1340'   shufflenet_9.Reshape_To_ReshapeLayer1340   shufflenet_9.Reshape_To_ReshapeLayer1340
        13   'Reshape_To_ReshapeLayer1345'   shufflenet_9.Reshape_To_ReshapeLayer1345   shufflenet_9.Reshape_To_ReshapeLayer1345
        14   'Reshape_To_ReshapeLayer1350'   shufflenet_9.Reshape_To_ReshapeLayer1350   shufflenet_9.Reshape_To_ReshapeLayer1350
        15   'Reshape_To_ReshapeLayer1355'   shufflenet_9.Reshape_To_ReshapeLayer1355   shufflenet_9.Reshape_To_ReshapeLayer1355
        16   'Reshape_To_ReshapeLayer1360'   shufflenet_9.Reshape_To_ReshapeLayer1360   shufflenet_9.Reshape_To_ReshapeLayer1360
    

    Helper Function

    This section defines the findCustomLayers helper function. findCustomLayers returns the indices of the custom layers that importNetworkFromONNX automatically generates.

    function indices = findCustomLayers(layers,Namespace)
    
    s = what(['.\' Namespace]);
    
    indices = zeros(1,length(s.m));
    for i = 1:length(layers)
        for j = 1:length(s.m)
            if strcmpi(class(layers(i)),[Namespace(2:end) '.' s.m{j}(1:end-2)])
                indices(j) = i;
            end
        end
    end
    
    end

    Input Arguments

    collapse all

    Name of ONNX model file ONNX model, specified as a character vector or string scalar. modelfile must be in the current folder, or you must include a full or relative path to the file.

    Example: "cifarResNet.onnx"

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: importNetworkFromONNX(modelfile,InputDataFormats="BCSS") imports the network in modelfile as a dlnetwork object where the dimension order of each input to the ONNX network is batch, channel, spatial, spatial.

    Name of the custom layers namespace in which importNetworkFromONNX saves custom layers, specified as a character vector or string scalar. importNetworkFromONNX saves the custom layers namespace +Namespace in the current folder. If you do not specify Namespace, then importNetworkFromONNX saves the custom layers in a namespace named +modelfile in the current folder. For more information about namespaces, see Create Namespaces.

    Example: Namespace="shufflenet_9"

    Example: Namespace="CustomLayers"

    Data format of the ONNX network inputs, specified as a character vector, string scalar, or string array. importNetworkFromONNX tries to interpret the input data formats from the ONNX file. Use this name-value argument when importNetworkFromONNX cannot determine the input data formats.

    Set InputDataFomats to a data format in the ordering of an ONNX input tensor. For example, if you specify InputDataFormats as "BCSS" (batch channel spatial spatial), the imported MATLAB® network has one imageInputLayer input, where the dimension order of each input is "SSCB" (spatial spatial channel batch). For more information about how importNetworkFromONNX interprets the data format of ONNX input tensors and how to specify InputDataFormats for different Deep Learning Toolbox input layers, see Conversion of ONNX Input Tensors into Deep Learning Toolbox Layers.

    If you specify an empty data format ([] or ""), importNetworkFromONNX automatically interprets the input data format.

    Example: InputDataFormats='BCSS'

    Example: InputDataFormats="BCSS"

    Example: InputDataFormats=["BCSS","","BC"]

    Example: InputDataFormats={'BCSS',[],'BC'}

    Data Types: char | string | cell

    Data format of the ONNX network outputs, specified as a character vector, string scalar, or string array. importNetworkFromONNX tries to interpret the output data formats from the ONNX file. Use this name-value argument when importNetworkFromONNX cannot determine the output data formats.

    Set OutputDataFormats to a data format in the ordering of an ONNX output tensor. For example, if you specify OutputDataFormats as "BC" (batch,channel), the imported MATLAB network has one nnet.onnx.layer.CustomOutputLayer output where the dimension order of each output is "CB" (channel,batch). For more information about how importNetworkFromONNX interprets the data format of ONNX output tensors and how to specify OutputDataFormats for different Deep Learning Toolbox output formats, see Conversion of ONNX Output Tensors into MATLAB Output Formats.

    If you specify an empty data format ([] or ""), importNetworkFromONNX automatically interprets the output data format.

    Example: OutputDataFormats='BC'

    Example: OutputDataFormats="BC"

    Example: OutputDataFormats=["BCSS","","BC"]

    Example: OutputDataFormats={'BCSS',[],'BC'}

    Data Types: char | string | cell

    Output Arguments

    collapse all

    Pretrained ONNX network, returned as an initialized dlnetwork object. You can predict class labels by using the predict function with this network. Specify the input data as a dlarray object using the correct data format. For more information, see the fmt argument of dlarray.

    Limitations

    • importNetworkFromONNX supports these ONNX:

      • ONNX intermediate representation version 7

      • ONNX operator sets 6–14

    Note

    If you import an exported network, layers of the reimported network might differ from layers of the original network, and might not be supported.

    More About

    collapse all

    ONNX Operators Supported for Conversion into Built-In MATLAB Layers

    importNetworkFromONNX supports these ONNX operators for conversion into built-in MATLAB layers, with some limitations.

    ONNX OperatorDeep Learning Toolbox Layer

    Add

    additionLayer or nnet.onnx.layer.ElementwiseAffineLayer

    AveragePool

    averagePooling1dLayer or averagePooling2dLayer

    BatchNormalization

    batchNormalizationLayer

    Concat

    concatenationLayer

    Constant

    None (Imported as weights)

    Conv*

    convolution1dLayer or convolution2dLayer

    ConvTranspose

    transposedConv2dLayer

    Dropout

    dropoutLayer

    Elu

    eluLayer

    Gemm

    fullyConnectedLayer if ONNX network is recurrent, otherwise nnet.onnx.layer.FlattenLayer followed by convolution2dLayer

    GlobalAveragePool

    globalAveragePooling1dLayer or globalAveragePooling2dLayer

    GlobalMaxPool

    globalMaxPooling1dLayer or globalMaxPooling2dLayer

    GRU

    gruLayer

    InstanceNormalization

    groupNormalizationLayer with numGroups specified as "channel-wise"

    LeakyRelu

    leakyReluLayer

    LRN

    CrossChannelNormalizationLayer

    LSTM

    lstmLayer or bilstmLayer

    MatMul

    fullyConnectedLayer if ONNX network is recurrent, otherwise convolution2dLayer

    MaxPool

    maxPooling1dLayer or maxPooling2dLayer

    Mul

    multiplicationLayer

    Relu

    reluLayer or clippedReluLayer

    Sigmoid

    sigmoidLayer

    Softmax

    softmaxLayer

    Sum

    additionLayer

    Tanh

    tanhLayer

    * If importNetworkFromONNX imports the Conv ONNX operator as a convolution2dLayer object and the Conv operator is a vector with only two elements [p1 p2], importNetworkFromONNX sets the Padding option of convolution2dLayer to [p1 p2 p1 p2].

    ONNX OperatorONNX Importer Custom Layer

    Clip

    nnet.onnx.layer.ClipLayer

    Div

    nnet.onnx.layer.ElementwiseAffineLayer

    Flatten

    nnet.onnx.layer.FlattenLayer or nnet.onnx.layer.Flatten3dLayer

    Identity

    nnet.onnx.layer.IdentityLayer

    ImageScaler

    nnet.onnx.layer.ElementwiseAffineLayer

    PRelu

    nnet.onnx.layer.PreluLayer

    Reshape

    nnet.onnx.layer.FlattenLayer

    Sub

    nnet.onnx.layer.ElementwiseAffineLayer
    ONNX OperatorCorresponding Image Processing Toolbox™ Layer
    DepthToSpacedepthToSpace2dLayer (Image Processing Toolbox)
    Resizeresize2dLayer (Image Processing Toolbox) or resize3dLayer (Image Processing Toolbox)
    SpaceToDepthspaceToDepthLayer (Image Processing Toolbox)
    Upsampleresize2dLayer (Image Processing Toolbox) or resize3dLayer (Image Processing Toolbox)

    Conversion of ONNX Input and Output Tensors into Built-In MATLAB Layers and Formats

    importNetworkFromONNX tries to interpret the data format of the ONNX network's input and output tensors, and then convert them into built-in MATLAB input layers and output formats. For details about the interpretation, see Conversion of ONNX Input Tensors into Deep Learning Toolbox Layers and Conversion of ONNX Output Tensors into MATLAB Output Formats.

    In Deep Learning Toolbox, each data format character must be one of these labels:

    • S — Spatial

    • C — Channel

    • B — Batch observations

    • T — Time or sequence

    • U — Unspecified

    Conversion of ONNX Input Tensors into Deep Learning Toolbox Layers

    Data FormatsData InterpretationDeep Learning Toolbox Layer
    ONNX Input Tensor MATLAB Input FormatShapeType
    BCCBc-by-n array, where c is the number of features and n is the number of observationsFeaturesfeatureInputLayer
    BCSS, BSSC, CSS, SSCSSCB

    h-by-w-by-c-by-n numeric array, where h, w, c, and n are the height, width, number of channels of the images, and number of observations, respectively

    2-D imageimageInputLayer
    BCSSS, BSSSC, CSSS, SSSCSSSCB

    h-by-w-by-d-by-c-by-n numeric array, where h, w, d, c, and n are the height, width, depth, number of channels of the images, and number of image observations, respectively

    3-D imageimage3dInputLayer
    TBCCBT

    c-by-s-by-n matrix, where c is the number of features of the sequence, s is the sequence length, and n is the number of sequence observations

    Vector sequencesequenceInputLayer
    TBCSSSSCBT

    h-by-w-by-c-by-s-by-n array, where h, w, c, and n correspond to the height, width, and number of channels of the image, respectively, s is the sequence length, and n is the number of image sequence observations

    2-D image sequencesequenceInputLayer
    TBCSSSSSSCBT

    h-by-w-by-d-by-c-by-s-by-n array, where h, w, d, and c correspond to the height, width, depth, and number of channels of the image, respectively, s is the sequence length, and n is the number of image sequence observations

    3-D image sequencesequenceInputLayer

    Conversion of ONNX Output Tensors into MATLAB Output Formats

    Data Formats
    ONNX Output TensorMATLAB Output Format
    BC, TBCCB, CBT
    BCSS, BSSC, CSS, SSC, BCSSS, BSSSC, CSSS, SSSCSSCB, SSSCB
    TBCSS, TBCSSSSSCBT, SSSCBT

    Generate Code for Imported Network

    You can use MATLAB Coder™ or GPU Coder™ software with Deep Learning Toolbox software to generate MEX, standalone CPU, CUDA® MEX, or standalone CUDA code for an imported network. For more information, see Code Generation.

    • Use MATLAB Coder with Deep Learning Toolbox to generate MEX or standalone CPU code that runs on desktop or embedded targets. You can deploy generated standalone code that uses the Intel® Math Kernel Library for Deep Neural Networks (MKL-DNN) or the ARM® Compute library. Alternatively, you can generate generic C or C++ code that does not call third-party library functions. For more information, see Deep Learning with MATLAB Coder (MATLAB Coder).

    • Use GPU Coder with Deep Learning Toolbox to generate CUDA MEX or standalone CUDA code that runs on desktop or embedded targets. You can deploy generated standalone CUDA code that uses the CUDA deep neural network library (cuDNN), the TensorRT™ high performance inference library, or the ARM Compute library for Mali GPU. For more information, see Deep Learning with GPU Coder (GPU Coder).

    importNetworkFromONNX returns the network net as a dlnetwork object. This object supports code generation. For more information about MATLAB Coder and GPU Coder support for Deep Learning Toolbox objects, see Supported Classes (MATLAB Coder) and Supported Classes (GPU Coder), respectively.

    You can generate code for any imported network whose layers support code generation. For lists of the layers that support code generation with MATLAB Coder and GPU Coder, see Supported Layers (MATLAB Coder) and Supported Layers (GPU Coder), respectively. For more information about the code generation capabilities and limitations of each built-in MATLAB layer, see the Extended Capabilities section of the layer. For example, see Code Generation and GPU Code Generation of imageInputLayer.

    Use Imported Network on GPU

    importNetworkFromONNX does not execute on a GPU. However, importNetworkFromONNX imports a pretrained neural network for deep learning as a dlnetwork object, which you can use on a GPU.

    • If you import the network as a dlnetwork object, you can make predictions with the imported network on a CPU or GPU by using predict. The predict function executes on the GPU if you store the input data or network parameters on the GPU.

      • If you use minibatchqueue to process and manage the mini-batches of input data, the minibatchqueue object converts the output to a GPU array by default if a GPU is available.

      • Use dlupdate to convert the learnable parameters of a dlnetwork object to GPU arrays.

        net = dlupdate(@gpuArray,net)

    • You can train the imported network on either a CPU or GPU by using trainnet. To specify training options, including options for the execution environment, use the trainingOptions function. Specify the hardware requirements using the ExecutionEnvironment name-value argument. For more information about how to accelerate training, see Scale Up Deep Learning in Parallel, on GPUs, and in the Cloud.

    Using a GPU requires a Parallel Computing Toolbox™ license and a supported GPU device. For information about supported devices, see GPU Computing Requirements (Parallel Computing Toolbox).

    Tips

    • To use a pretrained network for prediction or transfer learning on new images, you must preprocess your images in the same way as the images that you use to train the imported model. The most common preprocessing steps are resizing images, subtracting image average values, and converting the images from BGR format to RGB format.

      • To resize images, use imresize. For example, imresize(image,[227 227 3]).

      • To convert images from RGB to BGR format, use flip. For example, flip(image,3).

      For more information about preprocessing images for training and prediction, see Preprocess Images for Deep Learning.

    • The members of the +Namespace namespace (custom layers and operators) are not accessible if the namespace parent folder is not on the MATLAB path. For more information, see Namespaces and the MATLAB Path.

    • MATLAB uses one-based indexing, whereas Python® uses zero-based indexing. In other words, the first element in an array has an index of 1 and 0 in MATLAB and Python, respectively. For more information about MATLAB indexing, see Array Indexing. In MATLAB, to use an array of indices (ind) created in Python, convert the array to ind+1.

    • For more tips, see Tips on Importing Models from TensorFlow, PyTorch, and ONNX.

    Algorithms

    The importNetworkFromONNX function imports an ONNX operator into MATLAB by trying these steps in order:

    1. The function tries to import the ONNX operator as a built-in MATLAB layer. For more information, see ONNX Operators Supported for Conversion into Built-In MATLAB Layers.

    2. The function tries to import the ONNX operator as a custom layer. importNetworkFromONNX saves the generated custom layers and the associated functions in the +Namespace namespace. For an example, see Import ONNX Network with Automatically Generated Custom Layers.

    3. The function imports the ONNX operator as a custom layer with a placeholder function. You must complete the placeholder function before you can use the network.

    If these steps do not result in an imported network, you can use the importONNXFunction function. importONNXFunction imports the model as an ONNXParameters object, which contains the network parameters, and a model function, which contains the network architecture.

    In some cases, the software indicates that you need to initialize the imported network.

    References

    [1] GitHub. “Open Neural Network Exchange.” Accessed July 3, 2023. https://github.com/onnx/.

    [2] "ONNX | Home.” Accessed July 3, 2023. https://onnx.ai/.

    Version History

    Introduced in R2023b