analyzeNetworkForCodegen - Analyze deep learning network for code generation - MATLAB (original) (raw)

Analyze deep learning network for code generation

Since R2022b

Syntax

Description

[result](#mw%5F4fe9ec2f-9bb7-4044-9cc6-8adb98a4747f) = analyzeNetworkForCodegen([net](#mw%5F84df0c26-26d9-4c89-9d3d-988d9b8e876b)) 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](#namevaluepairarguments)) 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

Check Network for Code Generation Compatibility

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.

         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

net — Deep learning network to analyze

SeriesNetwork object | DAGNetwork object | dlnetwork object

Network to analyze for code generation. Network can be adlnetwork, SeriesNetwork, orDAGNetwork object for custom training loops or custom pruning loops.

Name-Value Arguments

Specify optional pairs of arguments asName1=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"]);

TargetLibrary — Code generation target library

character vector | string scalar

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

Value Description
"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.

Quiet — Suppress report display

false (default) | true

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

Output Arguments

collapse all

result — Analysis output

structure array

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

Version History

Introduced in R2022b