필터 지우기
필터 지우기

How to load a fully connected Pytorch model (trained.model) into matlab ?

조회 수: 113 (최근 30일)
Oualid Doukhi
Oualid Doukhi 2020년 10월 8일
댓글: Sivylla Paraskevopoulou 2022년 12월 13일
I have i fully connected neural networks which was trained in pytorch, the model was saved as (.model) i would like to load this model to matlab is there any way how to di it?

답변 (2개)

Ameer Hamza
Ameer Hamza 2020년 10월 8일
Yes, the deep learning toolbox supports Framework Interoperability: https://www.mathworks.com/products/deep-learning.html#frm. It directly supports importing models from TensorFlow and Caffe. For PyTorch, you might need to use the ONNX format to load it in MATLAB: https://www.mathworks.com/help/deeplearning/ref/importonnxnetwork.html. This webpage shows how to convert PyTorch to ONNX: https://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html.
  댓글 수: 4
Yam Alcaraz
Yam Alcaraz 2021년 3월 22일
Just to help out, I tried it with pytorch and it works:
  1. imported alexnet from torchvision
  2. exported as an .onnx file
  3. imported in matlab as importONNXNetwork('alexnet.onnx','OutputLayerType','classification');
Med Future
Med Future 2022년 3월 11일
@Yam Alcaraz Can you share your code for both pytorch and MATLAB

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


Sivylla Paraskevopoulou
Sivylla Paraskevopoulou 2022년 10월 7일
In R2022b we introduced the Deep Learning Toolbox Converter for PyTorch Models support package. This initial release supports importing image classification models. Support for other model types will be added in future releases. Use the function importNetworkFromPyTorch to import a PyTorch model. Make sure that the PyTorch model that you are importing is pretrained and traced.
For more details, check out the blog post What’s New in Interoperability with TensorFlow and PyTorch and the importNetworkFromPyTorch documentation page.
If you want to import another type (not image classification) model from PyTorch, convert you model to the ONNX model format and then, use the importONNXNetwork function.
  댓글 수: 4
Jean-Robert Philippe
Jean-Robert Philippe 2022년 12월 13일
In the opposite direction, how can we export a .pt model from Matlab? I obtained very good results with a model pre-trained in Matlab, but this kind of model doesn't exist in PyTorch.
I tried onnx format and onnx2pytorch, but it doesn't work.
Sivylla Paraskevopoulou
Sivylla Paraskevopoulou 2022년 12월 13일
Glad to hear you obtained good results with MATLAB!
At the moment, there is no direct path to convert MATLAB models to PyTorch models. You have to do it via ONNX by using the exportONNXNetwork function.
If exporting to TensorFlow is suitable for your workflow, you can use the exportNetworkToTensorFlow function to export MATLAB models to TensorFlow.

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

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by