Main Content

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.

Deep Network Designer app

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

expand all

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

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

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 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") opens the legacy (before R2024a) version of the app. This version supports DAGNetwork, SeriesNetwork, and LayerGraph objects. For more information, see Change in default behavior.

Version History

Introduced in R2018b

expand all