Main Content

coder.CMSISNNConfig

Parameters to configure deep learning code generation with the CMSIS-NN library for Cortex-M targets

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

expand all

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.

Precision of inference computations in supported layers.

Name of target library, specified as a character vector.

Examples

collapse all

Create an entry-point function net_predict that uses the coder.loadDeepLearningNetwork function to load the network object net 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 the DeepLearningConfig 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 the codegen folder.

Version History

Introduced in R2022a