Main Content

removeLayers

Remove layers from layer graph or network

Description

example

lgraphUpdated = removeLayers(lgraph,layerNames) removes the layers specified by layerNames from the layer graph lgraph. The function also removes any connections to the removed layers.

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.

Examples

collapse all

Create a layer graph from an array of layers.

layers = [
    imageInputLayer([28 28 1],'Name','input')  
    convolution2dLayer(3,16,'Padding','same','Name','conv_1')
    batchNormalizationLayer('Name','BN_1')
    reluLayer('Name','relu_1')];

lgraph = layerGraph(layers);
figure
plot(lgraph)

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

Remove the 'BN_1' layer and its connections.

lgraph = removeLayers(lgraph,'BN_1');
figure
plot(lgraph)

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

Input Arguments

collapse all

Layer graph, specified as a LayerGraph object. To create a layer graph, use layerGraph.

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 layer graph, specify the name of the layer.

To remove multiple layers, specify the layer names in an array, where each element of the array is a layer name.

Example: 'conv1'

Example: {'conv1','add1'}

Output Arguments

collapse all

Updated layer graph, returned as a LayerGraph object.

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