getLayer
Description
Examples
Define a simple network architecture and display the network in a plot.
net = dlnetwork;
layers = [
imageInputLayer([28 28])
convolution2dLayer(3,16,Padding="same")
reluLayer
fullyConnectedLayer(10)
softmaxLayer];
net = addLayers(net,layers);
figure
plot(net)
Look up the convolution layer by name. You can then edit the layer and replace it using the getLayer function.
convLayer = getLayer(net,"conv")convLayer =
Convolution2DLayer with properties:
Name: 'conv'
Hyperparameters
FilterSize: [3 3]
NumChannels: 'auto'
NumFilters: 16
Stride: [1 1]
DilationFactor: [1 1]
PaddingMode: 'same'
PaddingSize: []
PaddingValue: 0
Learnable Parameters
Weights: []
Bias: []
Show all properties
If you know the index of the layer, you can alternatively look it up by index.
convLayer = net.Layers(2);
Define a network architecture containing several network layers.
net = dlnetwork;
layers = [lstmLayer(100,OutputMode="sequence")
dropoutLayer(0.2)];
lstmDropoutLayer = networkLayer(layers);
layers = [sequenceInputLayer(3)
lstmDropoutLayer
lstmDropoutLayer
fullyConnectedLayer(10)
softmaxLayer];
net = addLayers(net,layers);Plot the network.
figure plot(net)

Look up the first LSTM layer by specifying the path to the layer. The path includes the name of the network layer ("subnet_1") and the name of the LSTM layer ("lstm"), separated by a forward slash. You can use the path to look up layers nested within a hierarchy of multiple network layers.
tempLSTMLayer = getLayer(net,"subnet_1/lstm");Edit properties of the layer, and replace the original layer with the modified layer.
tempLSTMLayer.InputWeightsInitializer = "zeros"; tempLSTMLayer.RecurrentWeightsInitializer = "zeros"; tempLSTMLayer.BiasInitializer = "ones"; tempLSTMLayer.Name = "modifiedLSTM";
Replace the original layer with the modified layer, specifying the network, the path to the layer to replace, and the modified layer.
net = replaceLayer(net,"subnet_1/lstm",tempLSTMLayer);Input Arguments
Neural network, specified as a dlnetwork object.
Name of layer to look up, specified as a character vector or string scalar.
Example: "conv1"
Data Types: char | string
Path to nested layer, specified as a character vector or string scalar.
For a layer within a networkLayer,
specify layerPath as:
The name of the network layer and the name of the nested layer separated by a forward slash
"/". For example, the path to a layer named"nestedLayerName"in a network layer named"networkLayerName"is"networkLayerName/nestedLayerName". If there are multiple levels of nested layers, then specify the path using the formnetworkLayerName1/.../networkLayerNameN/nestedLayerName.
Custom layers can have a dlnetwork as a learnable or state property. For a
layer of a dlnetwork in the property of a custom layer, specify
layerPath as:
The name of the custom layer, the name of the
dlnetworkproperty, and the name of the nested layer separated by forward slashes"/". For example, the path to a layer named"layerName"inside adlnetworkproperty named"propertyName"of a custom layer named"customLayerName"is"customLayerName/propertyName/layerName". If there are multiple levels of nested layers, then specify the path using the form"customLayerName1/propertyName1/.../customLayerNameN/propertyNameN/layerName".
Data Types: char | string
Version History
Introduced in R2024a
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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)