主要内容

德ep Network Designer

德sign, visualize, and train deep learning networks

Since R2018b

德scription

The德ep Network Designerapp 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.

Open the Deep Network Designer App

  • MATLAB Toolstrip: On theAppstab, underMachine Learning and Deep Learning, click the app icon.

  • MATLAB command prompt: EnterdeepNetworkDesigner.

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德signertab and clickingNew. If you need to download the network, then clickInstallto 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, seePretrained Deep Neural Networks.

德ep Network Designer start page showing available networks

In the德signerpane, visualize and explore the network. For a list of available pretrained image classification networks and how to compare them, seePretrained Deep Neural Networks.

德ep Network Designer displaying a pretrained image classification network

For information on constructing networks using Deep Network Designer, seeBuild 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 newconvolution2dLayeronto the canvas. Set theFilterSizeproperty to1,1and theNumFiltersproperty 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 theWeightLearnRateFactorandBiasLearnRateFactorvalues.

  • 德lete the lastconvolution2dLayerand 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 theOutputSizeproperty to the new number of classes. For an example, seeGet Started with Deep Network Designer.

Next, delete the classification output layer. Then, drag a newclassificationLayeronto 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 clickingAnalyzein the德signertab. The network is ready for training if德ep Learning Network Analyzerreports zero errors. For an example showing how to train a network to classify new images, seeTransfer Learning with Deep Network Designer.

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

On the德signerpane, 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, seeList 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 theLayer Libraryto the德signerpane and connecting them. You can also add custom layers from the workspace to a network in the德signerpane. Suppose that you have a custom layer stored in the variablemyCustomLayer.

  1. ClickNewin the德signertab.

  2. 暂停上From Workspaceand clickImport.

  3. SelectmyCustomLayerand clickOK.

  4. ClickAdd.

The app adds the custom layer to the top of the德signerpane. To see the new layer, zoom-in using a mouse or clickZoom in.

ConnectmyCustomLayerto the network in the德signerpane. For an example showing how build a network with a custom layer in Deep Network Designer, seeImport 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 clickEdit Layer Code. For more information, seeView Autogenerated Custom Layers Using Deep Network Designer.(since R2023a)

Import data into Deep Network Designer for training.

You can use theDatatab 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.

Task Data Type Data Import Method Example Visualization
Image classification

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

SelectImport 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, seeImport 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 thetrainNetworkfunction. For more information about constructing and using datastore objects for deep learning applications, seeDatastores for Deep Learning.

SelectImport Data>Import Custom Data.

Import Datastore dialog box

You can specify the validation data in the Import Custom Data dialog box. For more information, seeImport 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 thetrainNetworkfunction. For example, you can train a semantic segmentation network or a multi-input network using aCombinedDatastoreobject. For more information about importing data into Deep Network Designer, seeImport Data into Deep Network Designer.

To train a network on data imported into Deep Network Designer, on theTrainingtab, clickTrain. 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 buttonin 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, seeTrain Networks Using Deep Network Designer.

If you require greater control over the training, click培训方案to select the training settings. For more information about selecting training options, seetrainingOptions.

培训方案dialog box in Deep Network Designer

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

To train a network on data not supported by Deep Network Designer, select the德signertab, and clickExportto 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德signertab, clickExport. Depending on the network architecture, Deep Network Designer exports the network as aLayerGraphlgraphor as aLayerobjectlayers.

  • To export the network trained in Deep Network Designer to the workspace, on theTrainingtab, clickExport. Deep Network Designer exports the trained network architecture as aDAGNetworkobjecttrainedNetwork. Deep Network Designer also exports the results from training, such as training and validation accuracy, as the structure arraytrainInfoStruct.

  • To export the network trained in Deep Network Designer to Simulink, on theTrainingtab, clickExport>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从深Netw导出图像分类网络ork 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德signertab, selectExport>Generate Code.

  • To recreate the network layers, including any learnable parameters, on the德signertab, selectExport>Generate Code with Initial Parameters.

  • To recreate the network, data import, and training, on theTrainingtab, selectExport>生成代码的训练.

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, seeGenerate 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 useExperiment Managerto tune the hyperparameters of a network trained in Deep Network Designer, seeGenerate Experiment Using Deep Network Designer.

Related Examples

Programmatic Use

expand all

deepNetworkDesigneropens the Deep Network Designer app. If Deep Network Designer is already open,deepNetworkDesignerbrings 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(净)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, tryExperiment Manager. You can use Deep Network Designer to create experiments suitable for Experiment Manager.

Version History

Introduced in R2018b

Baidu
map