Main Content

Deep Network Designer

Design, visualize, and train deep learning networks

Since R2018b

Description

The Deep Network Designer app lets you build, visualize, edit, and train deep learning networks. Using this app, you can:

  • Build, import, edit, and combine networks.

  • Load pretrained networks and edit them for transfer learning.

  • View and edit layer properties and add new layers and connections.

  • Analyze the network to ensure that the network architecture is defined correctly, and detect problems before training.

  • Import and visualize datastores and image data for training and validation.

  • Apply augmentations to image classification training data and visualize the distribution of the class labels.

  • Train networks and monitor training with plots of accuracy, loss, and validation metrics.

  • Export trained networks to the workspace or to Simulink®.

  • Generate MATLAB® code for building and training networks and create experiments for hyperparameter tuning using Experiment Manager.

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

Examine a pretrained network in Deep Network Designer.

Open the app and select a pretrained network. You can also load a pretrained network by selecting the Designer tab and clicking New. If you need to download the network, then click Install to open the Add-On Explorer. Deep Network Designer has pretrained networks suitable for image and audio tasks. Loading pretrained audio networks requires Audio Toolbox™.

Tip

To get started, try choosing one of the faster image classification networks, such as SqueezeNet or GoogLeNet. Once you gain an understanding of which settings work well, try a more accurate network, such as Inception-v3 or a ResNet, and see if that improves your results. For more information on selecting a pretrained network, see Pretrained Deep Neural Networks.

Deep Network Designer start page showing available networks

In the Designer pane, visualize and explore the network. For a list of available pretrained image classification networks and how to compare them, see Pretrained Deep Neural Networks.

Deep Network Designer displaying a pretrained image classification network

For information on constructing networks using Deep Network Designer, see Build Networks with Deep Network Designer.

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.

Open Deep Network Designer with SqueezeNet.

deepNetworkDesigner(squeezenet)

To prepare the network for transfer learning, replace the last learnable layer and the final classification layer. For SqueezeNet, the last learnable layer is a 2-D convolutional layer named 'conv10'.

  • Drag a new convolution2dLayer onto the canvas. Set the FilterSize property to 1,1 and 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.

  • Delete the last convolution2dLayer and connect your new layer instead.

    Convolution 2-D layer selected in Deep Network Designer. FilterSize is set to 1,1 and NumFilters is set to 5.

Tip

For most pretrained networks (for example, GoogLeNet) the last learnable layer is the fully connected layer. To prepare the network for transfer learning, replace the fully connected layer with a new fully connected layer and set the OutputSize property to the new number of classes. For an example, see Get Started with Deep Network Designer.

Next, delete the classification output layer. Then, drag a new classificationLayer onto the canvas and connect it instead. The default settings for the output layer mean the network learns the number of classes during training.

Classification layer selected in Deep Network Designer. OutputSize is set to auto.

Check your network by clicking Analyze in the Designer tab. The network is ready for training if Deep Learning Network Analyzer reports zero errors. For an example showing how to train a network to classify new images, see Transfer Learning with Deep Network Designer.

For help understanding and editing layer properties, click the help icon next to the layer name.

On the Designer pane, select a layer to view and edit the properties. Click the help icon next to the layer name for more information about the properties of the layer.

Cross channel normalization layer selected in Deep Network Designer

For more information about layer properties, see List of Deep Learning Layers.

Add layers from the workspace to a network in Deep Network Designer.

In Deep Network Designer, you can build a network by dragging built-in layers from the Layer Library to the Designer pane and connecting them. You can also add custom layers from the workspace to a network in the Designer pane. Suppose that you have a custom layer stored in the variable myCustomLayer.

  1. Click New in the Designer tab.

  2. Pause on From Workspace and click Import.

  3. Select myCustomLayer and click OK.

  4. Click Add.

The app adds the custom layer to the top of the Designer pane. To see the new layer, zoom-in using a mouse or click Zoom in.

Connect myCustomLayer to the network in the Designer pane. For an example showing how build a network with a custom layer in Deep Network Designer, see Import Custom Layer into Deep Network Designer.

You can also combine networks in Deep Network Designer. For example, you can create a semantic segmentation network by combining a pretrained network with a decoder subnetwork.

To view or edit the custom layer class definition, select the layer, and then click Edit Layer Code. For more information, see View Autogenerated Custom Layers Using Deep Network Designer. (since R2023a)

Import data into Deep Network Designer for training.

You can use the Data tab of Deep Network Designer to import training and validation data. Deep Network Designer supports the import of image data and datastore objects. Select an import method based on the type of task.

TaskData TypeData Import MethodExample Visualization
Image classification

ImageDatastore object, or a folder with subfolders containing images for each class. The class labels are sourced from the subfolder names.

Select Import Data > Import Image Classification Data.

Import Image Data dialog box

You can select augmentation options and specify the validation data in the Import Image Data dialog box. For more information, see Import Data into Deep Network Designer.

Data tab of Deep Network Designer displaying a histogram of the class labels and a selection of random images from the imported data

Other extended workflows (such as numeric feature input, out-of-memory data, image processing, and audio and speech processing)

Datastore.

For other extended workflows, use a suitable datastore object. For example, AugmentedImageDatastore, CombinedDatastore, pixelLabelImageDatastore (Computer Vision Toolbox), audioDatastore (Audio Toolbox), or custom datastore.

You can import and train any datastore object that works with the trainNetwork function. For more information about constructing and using datastore objects for deep learning applications, see Datastores for Deep Learning.

Select Import Data > Import Custom Data.

Import Datastore dialog box

You can specify the validation data in the Import Custom Data dialog box. For more information, see Import Data into Deep Network Designer.

Data tab of Deep Network Designer displaying a preview of the first five observations in the datastore

Train deep neural networks using Deep Network Designer.

Using Deep Network Designer, you can train a network using image data or any datastore object that works with the trainNetwork function. For example, you can train a semantic segmentation network or a multi-input network using a CombinedDatastore object. For more information about importing data into Deep Network Designer, see Import Data into Deep Network Designer.

To train a network on data imported into Deep Network Designer, on the Training tab, click Train. The app displays an animated plot of the training progress. The plot shows mini-batch loss and accuracy, validation loss and accuracy, and additional information on the training progress. The plot has a stop button in the top-right corner. Click the button to stop training and return the current state of the network.

Training progress plot in Deep Network Designer

For more information, see Train Networks Using Deep Network Designer.

If you require greater control over the training, click Training Options to select the training settings. For more information about selecting training options, see trainingOptions.

Training Options dialog box in Deep Network Designer

For an example showing how to train an image classification network, see Transfer Learning with Deep Network Designer. For an example showing how to train a sequence-to-sequence LSTM network, see Train Network for Time Series Forecasting Using Deep Network Designer.

To train a network on data not supported by Deep Network Designer, select the Designer tab, and click Export to export the initial network architecture. You can then programmatically train the network, for example, using a custom training loop.

Export the network architecture created in Deep Network Designer to the workspace or Simulink and generate code to recreate the network and training.

  • To export the network architecture with the initial weights to the workspace, on the Designer tab, click Export. Depending on the network architecture, Deep Network Designer exports the network as a LayerGraph lgraph or as a Layer object layers.

  • To export the network trained in Deep Network Designer to the workspace, on the Training tab, click Export. Deep Network Designer exports the trained network architecture as a DAGNetwork object trainedNetwork. Deep Network Designer also exports the results from training, such as training and validation accuracy, as the structure array trainInfoStruct.

  • To export the network trained in Deep Network Designer to Simulink, on the Training tab, click Export > Export to Simulink. Deep Network Designer saves the trained network as a MAT-file and generates Simulink blocks representing the trained network. The blocks generated depend on the type of network trained.

    • 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 recurrent neural network.

    • Stateful Predict — Predict responses using a trained recurrent neural network.

For an example showing how to export a network from Deep Network Designer to Simulink, see Export Image Classification Network from Deep Network Designer to Simulink.

To recreate a network that you construct and train in Deep Network Designer, generate MATLAB code.

  • To recreate the network layers, on the Designer tab, select Export > Generate Code.

  • To recreate the network layers, including any learnable parameters, on the Designer tab, select Export > Generate Code with Initial Parameters.

  • To recreate the network, data import, and training, on the Training tab, select Export > Generate Code for Training.

After generating a script, you can perform the following tasks.

  • To recreate the network layers created in the app, run the script. If you generated the training script, running the script will also replicate the network training.

  • Examine the code to learn how to create and connect layers programmatically, and how to train a deep network.

  • To modify the layers, edit the code. You can also run the script and import the network back into the app for editing.

For more information, see Generate MATLAB Code from Deep Network Designer.

You can also use Deep Network Designer to create deep learning experiments which sweep through a range of hyperparameter values or use Bayesian optimization to find optimal training options. For an example showing how to use Experiment Manager to tune the hyperparameters of a network trained in Deep Network Designer, see Generate Experiment Using 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 a series network, DAG network, layer graph, or an array of layers.

For example, open Deep Network Designer with a pretrained SqueezeNet network.

net = squeezenet;
deepNetworkDesigner(net);

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.

Tips

To train multiple networks and compare the results, try Experiment Manager. You can use Deep Network Designer to create experiments suitable for Experiment Manager.

Version History

Introduced in R2018b