Inference simple AI model on MCU (Cortex M)
Reference from here
- Write an entry-point function in MATLAB that:
function out = my_predict(in)
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('Net.mat');
end
out = predict(mynet,in,'MiniBatchSize',2);
- Create a dlconfig that is configured for generating generic C/C++ code by using the coder.DeepLearningConfig function.
dlconfig = coder.DeepLearningConfig(TargetLibrary='none');
Create a code generation configuration object for MEX, executable, or static or dynamically linked library:
cfg = coder.config('lib');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = dlconfig;
- Run the codegen command
codegen -config cfg my_predict -args {testNormal} -report
Porting for RA8M1
-
copy all file
*.cpp
and*.h
in generate folder to foldersrc
of e2studio project:copy
tmwtypes.h
tosrc
folder -
Config project:
Stack size is 32kB:
Enable Data Cache:
TestCase | Time [ms] |
---|---|
w/ Data Cache | 6.374 |
wo/ Data Cache | 19.363 |
https://www.mathworks.com/help/predmaint/ug/anomaly-detection-using-3-axis-vibration-data.html https://www.mathworks.com/help/coder/ug/generate-generic-cc-code-for-deep-learning-networks.html