Main Content

analyzeNetworkForCodegen

Analyze deep learning network for code generation

Since R2022b

    Description

    result = analyzeNetworkForCodegen(net) analyzes the deep learning network net for code generation and reports network and layer compatibility issues. Network must be a dlnetwork, SeriesNetwork, or DAGNetwork 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.

    example

    Examples

    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.

    mobilenetv2 = imagePretrainedNetwork('mobilenetv2')
    mobilenetv2 = 
      dlnetwork with properties:
    
             Layers: [153x1 nnet.cnn.layer.Layer]
        Connections: [162x2 table]
         Learnables: [210x3 table]
              State: [104x3 table]
         InputNames: {'input_1'}
        OutputNames: {'Logits_softmax'}
        Initialized: 1
    
      View summary with summary.
    
    

    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 = ["none","cudnn","tensorrt","mkldnn","arm-compute",...
        "arm-compute-mali","cmsis-nn"];
    S = analyzeNetworkForCodegen(mobilenetv2,TargetLibrary  = targetLibraries);
                            Supported                                                                                   LayerDiagnostics                                                                                
                            _________    _______________________________________________________________________________________________________________________________________________________________________________
    
        none                  "Yes"      ""                                                                                                                                                                             
        cudnn                 "Yes"      ""                                                                                                                                                                             
        tensorrt              "Yes"      ""                                                                                                                                                                             
        mkldnn                "Yes"      ""                                                                                                                                                                             
        arm-compute           "Yes"      ""                                                                                                                                                                             
        arm-compute-mali      "Yes"      ""                                                                                                                                                                             
        cmsis-nn              "No"       "Found 6 unsupported layer types. View incompatible layer types."
    

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

    disp(S(7))
                 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.

    S(7).IncompatibleLayerTypes
    ans = 6x1 string
        "AdditionLayer"
        "BatchNormalizationLayer"
        "ClippedReLULayer"
        "Convolution2DLayer"
        "GlobalAveragePooling2DLayer"
        "GroupedConvolution2DLayer"
    
    

    Input Arguments

    collapse all

    Network to analyze for code generation. Network can be a dlnetwork, SeriesNetwork, or DAGNetwork 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.

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

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

    ValueDescription
    "none"

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

    "arm-compute"

    For generating code that uses the ARM® Compute Library.

    "mkldnn"

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

    "cmsis-nn"

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

    Requires the MATLAB® Coder™ Interface for Deep Learning.

    "cudnn"

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

    This option requires GPU Coder™.

    "tensorrt"

    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