- Retrain/recreate the model in Deep Learning Toolbox, so you don't have to convert to ONNX and deal with model import into MATLAB.
- If you can convert your model to TensrFlow, we support direct import from TensrFlow. Once the model is imported, again, use Stateful Predict block to bring it into Simulink.
Import a Neural Network trained in PyTorch in Simulink
45 views (last 30 days)
I would like to know if it is possible to import a neural network trained in PyTorch, into a Simulink model.
Specifically, in PyTorch I have trained a recurrent neural network in a parallel configuration (for simulation purposes), which identifies a dynamical black-box model. I would like to convert this network into a Simulink block, in order to fit it into a simulation model that marches through time.
Thank you in advance.
Arkadiy Turevskiy on 2 Dec 2021
At the moment the direct import of PyTorch models into MATLAB (and Simulink) is not supported. You can try exporting your PyTorch model to ONNX (open neural network exchange) format. Once the model is in ONNX, you can import it into MATLAB, and once the network is in MATLAB, you can add it to your Simulink model using Stateful Predict block from Deep Learning Toolbox Simulink library.
The other options you might consider:
Can I aks also: do you need to simulate only or is eventual goal code generation as well?
If none of these options are viable for you, please get in touch with me, and we'll try to support you.