Main Content

Build Networks with Deep Network Designer

Build and edit deep learning networks interactively using the Deep Network Designer app. Using this app, you can import networks or build a network from scratch, view and edit layer properties, combine networks, and generate code to create the network architecture. You can then train your network using Deep Network Designer, or export the network for training at the command line.

You can use Deep Network Designer for a range of network construction tasks:

Assemble a network by dragging blocks from the Layer Library and connecting them. To quickly search for layers, use the Filter layers search box in the Layer Library pane.

Designer pane of Deep Network Designer with an imageInputLayer connected to a convolution2dLayer and an unconnected reluLayer

You can add layers from the workspace to the network in the Designer pane.

  1. Click New.

  2. Pause on From Workspace and click Import.

  3. Choose the layers or network to import and click OK.

  4. Click Add to add the layers or network to the Designer pane.

You can also load pretrained networks by clicking New and selecting them from the start page.

To view and edit layer properties, select a layer. Click the help icon next to the layer name for information on the layer properties.

Properties pane displaying the properties of a crossChannelNormalizationLayer

For information on all layer properties, click the layer name in the table on the List of Deep Learning Layers page.

Once you have constructed your network, you can analyze it to check for errors. For more information, see Check Network.

Transfer Learning

Transfer learning is commonly used in deep learning applications. You can take a pretrained network and use it as a starting point to learn a new task. Fine-tuning a network with transfer learning is usually much faster and easier than training a network with randomly initialized weights from scratch. You can quickly transfer learned features to a new task using a smaller number of training images.

Deep Network Designer has a selection of pretrained networks suitable for transfer learning with image data.

Load Pretrained Network

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, pause on the network and click Install to open the Add-On Explorer.

Tip

To get started, try choosing one of the faster 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

Adapt Pretrained Network

To prepare the network for transfer learning, edit the last learnable layer and the final classification layer.

  • If the last learnable layer is a 2-D convolutional layer (for example, the 'conv10' layer in SqueezeNet):

    • Select the convolutional layer. At the bottom of the Properties pane, click Unlock Layer. This 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.

Convolution 2-D layer selected in Deep Network Designer. The Properties pane shows NumFilters set to 5.

  • If the last learnable layer is a fully connected layer (most pretrained networks, for example, GoogLeNet):

    • Select the convolutional layer. At the bottom of the Properties pane, click Unlock Layer. This unlocks the layer properties so that you can adapt them to your new task. Set the OutputSize 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.

Fully connected layer selected in Deep Network Designer. The Properties pane shows OutputSize set to 5.

Next, edit the classification output layer. In the Properties pane, select Unlock Layer. The default settings for the output layer mean it will learn the number of classes during training.

Classification layer selected in Deep Network Designer. The Properties pane shows OutputSize set to auto.

To check that the network is ready for training, on the Designer tab, click Analyze.

For an example showing how to retrain a pretrained network to classify new images, see Transfer Learning with Deep Network Designer. If you have Audio Toolbox™, you can also load pretrained networks suitable for audio tasks. For an example showing how to retrain a pretrained network to classify a new set of audio signals, see Transfer Learning with Pretrained Audio Networks in Deep Network Designer.

You can also use pretrained networks and transfer learning for regression tasks. For more information, see Convert Classification Network into Regression Network.

You can also use the app to import networks from external platforms. For more information, see Import PyTorch® Model Using Deep Network Designer.

Image Classification

You can build an image classification network using Deep Network Designer by dragging layers from the Layer Library and connecting them. You can also create the network at the command line and then import the network into Deep Network Designer.

For example, create a network to train for image classification on a data set of 28-by-28 images divided into 10 classes.

inputSize = [28 28 1];
numClasses = 10;

layers = [
    imageInputLayer(inputSize)
    convolution2dLayer(5,20)
    batchNormalizationLayer
    reluLayer
    fullyConnectedLayer(numClasses)
    softmaxLayer
    classificationLayer];

deepNetworkDesigner(layers)

Image classification network in Deep Network Designer. The network starts with an image input layer and ends with a classification layer.

To adapt this network to your own data, set the InputSize of the image input layer to match your image input size and set the OutputSize of the fully connected layer to the number of classes in your data. For more complex classification tasks, create a deeper network. For more information, see Deep Networks.

For an example showing how to create and train an image classification network, see Create Simple Image Classification Network Using Deep Network Designer.

Sequence Classification

You can use Deep Network Designer to build a sequence network from scratch, or you can use one of the prebuilt untrained networks from the start page. Open the Deep Network Designer start page. Pause on Sequence-to-Label and click Open. Doing so opens a prebuilt network suitable for sequence classification problems.

Sequence classification network in Deep Network Designer. The network starts with a sequence input layer and ends with a classification layer.

You can adapt this sequence network for training with your data. Suppose you have data with 12 features and 9 classes. To adapt this network, select sequenceInputLayer and set the InputSize to 12.

Sequence input layer selected in Deep Network Designer. The Properties pane shows InputSize set to 12.

Then, select the fullyConnectedLayer and set the OutputSize to 9, the number of classes.

Fully connected layer selected in Deep Network Designer. The Properties pane shows OutputSize set to 9.

The network is now ready to train. To train the network in Deep Network Designer, create a CombinedDatastore containing the predictors and responses. For more information, see Import Data into Deep Network Designer. For an example showing how to create a combined datastore and train a sequence-to-sequence regression network using Deep Network Designer, see Train Network for Time Series Forecasting Using Deep Network Designer. For an example showing how to export a network built in Deep Network Designer and train using command line functions, see Create Simple Sequence Classification Network Using Deep Network Designer.

Numeric Data Classification

If you have a data set of numeric features (for example, a collection of numeric data without spatial or time dimensions), then you can train a deep learning network using a feature input layer. For more information about the feature input layer, see featureInputLayer.

You can construct a suitable network using Deep Network Designer, or you can create the network at the command line and import the network into Deep Network Designer.

For example, create a network for numeric data with 10 classes, where each observation consists of 20 features.

inputSize = 20;
numClasses = 10;

layers = [
featureInputLayer(inputSize,'Normalization','zscore')
fullyConnectedLayer(50)
batchNormalizationLayer
reluLayer
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];

deepNetworkDesigner(layers)

Feature classification network in Deep Network Designer. The network starts with a feature input layer and ends with a classification layer.

To adapt this network to your own data, set the InputSize of the feature input layer to match the number of features in your data and set the OutputSize of the fully connected layer to the number of classes in your data. For more complex classification tasks, create a deeper network. For more information, see Deep Networks.

To train a network in Deep Network Designer using data in a table, you must first convert your data into a suitable datastore. For example, start by converting your table into arrays containing the predictors and responses. Then, convert the arrays into arrayDatastore objects. Finally, combine the predictor and response array datastores into a CombinedDatastore object. You can then use the combined datastore to train in Deep Network Designer. For more information, see Import Data into Deep Network Designer. You can also train with tabular data and the trainNetwork function by exporting the network to the workspace.

Convert Classification Network into Regression Network

You can convert a classification network into a regression network by replacing the final layers of the network. Conversion is useful when you want to take a pretrained classification network and retrain it for regression tasks.

For example, suppose you have a GoogLeNet pretrained network. To convert this network into a regression network with a single response, replace the final fully connected layer, the softmax layer, and the classification output layer with a fully connected layer with OutputSize set to 1 (the number of responses) and a regression layer.

Diagram of the conversion of a classification network into a regression network. The final two layers of the classification network, a softmax layer and a classification layer, are replaced by a regression layer.

If your output has multiple responses, change the OutputSize value of the fully connected layer to the number of responses.

Multiple-Input and Multiple-Output Networks

Multiple Inputs

You can define a network with multiple inputs if the network requires data from multiple sources or in different formats. For example, some networks require image data captured from multiple sensors at different resolutions.

Using Deep Network Designer, you can control the inputs and outputs of each layer. For example, to create a network with multiple image inputs, create two branches, each starting with an image input layer.

Network with multiple inputs in Deep Network Designer. The network has two image input layers and a single classification output layer.

You can train a multi-input network with the same type of input, for example, images from two difference sources, using Deep Network Designer and a datastore object.

Multiple Outputs

You can define networks with multiple outputs for tasks requiring multiple responses in different formats, for example, tasks requiring both categorical and numeric output.

Using Deep Network Designer, you can control the outputs of each layer.

The end of a network with multiple outputs. The first branch ends with a fully connected layer and a softmax layer. The second branch ends with a fully connected layer.

Deep Networks

Building large networks can be difficult, you can use Deep Network Designer to speed up construction. You can work with blocks of layers at a time. Select multiple layers, then copy and paste or delete. For example, you can use blocks of layers to create multiple copies of groups of convolution, batch normalization, and ReLU layers.

Group selection of multiple layers in Deep Network Designer.

For trained networks, copying layers also copies the weights and the biases.

You can also copy sub-networks from the workspace to connect up easily using the app. To import a network or layers into the app, click New > Import from workspace. Click Add to add the layers to the current network.

Advanced Deep Learning Applications

You can use Deep Network Designer to build and train networks for advanced applications, such as computer vision or image processing tasks.

Create Semantic Segmentation Network

Semantic segmentation describes the process of associating each pixel of an image with a class label. Applications for semantic segmentation include road segmentation for autonomous driving and cancer cell segmentation for medical diagnosis.

Create a semantic segmentation network by dragging layers from the Layer Library to the Designer pane or creating the network at the command-line and importing the network into Deep Network Designer.

For example, create a simple semantic segmentation network based on a downsampling and upsampling design.

inputSize = [32 32 1];

layers = [
    imageInputLayer(inputSize)
    convolution2dLayer([3,3],64,'Padding',[1,1,1,1])
    reluLayer
    maxPooling2dLayer([2,2],'Stride',[2,2])
    convolution2dLayer([3,3],64,'Padding',[1,1,1,1])
    reluLayer
    transposedConv2dLayer([4,4],64,'Stride',[2,2],'Cropping',[1,1,1,1])
    convolution2dLayer([1,1],2)
    softmaxLayer
    pixelClassificationLayer
    ];

deepNetworkDesigner(layers) 

Semantic segmentation network in Deep Network Designer. The network starts with an image input layer and ends with a pixel classification layer.

For more information on constructing and training a semantic segmentation network, see Train Simple Semantic Segmentation Network in Deep Network Designer (Computer Vision Toolbox).

Create Image-to-Image Regression Network

Image-to-image regression involves taking an input image and producing an output image, often of the same size. This type of network is useful for super-resolution, colorization, or image deblurring.

You can create image-to-image regression networks using Deep Network Designer. For example, create a simple network architecture suitable for image-to-image regression using the unetLayers function from Computer Vision Toolbox™. This function provides a network suitable for semantic segmentation, that can be easily adapted for image-to-image regression.

Create a network with input size 28-by-28-by-1 pixels.

layers = unetLayers([28,28,1],2,'encoderDepth',2);
deepNetworkDesigner(layers);

In the Designer pane, replace the softmax and pixel classification layers with a regression layer from the Layer Library.

Diagram of the conversion of a pixel classification network into an image-to-image regression network. The final two layers of the classification network, a softmax layer and a pixel classification layer, are replaced by a regression layer.

Select the final convolutional layer and set the NumFilters property to 1.

Convolutional 2-D layer selected in Deep Network Designer. The Properties pane shows NumFilters set to 1.

For more information on constructing and training an image-to-image regression network, see Image-to-Image Regression in Deep Network Designer.

Build dlnetwork

You can build and analyze dlnetwork objects using Deep Network Designer. A dlnetwork object enables support for training using the trainnet function or a custom training loop. Use custom training loops when the built-in training options do not provide the training options that you need for your task. To open Deep Network Designer in dlnetwork mode, use the syntax

deepNetworkDesigner(net)
where net is a dlnetwork object.

Training with trainnet or a custom training loop is not supported in Deep Network Designer. To train your network, you must export the network to the workspace.

Check Network

To check your network and examine the layers in further detail, on the Designer tab, click Analyze. Investigate problems and examine the layer properties to resolve size mismatches in the network. Return to Deep Network Designer to edit layers, then check the results by clicking Analyze again. If Deep Learning Network Analyzer reports zero errors, then the edited network is ready for training.

Deep Learning Network Analyzer showing zero warnings or errors.

You can also analyze networks for custom training and trainnet workflows. To analyze the network for usage with dlnetwork objects, open Deep Network Designer with a dlnetwork and then click Analyze. For example, the Network Analyzer checks that the layer graph does not have any output layers.

See Also

Related Topics