0% found this document useful (0 votes)
185 views

MATLAB With TensorFlow and PyTorch (TechSource)

This document summarizes how MATLAB is helping engineers and domain experts apply deep learning to their applications using tools like TensorFlow and PyTorch. MATLAB allows users to import models from TensorFlow and PyTorch via converters. It also enables co-execution with these frameworks so users can test models in MATLAB. Simulink can simulate larger systems that include deep learning models. MATLAB can also automatically generate embedded code for models to run on devices.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
185 views

MATLAB With TensorFlow and PyTorch (TechSource)

This document summarizes how MATLAB is helping engineers and domain experts apply deep learning to their applications using tools like TensorFlow and PyTorch. MATLAB allows users to import models from TensorFlow and PyTorch via converters. It also enables co-execution with these frameworks so users can test models in MATLAB. Simulink can simulate larger systems that include deep learning models. MATLAB can also automatically generate embedded code for models to run on devices.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

© 2022 The MathWorks, Inc.

1
Questions MATLAB users are asking about deep learning…

Our engineers aren’t deep learning experts, they’re domain experts.


How can they apply deep learning to their applications?
—Government Department

Our data scientists use TensorFlow & PyTorch, Our engineers


use MATLAB. How can our teams work together?
—Automotive OEM

How can I simulate my model within a larger system?


—Aerospace Contractor

How can I run my model onto an embedded device?


—Electronics OEM

2
How MATLAB (and Simulink) is answering these questions…

MATLAB has 100s of examples of deep learning being used in


domain-specific applications

MATLAB works with TensorFlow and PyTorch

Simulink can simulate larger systems that include Deep Learning

MATLAB coders can automatically generate embedded


code for deep learning on CPU, GPU or FPGA’s

3
The focus of today’s session is to show how:

MATLAB has 100s of examples of deep learning being used in


domain-specific applications

MATLAB works with TensorFlow and PyTorch

Simulink can simulate larger systems that include Deep Learning

MATLAB coders can automatically generate embedded


code for deep learning on CPU, GPU or FPGA’s

4
There are two ways MATLAB can work with TensorFlow and
PyTorch

▪ Converting TensorFlow & PyTorch models into MATLAB

▪ Co-executing TensorFlow & PyTorch with MATLAB

5
Converting TensorFlow & PyTorch models into MATLAB

6
Interoperability is part of the AI System Design Workflow

Data Preparation AI Modeling Simulation & Test Deployment

Data cleansing and Model design and Integration with


Embedded devices
preparation tuning complex systems

Hardware
Human insight System simulation Enterprise systems
accelerated training

Simulation- System verification Edge, cloud,


Interoperability
generated data and validation desktop

7 7
Interoperability is part of the AI System Design Workflow

Data Preparation AI Modeling Simulation & Test Deployment

Data cleansing and Model design and Integration with


Embedded devices
preparation tuning complex systems

Hardware
Human insight System simulation Enterprise systems
accelerated training

Simulation- System verification Edge, cloud,


Interoperability
generated data and validation desktop

8 8
MATLAB has model converters for TensorFlow, PyTorch and
ONNX

• Once a model is converted in MATLAB, the rest of


the AI system design workflow is available:

9
Mitsui Chemicals Deploys AI and Automation Systems with TensorFlow
and MATLAB

Challenge
Automate visual inspection of sheet-shaped products and
ensure ease of use and maintenance of the deployed
model
Solution
Import the trained TensorFlow-Keras model into MATLAB
using an importer, create a user interface, and deploy it in Model development with Python (TensorFlow-Keras)
the field as an application and efficient onsite implementation of models with
MATLAB.

Key Outcomes
▪ Reduced visual inspection time by 80%
“MATLAB solved our problems on the field
▪ Effectively used models trained in other frameworks implementation and saved development time. That
▪ Deployed application with a user interface that anyone led to highly accurate development.”
can use - Shintaro Maekawa, Mitsui Chemicals, Inc.

Link to case study 10


Before converting, save time and check if the model exists in the
MATLAB Deep Learning Model Hub

• Over 50 popular pretrained models

https://github.com/matlab-deep-learning/MATLAB-Deep-Learning-Model-Hub 11
The TensorFlow model converter can import and export
networks to and from MATLAB
There are two examples to highlight:

▪ Example 1 - Import a TensorFlow model into MATLAB

>> importTensorFlowNetwork

▪ Example 2 – Export a network from MATLAB to TensorFlow*

>> exportNetworkToTensorflow

* Export released in

DEMO 1 Deep Learning Toolbox Converter for TensorFlow Models 12


The PyTorch model converter has newly been released,
support is limited to Image Classification models
More support for more networks will be added in
upcoming releases

▪ Import the model into MATLAB


>> importNetworkfromPyTorch

* Newly released in

Deep Learning Toolbox Converter for PyTorch Models 13


The ONNX model converter supports both import and
export, and is the recommended path for going to PyTorch
There are two functions to highlight:

▪ Import the model into MATLAB


>> importONNXNetwork

▪ Export the model to ONNX


>> exportONNXNetwork

Deep Learning Toolbox Converter for ONNX Model Format 14


There are challenges when using model conversion

• Not all models can be imported


• TensorFlow and PyTorch frameworks are
constantly evolving, what’s supported today might
not be supported tomorrow

15
Things you need to consider before using model conversion

• MATLAB, TensorFlow and PyTorch are Deep


Learning frameworks that are not 100% the same
• Many layers and operators do match
• Some require manual coding
• Some require features that are not yet
supported in the other frameworks

• Model conversion is a one-way trip


• Roundtripping isn’t supported.

16
Co-executing TensorFlow & PyTorch with MATLAB

17
Co-execution allows:

▪ Calling Python from MATLAB to access any AI frameworks and networks


▪ Calling MATLAB from Python to reuse the domain specific processing

Calling Python from MATLAB Calling MATLAB from Python

Python Interface MATLAB Engine

18
1. Co-execution with MATLAB, TensorFlow or PyTorch

• Allows testing of any model from TensorFlow / PyTorch in MATLAB


• Requires MATLAB and TensorFlow / PyTorch
• Requires datatype conversion / reformatting

19
MATLAB + TensorFlow co-execution

There are options to highlight:

▪ Run Python code using a Live Task

▪ Call the Python engine from the MATLAB


command line

DEMO 2
20
But there are challenges with co-execution

• Performance is impacted by data transfer between frameworks


• Codegeneration is not supported* (*Except TFLite)

21
Support for TensorFlow Lite
In both MATLAB and Simulink, for simulation and deployment

▪ TFLite is an open source deep Simulation Code Generation


learning framework for on-device Application logic executing in Application logic as
MATLAB/Simulink generated C++ code
inference
▪ Simulate and deploy using Application
logic
Application
logic
pretrained models from TFLite

DL network executing in TFLite DL network executing in TFLite

Deep Learning Toolbox Interface for TensorFlow Lite 22


22
There are more co-execution examples on GitHub

▪ Hyperparameter Tuning in MATLAB using Experiment Manager & TensorFlow

▪ Automate Labeling in Image Labeler using a Pretrained TensorFlow Object Detector

▪ Use a Python Speech Command Recognition System in MATLAB

23
Comparison of Models accessible in MATLAB

24
Links for getting started

▪ Model Conversion
– Deep Learning Import and Export

▪ Co-execution
– Image Classification in MATLAB Using TensorFlow

25
26
© 2022 The MathWorks, Inc.
27
MORE THAN 54 COURSES

BASIC, ADVANCED &


CUSTOMIZED COURSES

TAUGHT BY EXPERTS

CERTIFICATE OF
COMPLETION
For more info, visit https://www.techsource-asia.com/training-calendar/
28
29
30
31
32

You might also like