coder.DeepLearningConfig - Create deep learning code generation configuration objects - MATLAB (original) (raw)
Main Content
Create deep learning code generation configuration objects
Syntax
Description
[deepLearningCfg](#mw%5F94b517d0-ab62-473f-8fbf-0dbbf359afa8) = coder.DeepLearningConfig(TargetLibrary = [targetlib](#mw%5Faece8741-6f5a-4753-b5d3-b32ece9f4ed8))
creates a deep learning configuration object containing library-specific parameters thatcodegen uses to generate code for deep neural networks. Assign this deep learning configuration object to theDeepLearningConfig
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
Generate Code That Does Not Depends on Third-party Libraries for the ResNet-50 Network
Set the code configuration parameters and generate C++ code for anResNet-50
series network. The generate code does not depends on third-party deep learning libraries.
Create an entry-point function resnet_predict
that uses theimagePretrainedNetwork
function to load thedlnetwork
object that contains the ResNet-50
network. For more information, see Code Generation for dlarray
function out = resnet_predict(in)
dlIn = dlarray(in, 'SSCB'); persistent dlnet; if isempty(dlnet) dlnet = imagePretrainedNetwork('resnet50'); end
dlOut = predict(dlnet, dlIn); out = extractdata(dlOut);
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 224-by-224-by-3. To read an input image from a graphics file and resize it to 224-by-224, 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, setDeepLearningConfig
with targetlib
as'none'
. 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(TargetLibrary = 'none'); codegen -args {ones(224,224,3,'single')} -config cfg resnet_predict;
The codegen
command places all the generated files in thecodegen
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 neural network, weight, and bias files.
Input Arguments
targetlib
— Specify the target deep learning 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. |
Output Arguments
deepLearningCfg
— Deep learning configuration object
Configuration Object
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 an DeepLearningCodeConfig configuration object. |
'arm-compute' | Creates an ARMNEONConfig configuration object. |
'mkldnn' | Creates an MklDNNConfig configuration object. |
'cmsis-nn | Creates a CMSISNNConfig configuration object. |
'cudnn' | Creates a CuDNNConfig configuration object. |
'tensorrt' | Creates a TensorRTConfig configuration object. |
Version History
Introduced in R2018b
See Also
Functions
- codegen | imagePretrainedNetwork (Deep Learning Toolbox) | coder.loadDeepLearningNetwork
Objects
- coder.CodeConfig | coder.DeepLearningCodeConfig | coder.MklDNNConfig | coder.ARMNEONConfig | coder.CMSISNNConfig
Topics
- Code Generation for Deep Learning Networks with MKL-DNN
- Code Generation for Deep Learning Networks with ARM Compute Library
- Generate Generic C/C++ Code for Deep Learning Networks
- Code Generation for Object Detection by Using YOLO v2 (GPU Coder)
- Code Generation for Deep Learning Networks by Using cuDNN (GPU Coder)
- Code Generation for Deep Learning Networks by Using TensorRT (GPU Coder)