coder.CMSISNNConfig - Parameters to configure deep learning code generation with the CMSIS-NN library for
Cortex-M targets - MATLAB ([original](https://www.mathworks.com/help/coder/ref/coder.cmsisnnconfig.html)) ([raw](?raw))
Main Content
Parameters to configure deep learning code generation with the CMSIS-NN library for Cortex-M targets
Since R2022a
Description
The coder.CMSISNNConfig
object contains CMSIS-NN library and associated ARM® Cortex-M target specific parameters that codegen uses for generating C code for deep neural networks.
To use a coder.CMSISNNConfig
object for code generation, assign it to the DeepLearningConfig
property of a code generation configuration object that you pass to codegen
.
Creation
Create a CMSIS-NN configuration object by using the coder.DeepLearningConfig function with target library set as'cmsis-nn'
.
Properties
CalibrationResultFile
— Location of calibration MAT-file
''
(default) | character vector | string scalar
Location of the MAT-file containing the calibration data.
When performing quantization, the calibrate (Deep Learning Toolbox) function exercises the network and collects the dynamic ranges of the weights and biases in the convolution and fully connected layers of the network and the dynamic ranges of the activations in all layers of the network. To generate code for the optimized network, save the results from the calibrate
function to a MAT-file and specify the location of this MAT-file to the code generator using this property. For more information, see Generate int8 Code for Deep Learning Networks.
DataType
— Inference computation precision
'int8'
(default)
Precision of inference computations in supported layers.
TargetLibrary
— Target library name
'cmsis-nn'
(default)
Name of target library, specified as a character vector.
Examples
Specify Configuration Parameters for C Code Generation for a Deep Neural Network
Create an entry-point function net_predict
that uses thecoder.loadDeepLearningNetwork
function to load the network objectnet
from the MAT-file netFile
. The function then performs prediction using this model object.
function out = net_predict(netFile, in) net = coder.loadDeepLearningNetwork(netFile); out = predict(net,in); end
Create a coder.config
configuration object for generation of a C static library.
cfg = coder.config('lib');
Create a coder.CMSISNNConfig
deep learning configuration object and specify the location of the calibration MAT-file. Assign it to theDeepLearningConfig
property of the cfg
configuration object.
dlcfg = coder.DeepLearningConfig('cmsis-nn'); dlcfg.CalibrationResultFile = 'calibration.mat'; cfg.DeepLearningConfig = dlcfg;
Use the -config
option of the codegen function to specify the cfg
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.
codegen -config cfg net_predict -args {coder.Constant('calibration.mat'), exampleinput}
The codegen
command places all the generated files in thecodegen
folder.
Version History
Introduced in R2022a