Deep Learning in MATLAB – MATLAB & Simulink
Mục Lục
Deep Learning in
MATLAB
What Is Deep Learning?
Deep learning is a branch of machine learning that teaches
computers to do what comes naturally to humans: learn from experience. Deep learning
uses neural networks to learn useful representations of features directly from data.
Neural networks combine multiple nonlinear processing layers, using simple elements
operating in parallel and inspired by biological nervous systems. Deep learning models
can achieve state-of-the-art accuracy in object classification, sometimes exceeding
human-level performance.
Deep Learning Toolbox™ provides simple MATLAB® commands for creating and interconnecting the layers of a deep neural
network. Examples and pretrained networks make it easy to use MATLAB for deep learning, even without knowledge of advanced computer vision
algorithms or neural networks.
For a free hands-on introduction to practical deep learning methods, see Deep Learning Onramp. To quickly get started deep learning, see Try Deep Learning in 10 Lines of MATLAB Code.
Start Deep Learning Faster Using Transfer Learning
Transfer learning is commonly used in deep learning applications. You can take a
pretrained network and use it as a starting point to learn a new task. Fine-tuning a
network with transfer learning is much faster and easier than training from scratch. You
can quickly make the network learn a new task using a smaller number of training images.
The advantage of transfer learning is that the pretrained network has already learned a
rich set of features that can be applied to a wide range of other similar tasks. For an
interactive example, see Transfer Learning with Deep Network Designer. For a programmatic
example, see Train Deep Learning Network to Classify New Images.
To choose whether to use a pretrained network or create a new deep network, consider
the scenarios in this table.
Use a Pretrained Network for Transfer
LearningCreate a New Deep NetworkTraining DataHundreds to thousands of labeled data (small)Thousands to millions of labeled dataComputationModerate computation (GPU optional)Compute intensive (requires GPU for speed)Training TimeSeconds to minutesDays to weeks for real problemsModel AccuracyGood, depends on the pretrained modelHigh, but can overfit to small data sets
To explore a selection of pretrained networks, use Deep Network
Designer.
Train Classifiers Using Features Extracted from Pretrained Networks
Feature extraction allows you to use the power of pretrained networks without
investing time and effort into training. Feature extraction can be the fastest way to
use deep learning. You extract learned features from a pretrained network, and use those
features to train a classifier, for example, a support vector machine (SVM — requires
Statistics and Machine Learning Toolbox™). For example, if an SVM trained using alexnet
can
achieve >90% accuracy on your training and validation set, then fine-tuning with
transfer learning might not be worth the effort to gain some extra accuracy. If you
perform fine-tuning on a small dataset, then you also risk overfitting. If the SVM
cannot achieve good enough accuracy for your application, then fine-tuning is worth the
effort to seek higher accuracy.
For an example, see Extract Image Features Using Pretrained Network.
Deep Learning with Big Data on CPUs, GPUs, in Parallel, and on the Cloud
Training deep networks is computationally intensive and can take many hours of
computing time; however, neural networks are inherently parallel algorithms. You can use
Parallel Computing Toolbox™ to take advantage of this parallelism by running in parallel using
high-performance GPUs and computer clusters. To learn more about deep learning in
parallel, in the cloud, or using a GPU, see Scale Up Deep Learning in Parallel, on GPUs, and in the Cloud.
Datastores in MATLAB® are a convenient way of working with
and representing collections of data that are too large to fit in memory at one time. To
learn more about deep learning with large data sets, see Deep Learning with Big Data.
Deep Learning Using Simulink
Implement deep learning functionality in Simulink® models
by using blocks from the Deep Neural Networks block library, included in the Deep
Learning Toolbox™, or by using the Deep Learning Object Detector block from the Analysis
& Enhancement block library included in the Computer Vision Toolbox™.
For more information, see Deep Learning with Simulink.
BlockDescription
Image Classifier
Classify data using a trained deep learning neural
network
Predict
Predict responses using a trained deep learning neural
network
Stateful Classify
Classify data using a trained deep learning recurrent neural
network
Stateful Predict
Predict responses using a trained recurrent neural
network
Deep Learning Object Detector (Computer Vision Toolbox)
Detect objects using trained deep learning object
detector
Deep Learning Interpretability
Deep learning networks are often described as “black boxes” because the reason that a
network makes a certain decision is not always obvious. You can use interpretability
techniques to translate network behavior into output that a person can interpret. This
interpretable output can then answer questions about the predictions of a
network.
The Deep Learning Toolbox provides several deep learning visualization methods to help
you investigate and understand network behaviour. For example, gradCAM
,
occlusionSensitivity
, and imageLIME
.
For more information, see Deep Learning Visualization Methods.
Deep Learning Import and Export
You can import networks and layer graphs from TensorFlow™ 2, TensorFlow-Keras, PyTorch®, and the ONNX™ (Open Neural Network Exchange) model format. You can also export Deep Learning Toolbox networks and layer graphs to TensorFlow 2 and the ONNX model format.
Import Functions
External Deep Learning Platform and Model FormatImport Model as NetworkImport Model as Layer GraphTensorFlow network in SavedModel
formatimportTensorFlowNetwork
importTensorFlowLayers
TensorFlow-Keras network in HDF5 or JSON formatimportKerasNetwork
importKerasLayers
traced PyTorch model in .pt
fileimportNetworkFromPyTorch
Not applicableNetwork in ONNX model formatimportONNXNetwork
importONNXLayers
The importTensorFlowNetwork
and
importTensorFlowLayers
functions are recommended over the
importKerasNetwork
and importKerasLayers
functions. For more information, see Recommended Functions to Import TensorFlow Models.
The importTensorFlowNetwork
,
importTensorFlowLayers
,
importNetworkFromPyTorch
, importONNXNetwork
,
and importONNXLayers
functions create automatically generated custom
layers when you import a model with TensorFlow layers, PyTorch layers, or ONNX operators that the functions cannot convert to built-in MATLAB layers. The functions save the automatically generated custom layers to a
package in the current folder. For more information, see Autogenerated Custom Layers.
Export Functions
Export Network or Layer GraphExternal Deep Learning Platform and Model FormatexportNetworkToTensorFlow
TensorFlow 2 model in Python® packageexportONNXNetwork
ONNX model format
The exportNetworkToTensorFlow
function saves a Deep Learning Toolbox network or layer graph as a TensorFlow model in a Python package. For more information on how to load the exported model and save it in
a standard TensorFlow format, see Load Exported TensorFlow Model and Save Exported TensorFlow Model in Standard Format.
By using ONNX as an intermediate format, you can interoperate with other deep learning
frameworks that support ONNX model export or import.