The Deep Network Designer app enables you to generate MATLAB® code that recreates the building, editing, and training of a network in the app.
In the Designer tab, you can generate a live script to:
Recreate the layers in your network. Select Export > Generate Code.
Recreate the layers in your network, including any initial parameters. Select Export > Generate Code with Initial Parameters.
In the Training tab, you can generate a live script to:
Recreate the building and training of an image classification network you construct in Deep Network Designer. Select Export > Generate Code for Training.
Generate MATLAB code for recreating the network constructed in Deep Network Designer. In the Designer tab, choose one of these options:
To recreate the layers in your network, select Export > Generate Code. This network does not contain initial parameters, such as pretrained weights.
To recreate the layers in your network, including any initial parameters, select Export > Generate Code with Initial 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.
Running the generated script returns the network architecture as a variable in the
workspace. Depending on the network architecture, the variable is a layer graph named
lgraph
or a layer array named layers
.
You can supply the generated layer graph or layer array to the
trainNetwork
function. For example, assume that the layers produced
by the generated code are named lgraph_1
, the images are in an augmented
image datastore called images
and options
contains the
training options. To train the network,
type:
trainedNet = trainNetwork(images,lgraph_1,options)
To recreate the construction and training of an image classification network in Deep Network Designer, generate MATLAB code. For an example of using Deep Network Designer to train a network, see Transfer Learning with Deep Network Designer.
Once training is complete, on the Training tab, select Export > Generate Code for Training. The app creates a live script and a MAT-file containing the initial parameters (weights and biases) from your network. If you import data as an image datastore then this is also contained in the generated MAT-file.
Running the generated script builds the network (including the learnable parameters from the MAT-file), imports the data, sets the training options, and trains the network. Examine the generated script to learn how to construct and train a network at the command line.
Suppose that the trained network is contained in the variable net
.
To use the trained image classification network for prediction, use the
predict
function. For example, use the network to predict the class
of peppers.png
.
img = imread("peppers.png");
img = imresize(img, net.Layers(1).InputSize(1:2));
label = predict(net, img);
imshow(img);
title(label);
[1] Kudo, Mineichi, Jun Toyama, and Masaru Shimbo. “Multidimensional Curve Classification Using Passing-through Regions.” Pattern Recognition Letters 20, no. 11–13 (November 1999): 1103–11. https://doi.org/10.1016/S0167-8655(99)00077-X.
[2] Kudo, Mineichi, Jun Toyama, and Masaru Shimbo. Japanese Vowels Data Set. Distributed by UCI Machine Learning Repository. https://archive.ics.uci.edu/ml/datasets/Japanese+Vowels.
Deep Network Designer | trainNetwork
| trainingOptions