Import Custom Layer into Deep Network Designer
This example shows how to import a custom classification output layer with the sum of squares error (SSE) loss and add it to a pretrained network in Deep Network Designer.
Define a custom classification output layer. To create this layer, save the file
sseClassificationLayer.m in the current folder. For more information on constructing this layer, see Define Custom Classification Output Layer.
Create an instance of the layer.
sseClassificationLayer = sseClassificationLayer('sse');
Open Deep Network Designer with a pretrained GoogLeNet network.
To adapt a pretrained network, edit the last learnable layer and the final classification layer to the new data set. In GoogLeNet, these layers have the names
In the Designer tab, click the final fully connected layer,
'loss3-classifier'. At the bottom of the Properties pane, click Unlock Layer. In the warning dialog that appears, click Unlock Anyway. This unlocks the layer properties so that you can adapt them to your new task.
Before R2023b: To edit the layer properties, you must replace the layers instead of unlocking them.
OutputSize to the number of classes in the new data, in this example, 2.
Edit learning rates to learn faster in the new layers than in the transferred layers. Set
Next, replace the output layer with your custom classification output layer. Click New in the Designer pane. Pause on From Workspace and click Import. To import the custom classification layer, select
sseClassificationLayer and click OK.
Add the layer to the current GoogLeNet pretrained network by clicking 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.
Drag the custom layer to the bottom of the Designer pane. Replace the output layer with the new classification output layer and connect the new layer.
To view or edit the custom layer, click Edit Layer Code.
Check your network by clicking Analyze. The network is ready for training if Deep Learning Network Analyzer reports zero errors.
After you construct your network, you are ready to import data and train. For more information on importing data and training in Deep Network Designer, see Transfer Learning with Deep Network Designer.
- View Autogenerated Custom Layers Using Deep Network Designer
- Build Networks with Deep Network Designer
- Import Data into Deep Network Designer
- Create Simple Sequence Classification Network Using Deep Network Designer
- Transfer Learning with Deep Network Designer
- Generate MATLAB Code from Deep Network Designer