Main Content

coder.DeepLearningConfig

Create deep learning code generation configuration objects

Description

example

deepLearningCfg= coder.DeepLearningConfig(TargetLibrary =targetlib)creates a deep learning configuration object containing library-specific parameters thatcodegenuses to generate code for deep neural networks. Assign this deep learning configuration object to theDeepLearningConfigproperty of the code configuration object created by usingcoder.config. Pass the code configuration object to thecodegenfunction by using the-configoption.

Examples

collapse all

Set the code configuration parameters and generate C++ code for anResNet-50series network. The generated code uses the Intel®MKL-DNN deep learning libraries.

Create an entry-point functionresnet_predictthat uses thecoder.loadDeepLearningNetworkfunction to load theresnet50(Deep Learning Toolbox)SeriesNetworkobject.

functionout = resnet_predict(in)persistentmynet;ifisempty(mynet) mynet = coder.loadDeepLearningNetwork('resnet50','myresnet');endout = predict(mynet,in);

The persistent object avoids reconstructing and reloading the network object during subsequent calls to the function to invoke thepredictmethod on the input.

的输入层pretrainedResNet-50network accepts images of size224x224x3. To read an input image from a graphics file and resize it to224x224, use the following lines of code:

in = imread('peppers.png'); in = imresize(in,[224,224]);

Create acoder.configconfiguration object for MEX code generation and set the target language to C++. On the configuration object, setDeepLearningConfigwithtargetlibas'mkldnn'. Use the-configoption of thecodegenfunction to pass this code configuration object. Thecodegenfunction must determine the size, class, and complexity of MATLAB®function inputs. Use the-argsoption to specify the size of the input to the entry-point function.

cfg = coder.config('mex'); cfg.TargetLang ='C++'; cfg.DeepLearningConfig = coder.DeepLearningConfig(TargetLibrary ='mkldnn'); codegen-args{ones(224,224,3,'single')}-configcfgresnet_predict;

Thecodegencommand places all the generated files in thecodegenfolder. It contains the C++ code for the entry-point functionresnet_predict.cpp, header and source files containing the C++ class definitions for the convoluted neural network (CNN), weight, and bias files.

Input Arguments

collapse all

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 theMATLAB Coder™ Interface for Deep Learning Libraries.

'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.

Output Arguments

collapse all

Configuration object based on the target library specified in the input argument. This object contains library-specific parameters that are used during code generation.

Target Library Deep Learning Configuration Object
'none' Creates anDeepLearningConfigBaseconfiguration object.
'arm-compute' Creates anARMNEONConfigconfiguration object.
'mkldnn' Creates anMklDNNConfigconfiguration object.
'cmsis-nn Creates aCMSISNNConfigconfiguration object.
'cudnn' Creates aCuDNNConfigconfiguration object.
'tensorrt' Creates aTensorRTConfigconfiguration object.

Version History

Introduced in R2018b