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:

Deep Network Designer app

Open the Deep Network Designer App

Examples

expand all

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.

featureInputLayer connected to a fullyConnectedLayer

Add a layerNormalizationLayer followed by a reluLayer to the canvas and connect them sequentially.

A series of layers connected sequentially. The order of the layers is featureInputLayer, fullyConnectedLayer, layerNormalizationLayer, and reluLayer.

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.

A series of layers connected sequentially. The order of the layers is featureInputLayer, fullyConnectedLayer, layerNormalizationLayer, reluLayer, fullyConnectedLayer, and softmaxLayer,

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.

Deep Learning Network Analyzer report view. The top shows the number of learnables, layers, warnings, and errors. The left shows a plot of the network and the right shows a table with information about each layer.

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.

Deep Network Designer start page with a selection of pretrained networks, such as SqueezeNet, GoogLeNet, and ResNet-50.

For this example, pause on SqueezeNet and click Open.

Deep Network Designer canvas. On the left is the Layer Library with a list of supported layers. In the middle is the network and on the right are the network properties.

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'.

Before R2023b: To edit the layer properties for a new task, you must replace the layers instead of unlocking them.

Properties of a convolution2dLayer. The NumFilters property is set to 5, and the WeightLearnRateFactor and BiasLearnRateFactor properties are set to 10.

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™.

Tiles from the Deep Network Designer start page. The tiels show "Blank Network", "From Workspace", "From PyTorch", and "From 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.

Import PyTorch Model dialog box. In the dialog box, you can specify the location of the traced model file. The dialog box displays a note saying that the software might save custom layers to the current folder.

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.

Generated import report showing one warning. The warning states that an imageInputLayer has been automatically added by the software and the InputSize property must be edited before using the network.

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:

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.

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.

Programmatic Use

expand all

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

expand all

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:

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:

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:

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.

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.