MATLAB: Import Keras Tensorflow Model into Simulink

deepimportkeraslearningmachineMATLABsimulinktensorflow

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

Best Answer

  • 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.