Build Networks with Deep Network Designer - MATLAB & Simulink (original) (raw)

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

  1. Click New.
  2. Pause on From Workspace and clickImport.
  3. Choose the layers or network to import and clickOK.
  4. Click Add to add the layers or network to theDesigner pane.

You can also load pretrained networks by clickingNew 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 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.

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

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

To check that the network is ready for training, clickAnalyze.

For an example showing how to retrain a pretrained network to classify new images, see Prepare Network for Transfer Learning Using 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 Adapt Pretrained Audio Network for New Data Using Deep Network Designer.

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];

deepNetworkDesigner(layers)

Image classification network in Deep Network Designer. The network starts with an image input layer and ends with a softmax 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 theOutputSize 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, seeGet Started with Image Classification.

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. In the Sequence-to-Label Networks (Untrained) section, pause on LSTM 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 softmax layer.

You can adapt this sequence network for training with your data. Suppose you have data with 10 features and 5 classes. To adapt this network, selectsequenceInputLayer and set the InputSize to 10.

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

Then, select the fullyConnectedLayer and set theOutputSize to 5, the number of classes.

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

For an example showing how to create and train a sequence classification network, seeGet Started with 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. You can also use the prebuilt multilayer perceptron (MLP) network from the start page. Open the Deep Network Designer start page. In the Feature Classification Networks (Untrained) section, pause on Multilayer Perceptron and click Open. Doing so opens a prebuilt network suitable for feature classification problems.

Feature classification network in Deep Network Designer. The network starts with a feature input layer and ends with a softmax 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 theOutputSize 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.

Convert Classification Network into Regression Network

You can convert a classification network into a regression network by adapting 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, remove the softmax layer and set theOutputSize of the final fully connected layer to 1 (the number of responses).

Diagram of the conversion of a classification network into a regression network. The final layer of the classification network, a softmax layer, is removed.

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

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, but 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 > . Click Add to add the layers to the current network.

Check Network

To check your network and examine the layers in further detail, clickAnalyze. 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.

See Also

Deep Network Designer | dlnetwork | trainnet

Topics