removeLayers

Remove layers from layer graph

Syntax

newlgraph = removeLayers(lgraph,layerNames)

Description

example

newlgraph = removeLayers(lgraph,layerNames) removes the layers specified by layerNames from the layer graph lgraph. 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)

Remove the 'BN_1' layer and its connections.

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

Input Arguments

collapse all

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

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

To remove a single layer from the layer graph, specify the name of the layer as a character vector.

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

Example: 'conv1'

Example: {'conv1','add1'}

Output Arguments

collapse all

Output layer graph, returned as a LayerGraph object.

Introduced in R2017b