removeLayers
Remove layers from neural network
Description
removes the layers specified by netUpdated
= removeLayers(net
,layerNames
)layerNames
from the
dlnetwork
object net
. The function also
removes any connections to the removed layers.
Examples
Remove Layer from Neural Network
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)
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)
Input Arguments
net
— Neural network
dlnetwork
object
Neural network, specified as a dlnetwork
object.
layerNames
— Names of layers to remove
character vector | cell array of character vectors | string array
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
netUpdated
— Updated network
dlnetwork
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 R2017bR2024a: LayerGraph
objects are not recommended
Starting in R2024a, LayerGraph
objects are not recommended. Use
dlnetwork
objects instead. This
recommendation means that this syntax is not recommended for
LayerGraph
input:
lgraphUpdated = removeLayers(lgraph,layerNames)
Most functions that support LayerGraph
objects also support
dlnetwork
objects. This table shows some typical usages of
LayerGraph
objects and how to update your code to use
dlnetwork
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.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)