Deep Network Designer
Design and visualize deep learning networks
Description
The Deep Network Designer app lets you import, build, visualize, and edit deep learning networks. Using this app, you can:
Build, edit, and combine networks.
Load pretrained networks and edit them for transfer learning.
Import networks from PyTorch® and TensorFlow™.
Analyze networks to ensure that the architecture is defined correctly.
Export networks to Simulink®.
Generate MATLAB® code for building networks.
![](https://www.mathworks.com/help/deeplearning/ref/app_deep_editor.png)
Open the Deep Network Designer App
MATLAB Toolstrip: On the Apps tab, under Machine Learning and Deep Learning, click the app icon.
MATLAB command prompt: Enter
deepNetworkDesigner
.
Examples
Build Deep Neural Network
Create a classification network for numeric feature data.
Open Deep Network Designer.
deepNetworkDesigner
To create a blank network, pause on Blank Network and click New. The app opens a blank canvas where you can drag and drop layers.
From the Layer Library, drag a featureInputLayer
onto the canvas. You can use the Layer Library filter to help you find layers. Select the layer. In the Properties pane, set Normalization
to "zscore"
and InputSize
to the number of features in your data. Next, drag a fullyConnectedLayer
onto the canvas. To connect the layers, pause on the featureInputLayer
and click the out
port. Drag the arrow to the in
port of the fullyConnectedLayer
.
Add a layerNormalizationLayer
followed by a reluLayer
to the canvas and connect them sequentially.
Finally, add a fullyConnectedLayer
followed by a softmaxLayer
and connect them. For the last fullyConnectedLayer
, select the layer and set the OutputSize
to the number of classes in your data.
To automatically align the layers, click Auto Arrange.
To check that the network is ready for training, select Analyze. The Deep Learning Network Analyzer shows that the network has zero warnings or errors.
To export the network to the workspace, click Export. To generate code to recreate the network, click Export > Generate Code without Initial Parameters.
Prepare Pretrained Network for Transfer Learning
Prepare a network for transfer learning by editing it in Deep Network Designer.
Transfer learning is the process of taking a pretrained deep learning network and fine-tuning it to learn a new task. You can quickly transfer learned features to a new task using a smaller number of training images. Transfer learning is therefore often faster and easier than training a network from scratch. To use a pretrained network for transfer learning, you must change the number of classes to match your new data set.
Deep Network Designer provides a selection of pretrained image and audio networks. To explore the pretrained networks, open Deep Network Designer.
deepNetworkDesigner
For this example, pause on SqueezeNet and click Open.
To prepare the network for transfer learning, edit the last learnable layer. For SqueezeNet, the last learnable layer is the 2-D convolutional layer 'conv10'
.
Select the
'conv10'
layer. At the bottom of the Properties pane, click Unlock Layer. Unlocking the layer deletes all of the layer learnables. In the warning dialog that appears, click Unlock Anyway. Doing so unlocks the layer properties so that you can adapt them to your new task. Set the NumFilters property to the new number of classes.Change the learning rates so that learning is faster in the new layer than in the transferred layers by increasing the WeightLearnRateFactor and BiasLearnRateFactor values to 10.
Before R2023b: To edit the layer properties for a new task, you must replace the layers instead of unlocking them.
Check your network by clicking Analyze. The network is ready for training if Deep Learning Network Analyzer reports zero errors. To export the prepared network to the workspace, click Export. To generate MATLAB code to create the network, click Generate Code with Initial Parameters.
For an example showing how to train a network to classify new images, see Prepare Network for Transfer Learning Using Deep Network Designer.
Import Network from External Platform
Import a neural network from PyTorch® or TensorFlow™.
For this example, import the MNASNet (Copyright© Soumith Chintala 2016) PyTorch model. Download the mnasnet1_0
file, which is approximately 17 MB in size, from the MathWorks website.
modelfile = matlab.internal.examples.downloadSupportFile("nnet", ... "data/PyTorchModels/mnasnet1_0.pt");
To import a network from an external platform, use Deep Network Designer.
deepNetworkDesigner
You can import models from PyTorch® or TensorFlow™.
For PyTorch® models, the From PyTorch icon. In the Import PyTorch Model dialog box, copy the location of the model file and then click Import.
When importing PyTorch networks using Deep Network Designer, you have the option to specify the input sizes of the network. This option is only available when specifying the input sizes might make the import more successful, for example, by reducing the number of custom layers.
The app imports the network and generates an Import Report. The Import Report displays any issues with the network that require attention before you use the network for training or inference. For example, the report shows a warning if the app is unable to infer the input sizes or if you need to complete any placeholder layers.
For an example that shows how to import a PyTorch® network into Deep Network Designer and fix any issues, see Import PyTorch® Model Using Deep Network Designer.
Export Network to Simulink
Export a trained network from Deep Network Designer to Simulink®.
Open Deep Network Designer.
deepNetworkDesigner
Pause on SqueezeNet and click Open. To export the network to Simulink, select Export > Export to Simulink. In the Export to Simulink dialog, select a location to save the MAT file with the network parameters and then select Export. During export, if the network is not initialized, then the app attempts to initialize it.
The blocks generated by the app depend on the type of network.
Predict — Predict responses using a trained deep learning neural network.
Stateful Predict — Predict responses using a trained recurrent neural network.
For SqueezeNet, the app generates a Predict block.
Generate MATLAB Code for Network Architecture
The Deep Network Designer app enables you to generate MATLAB® code that recreates the network architecture.
To recreate the layers in your network, including any initial parameters, select Export > Generate Network Code With Parameters. The app creates a live script and a MAT file containing the initial parameters (weights and biases) from your network. Run the script to recreate the network layers, including the learnable parameters from the MAT file. Use this option to preserve the weights if you want to perform transfer learning.
To recreate only the layers in your network, select Export > Generate Network Code Without Parameters. This network does not contain initial parameters, such as pretrained weights.
Running the generated script returns the network architecture as a dlnetwork
object. For an example of training a network exported from Deep Network Designer, see Get Started with Deep Network Designer. To learn more about generating code, see Generate MATLAB Code from Deep Network Designer.
Related Examples
Programmatic Use
deepNetworkDesigner
deepNetworkDesigner
opens the Deep Network Designer app.
If Deep Network Designer is already open, deepNetworkDesigner
brings focus to the app.
deepNetworkDesigner(net
)
net
)deepNetworkDesigner(
opens the Deep
Network Designer app and loads the specified network into the app. The network can
be an array of layers or a net
)dlnetwork
object. If you import a
DAGNetwork
or SeriesNetwork
object, then the app
attempts to convert the network into a dlnetwork
object. For more
information, see dag2dlnetwork
. If
you import a LayerGraph
object, then the app to attempts to convert it into
a dlnetwork
object.
If Deep Network Designer is already open,
deepNetworkDesigner(net)
brings focus to the app and prompts you to add
to or replace any existing network.
deepNetworkDesigner(___,"-v1"
)
"-v1"
)deepNetworkDesigner(___,
opens the legacy (before R2024a) version of the app. This version supports
"-v1"
)DAGNetwork
, SeriesNetwork
, and
LayerGraph
objects. For more information, see Change in default behavior.
Version History
Introduced in R2018bR2024a: Change in default behavior
Starting in R2024a, Deep Network Designer creates dlnetwork
objects by default. If you import a DAGNetwork
or
SeriesNetwork
object, then the app attempts to convert the network into a
dlnetwork
object. For more information, see dag2dlnetwork
. If
you import a LayerGraph
object, then the app to attempts to convert it into
a dlnetwork
object.
dlnetwork
objects have several advantages and are recommended instead of
DAGNetwork
, SeriesNetwork
, or
LayerGraph
objects.
dlnetwork
objects are a unified data type that supports network building, prediction, built-in training, visualization, compression, verification, and custom training loops.dlnetwork
objects support a wider range of network architectures that you can create or import from external platforms.The
trainnet
function supportsdlnetwork
objects, which enables you to easily specify loss functions. You can select from built-in loss functions or specify a custom loss function.Training and prediction with
dlnetwork
objects is typically faster thanLayerGraph
andtrainNetwork
workflows.
To replicate the app behavior from before R2024a, use the "-v1"
flag.
deepNetworkDesigner("-v1") deepNetworkDesigner(net,"-v1")
Comparison of Deep Network Designer Behavior
Not Recommended | Recommended |
---|---|
In the legacy version of Deep Network Designer, when you
work with
| In Deep Network Designer from R2024a onward, when you work with
|
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)