Run reinforcement learning Agent on raspberry

10 次查看(过去 30 天)
Hi,
my question is, how to run and train an reinforcement learning Agent on a raspberry pi.
I am having a Simulink model which uses an DDPG-agent from the reinforcement learning toolbox to learn a Sine-wave (on a raspberry and locally). I upload the Simulink model (sine_learning.slx. Raspberry_USB.slx).
The Raspberry reads a Sine-wave and outputs an action. The learning process should cause an convergence of the action with the sine-wave.
I have upladed the files used to train the model (with and without raspberry connection).
Only 1 file is run to train the net:
createSineAgent.m to train an agent locally
and
createUSBSineAgent.m to train on the raspberry.
The referenced Simulink models are sine_learning.slx and Raspberry_USB.slx. Two other files define the net-form and other training parameters.
The model is trained on a computer by exchanging the Serial-Read with a sine-wave-Simulink-block . During this the RL-agent is saved as a ".mat" file.
Now i want to execute this model on the raspberry. Running "create_USBAgent.m" directly does not seem to work. The training process is no initialized.
I heard i need to deploy the RL-Agent .
See:
I followed this instruction and generated an evaluatePolicy_mex.mexw64 file (according to - "C/C++ code for table, deep neural network, or linear basis function policies using MATLAB® Coder™" - see link
My question is, how can this Mex-file replace the network on the raspberry? Also is it possible to deploy an RLAgent on the board which continues to learn and improve its policy?
Alternatively, are there other ways to achieve my goal (running and training an RLAgent on a raspberry)?
Thank you for any tip or hint!!
Best regards,
V

采纳的回答

Sean de Wolski
Sean de Wolski 2021-6-11
You won't want to compile the MEX file to run on the Pi because it requires MATLAB. Instead generate code and recompile it for the Pi. Or bake that into the Simulink model (though a MATLAB function or system) and then when you generate code for the model, that part will come along (recommended workflow).
You can't generate code for training on the Pi, inference/prediction only.
  3 个评论
Walter Roberson
Walter Roberson 2021-6-12
There are two things referred to as mex files.
  1. files that end in .mex* file extensions. These are code that has been compiled to shared libraries (such as .dll or .so) for the architecture of the machine they are compiled on. The only cross-compiling that was ever supported was compiling on 64 bit windows for use on 32 bit windows. I might have missed some development for MacOS but as far as I know, compiling to ARM is not supported on any system. Note that these files require MATLAB desktop or at least MCR to run, and MCR is not available for ARM.
  2. sometimes mex files are used to refer to C or C++ (or Fortran) source code that has been written using MATLAB headers and using MATLAB library calls. In theory you could compile those to ARM. However they require an implementation library for the target system, and that is not available for ARM.
All of this is distinct from using a Simulink project with Simulink Coder technology to generate C / C++ targeting Raspberry or Arduino, or using MATLAB Coder to generate C++ targeting Raspberry (Arduino not supported). These routes do not require MCR... for the library functions they support.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Raspberry Pi Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by