How can I generate C code from a Simulink model with a Neural Nework in the Matlab base workspace?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Louis Amigues
el 13 de Sept. de 2019
Editada: johnnynoc4sh
el 19 de Mayo de 2021
I have a Python Neural Network model, developped with Keras, and I want to embed it in a dSpace controller which works with C code. There is a dSpace Toolbox that imports a Simulink model in the controller by compiling it in C code, the 'Build Model' function.
I have succesfully imported my trained Python Neural Network in the Matlab Worspace with the Deep Learning Toolbox and the importKerasNetwork function. In Simulink I can use the Neural Network for prediction via the MATLAB function block with the following code and simulation of the Simulink model works :
%%%%%%%%%%%%%%
function y = fcn(X)
coder.extrinsic('evalin');
coder.extrinsic('predict');
NN = evalin('base','NN');
y = double(predict(NN,X));
%%%%%%%%%%%%%%
Here is my problem :
When I try to embed my Simulink model in the dSpace controller it doesn't work as :
- coder.extrinsic is not compatible with code generation,
- I am trying to embed a NN that is stored in the Matlab base workspace.
Should I rebuild my Neural Network in Simulink with the Simulink Deep Learning Toolbox blocks or is there a way to solve my problem in another way?
Thank you in advance for your time!
0 comentarios
Respuesta aceptada
Jyotish Kumar
el 13 de Nov. de 2019
Hi,
The code generator does not produce code for the body of the extrinsic function and instead uses the MATLAB® engine to execute the call. This functionality is available only when the MATLAB engine is available in MEX functions, Simulink® simulations, or during calls at compile time. For more information refer the link below
1 comentario
johnnynoc4sh
el 19 de Mayo de 2021
Editada: johnnynoc4sh
el 19 de Mayo de 2021
Hi Kumar,
are there any options to integrate Keras / Tensorflow models into codegeneratable Simulink models? We are using a Speedgoat platform and I would use it for forecasting timeseries.
Best
Más respuestas (0)
Ver también
Categorías
Más información sobre Deep Learning Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!