Import Keras Tensorflow Model into Simulink

조회 수: 23 (최근 30일)
Lucas Ferreira-Correia
Lucas Ferreira-Correia 2020년 9월 11일
댓글: Jie Li 2021년 10월 13일
I've got a trained model from Python, which I need to run on Simulink for my application.
Is it possible to import trained Tensorflow Keras models and implement them in Simulink?
Cheers,
Lucas

채택된 답변

sruthi gundeti
sruthi gundeti 2020년 9월 12일
Hi,
You can import your keras network using
net = importKerasNetwork(modelfile)
net = importKerasNetwork(modelfile,Name,Value)
model file can .h5 format ot json format with weights
Then write a entry level function for the imported network
function out = resnetFun(in)
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('resnet50', 'myresnet');
end
out = predict(mynet,in);
You can integrate MATLAB function into your Simulink model using the MATLAB Function Block.
You can execute your MATLAB code from within the model to read the input data from your sensor and then pass this data into your Simulink block.
Refer to this example on how to use a MATLAB function block in your model.
  댓글 수: 2
Lucas Ferreira-Correia
Lucas Ferreira-Correia 2020년 9월 30일
Thank you for your help! I've imported my regression model and accordingly a placeholder layer is inserted on top of the model. I need a sequence input layer to replace the placeholder, is that possible? From the documentation I only see an image input layer available.
sruthi gundeti
sruthi gundeti 2021년 6월 7일
VxNet=importKerasNetwork('Network.json','WeightFile','Network.h5','OutputLayerType','regression')
This can import a regression network

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fernando Liozzi
Fernando Liozzi 2021년 6월 5일
Hi,
Is it possible to use this method to generate code for a microcontroller in c / c ++? Thank you.
  댓글 수: 2
Fernando Liozzi
Fernando Liozzi 2021년 6월 5일
Thanks, yes, is possible, my keras NN is working perfectly in a STM32!
Jie Li
Jie Li 2021년 10월 13일
Hi, Fernando, Could you post how you put it in the simulink? My code says the importKerasNetwork cannot be used when complie.Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Deep Learning with Simulink에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by