networkLayer
Description
A network layer contains a nested network. Use network layers to simplify building large networks that contain repeating components.
During training and inference a network layer behaves identically to the nested network.
Tip
To visualize a network layer, use Deep Network Designer.
To see inside the layer, double click the layer. To edit the layers in Deep Network
Designer, you must first expand the network using the expandLayers
function before opening the network in the app. After editing the network and exporting it
to the workspace, you can regroup the layers into network layers using the groupLayers
function. Adding a network layer to a network in Deep Network Designer is not
supported.
Creation
Description
sets writable properties using on or more name-value arguments. For example,
layer = networkLayer(___,Name=Value)Name="myNetworkLayer" sets the name of the network layer.
Input Arguments
Name-Value Arguments
Properties
Examples
More About
Tips
To get output from a layer inside a
networkLayerusing thepredict,minibatchpredict, andforwardfunctions, do one of the following:When you create the
networkLayer, specify its outputs using theOutputNamesoption. For an example, see Create Image Feature Extractor Layer.If your network already contains a
networkLayer, then expand the network layer, set theOutputNamesproperty of the network, then regroup the layers.For example, create a network that contains a
networkLayer.net = resnetNetwork([64 64],10); net = groupLayers(net);
To get the network output from the 2-D convolutional layer
"conv2"that is nested inside the"block1"network layer, which itself is nested inside the"stack3"network layer, expand the two network layers, set theOutputNamesproperty of the network to the desired output, then regroup the network layers. When you make predictions using the networknet, MATLAB® returns output from the specified convolutional layer.net = expandLayers(net); net.OutputNames = "stack3:block1:conv2"; net = groupLayers(net);To avoid expanding other layers with the
expandLayersfunctions, specify the layers to expand and turn off recursive expansion.net = expandLayers(net,"stack1",Recursive=false);To avoid grouping other layers with the
groupLayersfunction, specify the layers to group.net = groupLayers(net,["stack3:block1""stack3:block2"]);
Version History
Introduced in R2024a




