Import a Neural Network trained in PyTorch in Simulink

조회 수: 64 (최근 30일)
Marco Pizzoli
Marco Pizzoli 2021년 12월 2일
댓글: Pierre Harouimi 2022년 10월 10일
Hi everyone,
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.
Marco

답변 (1개)

Arkadiy Turevskiy
Arkadiy Turevskiy 2021년 12월 2일
Hi Marco,
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:
  1. Retrain/recreate the model in Deep Learning Toolbox, so you don't have to convert to ONNX and deal with model import into MATLAB.
  2. 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.
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.
Thanks
Arkadiy
  댓글 수: 3
Pierre Harouimi
Pierre Harouimi 2022년 10월 10일
You can now import PyTorch model as MATLAB network with importNetworkFromPyTorch function. Note that for now, you can import only image classification models, but support for other model types will be added in future updates. You can follow activities on the Deep Learning Toolbox Converter for PyTorch Models File Exchange support package.
Pierre Harouimi
Pierre Harouimi 2022년 10월 10일
Another approach is to co-execute external code, e.g., call TensorFlow or PyTorch models built in Python, directly from AMTLAB & Simulink. A nice and simple example here:

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by