Main Content

coder.DeepLearningConfig

Create deep learning code generation configuration objects

Description

example

deepLearningCfg = coder.DeepLearningConfig(targetlib)creates a deep learning configuration object containing library-specific parameters that codegen uses to generate code for deep neural networks. Assign this deep learning configuration object to the DeepLearningConfig property of the code configuration object created by using coder.config. Pass the code configuration object to the codegen function by using the -config option.

Examples

collapse all

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

Create an entry-point function resnet_predict that uses the coder.loadDeepLearningNetwork function to load the resnet50 (Deep Learning Toolbox) SeriesNetwork object.

function out = resnet_predict(in)

persistent mynet;
if isempty(mynet)
    mynet = coder.loadDeepLearningNetwork('resnet50', 'myresnet');
end

out = predict(mynet,in);

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

The input layer of the pretrained ResNet-50 network accepts images of size 224x224x3. To read an input image from a graphics file and resize it to 224x224, use the following lines of code:

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

Create a coder.config configuration object for MEX code generation and set the target language to C++. On the configuration object, set DeepLearningConfig with targetlib as 'mkldnn'. Use the -config option of the codegen function to pass this code configuration object. The codegen function must determine the size, class, and complexity of MATLAB® function inputs. Use the -args option to specify the size of the input to the entry-point function.

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

The codegen command places all the generated files in the codegen folder. It contains the C++ code for the entry-point function resnet_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.

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

'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 LibraryDeep Learning Configuration Object
'arm-compute'Creates an ARMNEONConfig configuration object.
'mkldnn'Creates an MklDNNConfig configuration object.
'cudnn'Creates a CuDNNConfig configuration object.
'tensorrt'Creates a TensorRTConfig configuration object.

Introduced in R2018b