Main Content


Analyze deep learning network for code generation

Since R2022b


    result = analyzeNetworkForCodegen(net) analyzes the deep learning network net for code generation and reports network and layer compatibility issues. Network must be a SeriesNetwork, DAGNetwork, or dlnetwork object. By default, the function validates against a set of default CPU and GPU deep learning library targets.


    ___ = analyzeNetworkForCodegen(___,Name,Value) analyzes the deep learning network net for code generation by using the options specified by one or more Name,Value pair arguments.


    collapse all

    This example shows how to check code generation compatibility of the MobileNet-v2 network by using the analyzeNetworkForCodegen function.

    You can use the analyzeNetworkForCodegen function to determine network and layer compatibility issues when targeting a variety of CPU and GPU deep learning library targets.

    Download MobileNet-v2 Support Package

    This example uses the pretrained version of the MobileNet-v2 available through the Deep Learning Toolbox™ Model for MobileNet-v2 Network support package.

    MobileNet-v2 is a convolutional neural network that is 53 layers deep. The pretrained version of the network is trained on more than a million images from the ImageNet database. The pretrained network has an image input size of 224-by-224 and can classify images into 1000 object categories, such as keyboard, mouse, pencil, and many animals.

    ans = 
      DAGNetwork with properties:
             Layers: [154x1 nnet.cnn.layer.Layer]
        Connections: [163x2 table]
         InputNames: {'input_1'}
        OutputNames: {'ClassificationLayer_Logits'}

    If the Deep Learning Toolbox Model for MobileNet-v2 Network support package is not installed, then the function provides a link to the required support package in the Add-On Explorer. To install the support package, click the link, and then click Install.

    Analyze Network for Code Generation

    Run the analyzeNetworkForCodegen function for mobilenetv2, specifying the target libraries to analyze. The analyzeNetworkForCodegen function requires the MATLAB® Coder™ Interface for Deep Learning and the GPU Coder™ Interface for Deep Learning support packages. To install the required support packages, use the Add-On Explorer.

    targetLibraries = ["cudnn","tensorrt","arm-compute-mali",...
    S = analyzeNetworkForCodegen(mobilenetv2,TargetLibrary  = targetLibraries);
                            Supported                                                                                    LayerDiagnostics                                                                                 
                            _________    _________________________________________________________________________________________________________________________________________________________________________________
        cudnn                 "Yes"      ""                                                                                                                                                                               
        tensorrt              "Yes"      ""                                                                                                                                                                               
        arm-compute-mali      "Yes"      ""                                                                                                                                                                               
        arm-compute           "Yes"      ""                                                                                                                                                                               
        mkldnn                "Yes"      ""                                                                                                                                                                               
        none                  "Yes"      ""                                                                                                                                                                               
        cmsis-nn              "No"       "Found 6 unsupported layer type(s). View incompatible layer types."

    To access the analysis results for the CMSIS-NN target, use the following command.

                 TargetLibrary: 'cmsis-nn'
                     Supported: 0
            NetworkDiagnostics: [0x0 table]
              LayerDiagnostics: [150x3 table]
        IncompatibleLayerTypes: [6x1 string]

    Display the layer types not supported for CMSIS-NN code generation.

    ans = 6x1 string

    Input Arguments

    collapse all

    Network to analyze for code generation. Network can be a SeriesNetwork, DAGNetwork, or dlnetwork object for custom training loops or custom pruning loops.

    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.

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: resultStruct = analyzeNetworkForCodegen(mobilenetv2, TargetLibrary = ["mkldnn", "none"]);

    Target library for deep learning code generation, specified as one of the values in this table.


    For generating code that does not use any third-party library.


    For generating code that uses the ARM® Compute Library.


    For generating code that uses the Intel® Math Kernel Library for Deep Neural Networks (Intel MKL-DNN).


    Common Microcontroller Software Interface Standard - Neural Network (CMSIS-NN) library.

    Requires the MATLAB® Coder™ Interface for Deep Learning.


    For generating code that uses the CUDA® Deep Neural Network library (cuDNN).

    This option requires GPU Coder™.


    For generating code that takes advantage of the NVIDIA® TensorRT – high performance deep learning inference optimizer and run-time library.

    This option requires GPU Coder.

    Scalar boolean value to suppress report display. By default, the function displays the analysis in verbose mode.

    Output Arguments

    collapse all

    Results of checking the deep learning network for code generation compatibility, returned as a 1-by-N structure, where N is the number of target libraries to check for.

    Version History

    Introduced in R2022b