MATLAB: How to generate code from a trained LSTM network using MATLAB/Simulink

bidirectionalcc codeEmbedded CoderGPU Codermatlab codersimulinkstateful

Is code generation from a trained LSTM network supported, and if so, how? There appear to be different approaches to generate code from a trained LSTM network while working without/with Simulink.

Best Answer

  • Generate code from a trained LSTM network using MATLAB
    In order to generate code from a trained LSTM network using MATLAB, there are different approaches:
    1) Generate C/C++ code using MATLAB Coder:
    From MATLAB R2020a onwards, you can generate code for ARM Cortex-A CPUs. Refer to the blog post below on how to get started with deep learning models on ARM Cortex-A with MATLAB:
    Another example is here:
    From MATLAB R2020b onwards, you can generate C++ code for an LSTM network, a stateful LSTM network, or a bidirectional LSTM network that uses the IntelĀ® MKL-DNN library.
    2) Generate CUDA code using GPU Coder:
    From R2019b onwards, you can generate code for NVIDIA GPUs. See the following documentation link for more information:
    Generate code from a trained LSTM network using Simulink
    In order to generate code from a trained LSTM network using Simulink, the following approach will be possible from R2020b onwards:
    Using MATLAB Coder or GPU Coder, you can use* coder.loadDeepLearningNetwork* and other associated functions to run inference in a MATLAB Function block. This will support accelerated simulation and code generation for both CPU or GPU targets.