Deep Network Designer - Design and visualize deep learning networks - MATLAB (original) (raw)
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.
- Analyze networks for memory reduction using compression techniques.
- Export networks to Simulink®.
- Generate MATLAB® code for building networks.
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
Create a classification network for numeric feature data.
Open Deep Network Designer.
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 Network Code Without Parameters.
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.
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 Network Code.
For an example showing how to train a network to classify new images, see Prepare Network for Transfer Learning Using Deep Network Designer.
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");
modelfile = 'C:\Users\jwelding\OneDrive - MathWorks\Documents\MATLAB\Examples\R2025a\supportfiles\nnet\data\PyTorchModels\mnasnet1_0.pt'
To import a network from an external platform, use Deep Network Designer.
You can import models from PyTorch® or TensorFlow™.
For PyTorch® models, click 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 a trained network from Deep Network Designer to Simulink®.
Open Deep Network Designer.
The app has two types of Simulink export:
- Export to a single network block, for example, a Predict block
- Export to multiple layer blocks
For small networks with all layers supported as layer blocks, exporting to layer blocks is recommended. For large networks or networks with layers not supported as layer blocks, exporting to a single network block is recommended. If your network has layers that are not supported as layer blocks, then you will see a warning.
Export as Layer Blocks
For this example, pause on LSTM and click Open. To export the network to Simulink, select Export > Export to Simulink. In the Export to Simulink dialog, select Export as to be Multiple Layer Blocks. Select a location to save the Simulink file with the network parameters and then click Export. During export, if the network is not initialized, then the app attempts to initialize it.
The app creates a Simulink model.
Click inside my_model_1
to see the individual layer blocks.
For a list of layers supported as layer blocks, see List of Deep Learning Layer Blocks and Subsystems.
**Export as Network Block
You can also export your model as a single network block. In Deep Network Designer, select Export as to be Single Network Block. In this example, the app exports the network as a Stateful Predict
block.
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. 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
- Prepare Network for Transfer Learning Using Deep Network Designer
- Build Networks with Deep Network Designer
- Import PyTorch Model Using Deep Network Designer
- Build Time Series Forecasting Network Using Deep Network Designer
- Profile Deep Learning Network for Deployment
Programmatic Use
deepNetworkDesigner
opens the Deep Network Designer app. If Deep Network Designer is already open, deepNetworkDesigner
brings focus to the app.
deepNetworkDesigner(`net`)
opens the Deep Network Designer app and loads the specified network into the app. The network can be an array of layers or a dlnetwork
object. If you import aDAGNetwork
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"`)
opens the legacy (before R2024a) version of the app. This version supportsDAGNetwork
, SeriesNetwork
, andLayerGraph
objects. For more information, see Change in default behavior.
Version History
Introduced in R2018b
Use Deep Network Designer to view inside nested layers. For example, you can now view inside NetworkLayer objects. Nested layers are common when importing networks from external platforms such as PyTorch and TensorFlow. To view inside a nested layer, double-click on the layer. For an example showing how to build, visualize, and train networks with nested layers, see Create and Train Network with Nested Layers.
Starting in R2025a, by default, Deep Network Designer represents PyTorch and TensorFlow network composition using NetworkLayer objects. Before R2025a, the app represents network composition using nested custom layers.
Use Deep Network Designer to export deep neural networks to Simulink layer blocks. The app returns a Simulink model that contains blocks corresponding to the layers in your network. For more information about supported layers, see List of Deep Learning Layer Blocks and Subsystems.
Starting in R2025a, when exporting a network to Simulink, the app chooses the default behavior based on your network architecture. If all the layers are supported as layer blocks, then the default export type is layer blocks. Otherwise, the default export type is to network blocks such as the Predict or Stateful Predict blocks.
Starting in R2025a, information about quantization is included in the report from theAnalyze for Compression option.
The compression analysis report now contains:
- Maximum possible memory reduction by quantization
- Quantization support for layers of your network
For more information about neural network compression techniques, see Reduce Memory Footprint of Deep Neural Networks.
Deep Network Designer now includes several features that enhance the user experience when using the app:
- Use keyboard shortcuts to confirm or dismiss dialog boxes.
- Specify the export name of your network.
- View network analysis information directly within the app.
The Deep Network Designer Start Page now has a template for a multilayer perceptron (MLP) neural network. You can use this template to quickly create MLP networks suitable for feature classification tasks.
You can now use Deep Network Designer to analyze the compressibility of neural networks. For example, you can check the maximum memory reduction of your network layers using Taylor pruning or projection.
Open your network in Deep Network Designer. Then, click Analyze for Compression.
The compression analysis report contains information about:
- Maximum possible memory reduction
- Pruning and projection support
- Effect of the network architecture on the ability to prune individual layers
- Layer memory
The Deep Network Designer Start Page now has templates for 1-D convolutional neural networks. You can use the templates to quickly create 1-D convolutional neural networks suitable for sequence-to-label and sequence-to-sequence classification tasks.
Starting in R2024a, Deep Network Designer creates dlnetwork
objects by default. If you import a DAGNetwork
orSeriesNetwork
object, then the app attempts to convert the network into adlnetwork
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 ofDAGNetwork
, SeriesNetwork
, orLayerGraph
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 supports
dlnetwork
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 DAGNetwork, SeriesNetwork, andLayerGraph objects, you can: Import pretrained networks.Build networks from scratch.Analyze networks for issues.Train networks.Export networks trained in Deep Network Designer to Simulink.Generate MATLAB code for building and training networks.Create experiments for networks trained in Deep Network Designer. | In Deep Network Designer from R2024a onward, when you work withdlnetwork objects, you can: Import networks from PyTorch and TensorFlow.Import pretrained networks.Build networks from scratch.Analyze networks for issues.Export networks to Simulink.Generate MATLAB code for building networks. |