Main Content

removeLayers

Remove layers from neural network

Description

netUpdated = removeLayers(net,layerNames) removes the layers specified by layerNames from the dlnetwork object net. The function also removes any connections to the removed layers.

example

Examples

collapse all

Create a simple neural network and display the network 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.

Remove the layer that has the name "batchnorm" and its connections. Display the updated network in a plot.

net = removeLayers(net,"batchnorm");
figure
plot(net)

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.

Names of layers to remove, specified as a character vector, a cell array of character vectors, or a string array.

To remove a single layer from the network, specify the name of the layer.

To remove multiple layers, specify the layer names in a string array or cell array of character vectors, where each element of the array is a layer name.

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 removeLayers 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