disconnectLayers - Disconnect layers in neural network - MATLAB (original) (raw)

Disconnect layers in neural network

Syntax

Description

[netUpdated](#mw%5F21023cfa-3dea-4063-ae19-d905a3f1188d%5Fsep%5Fmw%5F5956ea1d-4747-411e-8acc-7424b78ab717) = disconnectLayers([net](#mw%5F21023cfa-3dea-4063-ae19-d905a3f1188d%5Fsep%5Fmw%5F3ffb42b3-6af7-4c22-82b3-4fb0f6a399f2),[s](#d126e80749),[d](#d126e80790)) disconnects the source layer s from the destination layerd in the dlnetwork objectnet. The updated network, netUpdated, contains the same layers as net, but excludes the connection between s and d.

example

Examples

collapse all

Create a simple neural network and display it in a plot.

net = dlnetwork;

layers = [ imageInputLayer([28 28 1])
convolution2dLayer(3,16,Padding="same") batchNormalizationLayer reluLayer];

net = addLayers(net,layers); figure plot(net)

Figure contains an axes object. The axes object contains an object of type graphplot.

Disconnect the layer with the names "conv" and "batchnorm".

net = disconnectLayers(net,"conv","batchnorm");

Display the updated network in a plot.

Figure contains an axes object. The axes object contains an object of type graphplot.

Input Arguments

collapse all

Neural network, specified as a dlnetwork object.

Connection source, specified as a character vector or a string scalar.

Example: "conv"

Example: "mpool/indices"

Connection destination, specified as a string scalar or a character vector.

Example: "fc"

Example: "add/in1"

Output Arguments

collapse all

Updated network, returned as an uninitialized dlnetwork object.

To initialize the learnable parameters of a dlnetwork object, use the initialize function.

The disconnectLayers function does not preserve quantization information. If the input network is a quantized network, then the output network does not contain quantization information.

Version History

Introduced in R2017b

expand all

Starting in R2024a, LayerGraph objects are not recommended. Usedlnetwork objects instead. This recommendation means that this syntax is not recommended forLayerGraph input:

Most functions that support LayerGraph objects also supportdlnetwork objects. This table shows some typical usages ofLayerGraph objects and how to update your code to usedlnetwork object functions instead.

Not Recommended Recommended
lgraph = layerGraph; net = dlnetwork;
lgraph = layerGraph(layers); net = dlnetwork(layers,Initialize=false);
lgraph = layerGraph(net); net = dag2dlnetwork(net);
lgraph = addLayers(lgraph,layers); net = addLayers(net,layers);
lgraph = removeLayers(lgraph,layerNames); net = removeLayers(net,layerNames);
lgraph = replaceLayer(lgraph,layerName,layers); net = replaceLayer(net,layerName,layers);
lgraph = connectLayers(lgraph,s,d); net = connectLayers(net,s,d);
lgraph = disconnectLayers(lgraph,s,d); net = disconnectLayers(net,s,d);
plot(lgraph); plot(net);

To train a neural network specified as a dlnetwork object, use the trainnet function.