Code generation of a trained reinforcement learning agent

21 Ansichten (letzte 30 Tage)
Allmo
Allmo am 7 Mär. 2022
Bearbeitet: Allmo am 8 Mär. 2022
Hi,
i want to integrate a trained reinforcement learning agent to a microcontroller.
The training takes place in simulink.
The microcontroller only has a single precision FPU.
How do I setup the agent, that the agent uses single precision and not double presicion, especially if the observations are also of the single data type?

Akzeptierte Antwort

Sayan Saha
Sayan Saha am 7 Mär. 2022
Hi Allmo,
Since you are targeting a micro-controller to deploy code you can generate plain C/C++ code from the trained RL agent following the approaches in https://www.mathworks.com/help/reinforcement-learning/ug/deploy-trained-reinforcement-learning-agents.html. You'll have to use the library-free deep learning configuration object to generate plain C/C++ code as mentioned in https://www.mathworks.com/help/coder/ug/generate-generic-cc-code-for-deep-learning-networks.html :
dlconfig = coder.DeepLearningConfig(TargetLibrary='none');
While the input data to the entry-point function can be of non-single type, the data will always be casted to single precision before invoking the inference method on the network. You can specify the input data to be of single precision so that generated code will only have single precision data without any typecasting.
~Sayan
  3 Kommentare
Sayan Saha
Sayan Saha am 8 Mär. 2022
Great that it worked for you.
Single precision is the one common datatype across all different deep learning libraries like CuDNN/TensorRT/MKLDNN/... Many embedded targets also comes with only single precision FPUs. Even in MATLAB all the deep learning processing happens only in single precision.
We do support generating code for quantized deep learning networks as well where the datatype is INT8. You can find examples for both CPU and GPU target in https://www.mathworks.com/help/deeplearning/quantization.html however this is not yet supported for generic C/C++ codegen with TargetLibrary='none'.
~Sayan
Allmo
Allmo am 8 Mär. 2022
Bearbeitet: Allmo am 8 Mär. 2022
Thank you for the information!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by