Skip to content

Latest commit

 

History

History
61 lines (45 loc) · 1.75 KB

README.md

File metadata and controls

61 lines (45 loc) · 1.75 KB

AIonMCU

Inference simple AI model on MCU (Cortex M)

Training model

Reference from here

Generate predict model to C++

  1. 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); 
  1. 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;
  1. Run the codegen command
codegen -config cfg my_predict -args {testNormal} -report

Porting for RA8M1

  1. copy all file *.cpp and *.h in generate folder to folder src of e2studio project:

    source

    copy tmwtypes.h to src folder

  2. Config project:

    Stack size is 32kB:

    Stack

    Enable Data Cache:

    Cache

Result

TestCase Time [ms]
w/ Data Cache 6.374
wo/ Data Cache 19.363

Reference

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