Pretrained Networks from External Platforms
R2026bThere are two approaches for using pretrained networks from external deep learning platforms: import the model, or use coexecution to train and test external models. The preferred approach is to import the model whenever possible.
Deep Learning Toolbox™ supports neural networks import from TensorFlow™ 2, TensorFlow-Keras, Keras 3, PyTorch®, the ONNX™ (Open Neural Network Exchange) model format, and Caffe. Import networks interactively using the Deep Network Designer app or programmatically using command line functions. The app generates an import report that summarizes the import process and highlights any required actions. For more information, see Pretrained Deep Neural Networks and Interoperability Between Deep Learning Toolbox, TensorFlow, PyTorch, and ONNX.
Import functions in Deep Learning Toolbox require specific support packages. If a required support package is not installed, each function provides a download link to the corresponding support package in the Add-On Explorer. Download the support package to the default location for the MATLAB® version in use. Support packages are also available for direct download:
importNetworkFromONNXrequires Deep Learning Toolbox Converter for ONNX Model Format. To download the support package, go to https://www.mathworks.com/matlabcentral/fileexchange/67296-deep-learning-toolbox-converter-for-onnx-model-format.importNetworkFromPyTorchrequires Deep Learning Toolbox Converter for PyTorch Models. To download the support package, go to https://www.mathworks.com/matlabcentral/fileexchange/111925-deep-learning-toolbox-converter-for-pytorch-models.importNetworkFromTensorFlowandimportNetworkFromKerasrequire Deep Learning Toolbox Converter for TensorFlow Models. To download the support package, go to https://www.mathworks.com/matlabcentral/fileexchange/64649-deep-learning-toolbox-converter-for-tensorflow-models.
Interoperation between MATLAB and External Deep Learning Platforms
If importing a pretrained network is not possible, you can use coexecution to
run external models. Coexecution is supported for Python®-based models, including TensorFlow, ONNX, PyTorch, and custom Python models. For PyTorch models, you can run the model directly in MATLAB using a PyTorchModel object. This object acts
as a wrapper that executes the model in Python through the MATLAB–Python interface, enabling integration without requiring model import.
You also can convert between MATLAB numeric arrays and PyTorch Tensors by using the arrayToTorchTensor and torchTensorToArray functions.
Apps
| Deep Network Designer | Design and visualize deep learning networks |
Functions
Objects
PyTorchModel | Reference to a PyTorch model for Python execution (Since R2026b) |
Topics
Import
- Use PyTorch and MATLAB for Deep Learning Workflows
Learn how to use PyTorch models with MATLAB and Simulink® for deep learning workflows. - Interoperability Between Deep Learning Toolbox, TensorFlow, PyTorch, and ONNX
Learn how to import networks from TensorFlow, Keras 3, PyTorch, and ONNX and use the imported networks for common Deep Learning Toolbox workflows. Learn how to export networks to TensorFlow and ONNX. - Tips on Importing Models from TensorFlow, PyTorch, and ONNX
Tips on importing Deep Learning Toolbox networks from TensorFlow, Keras, PyTorch, and ONNX. - Import PyTorch Model Using Deep Network Designer
This example shows how to import a PyTorch® model interactively by using the Deep Network Designer app. (Since R2023b) - Pretrained Deep Neural Networks
Learn how to download and use pretrained convolutional neural networks for classification, transfer learning and feature extraction. - Inference Comparison Between TensorFlow and Imported Networks for Image Classification
Perform prediction in TensorFlow with a pretrained network, import the network into MATLAB usingimportTensorFlowNetwork, and then compare inference results between TensorFlow and MATLAB networks. - Inference Comparison Between ONNX and Imported Networks for Image Classification
Perform prediction in ONNX with a pretrained network, import the network into MATLAB usingimportONNXNetwork, and then compare inference results between ONNX and MATLAB networks. - Classify Images in Simulink with Imported TensorFlow Network
Import a pretrained TensorFlow network usingimportTensorFlowNetwork, and then use the Predict block for image classification in Simulink. - Deploy Imported TensorFlow Model with MATLAB Compiler
Import third-party pretrained networks and deploy the networks using MATLAB Compiler™. - View Autogenerated Custom Layers Using Deep Network Designer
This example shows how to import a pretrained TensorFlow™ network and view the autogenerated layers in Deep Network Designer. - Verify Robustness of Imported ONNX Network
This example shows how to verify the adversarial robustness of an imported ONNX™ deep neural network. (Since R2024a)
Python Coexecution for Simulink blocks
- Classify Images Using TensorFlow Model Predict Block
Classify images using TensorFlow Model Predict block. - Classify Images Using ONNX Model Predict Block
Classify images using ONNX Model Predict block. - Classify Images Using PyTorch Model Predict Block
Classify images using PyTorch Model Predict block. - Predict Responses Using TensorFlow Model Predict Block
Predict Responses Using TensorFlow Model Predict block. - Predict Responses Using ONNX Model Predict Block
Predict Responses Using ONNX Model Predict block. - Predict Responses Using PyTorch Model Predict Block
Predict Responses Using PyTorch Model Predict block. - Predict Responses Using Custom Python Model in Simulink (Statistics and Machine Learning Toolbox)
This example shows how to use the Custom Python Model Predict (Statistics and Machine Learning Toolbox) block for prediction in Simulink®. - Set Up Python Environment for Deep Learning with PyTorch Workflows
Configure Python and install PyTorch for use with MATLAB deep learning workflows.
PyTorch Coexecution in MATLAB Command Line
- Offline Training and Testing of PyTorch Model for CSI Feedback Compression (5G Toolbox)
Train an autoencoder-based PyTorch neural network offline and test for CSI compression. (Since R2025a)
Custom Layers
- Define Custom Deep Learning Layers
Learn how to define custom deep learning layers.
Related Information
- https://www.mathworks.com/matlabcentral/fileexchange/67296-deep-learning-toolbox-converter-for-onnx-model-format
- https://www.mathworks.com/matlabcentral/fileexchange/64649-deep-learning-toolbox-converter-for-tensorflow-models
- https://www.mathworks.com/matlabcentral/fileexchange/111925-deep-learning-toolbox-converter-for-pytorch-models
- https://www.mathworks.com/matlabcentral/fileexchange/61735-deep-learning-toolbox-importer-for-caffe-models
