identityLayer
Description
An identity layer is a layer whose output is identical to its input. You can use an identity layer to create a skip connection, which allows the input to skip one or more layers in the main branch of a neural network. For more information about skip connections, see More About.
Creation
Description
Input Arguments
Properties
This property is read-only.
Number of inputs to the layer, stored as 1
. This layer accepts a
single input only.
Data Types: double
This property is read-only.
Input names, stored as {'in'}
. This layer accepts a single input
only.
Data Types: cell
This property is read-only.
Number of outputs from the layer, stored as 1
. This layer has a
single output only.
Data Types: double
This property is read-only.
Output names, stored as {'out'}
. This layer has a single output
only.
Data Types: cell
Examples
Include an identity layer in a layer array.
layers = [ ...
imageInputLayer([28 28 1])
convolution2dLayer(5,20)
identityLayer
maxPooling2dLayer(2,Stride=2)
fullyConnectedLayer(10)
softmaxLayer]
layers = 6×1 Layer array with layers: 1 '' Image Input 28×28×1 images with 'zerocenter' normalization 2 '' 2-D Convolution 20 5×5 convolutions with stride [1 1] and padding [0 0 0 0] 3 '' Identity Identity 4 '' 2-D Max Pooling 2×2 max pooling with stride [2 2] and padding [0 0 0 0] 5 '' Fully Connected 10 fully connected layer 6 '' Softmax softmax
The third layer in layers
is an IdentityLayer
object that contains the properties of the identity layer.
Display the properties of the identity layer.
layers(3)
ans = IdentityLayer with properties: Name: ''
Create a deep learning neural network that includes residual blocks and an identity layer. For more information about residual neural networks, see More About.
Define Block Architecture
Write a function that returns a network layer representing a residual block.
function resblock = residualBlockLayer(name) reslayers = dlnetwork; layers = [ identityLayer(Name="split") convolution2dLayer(3,32,Padding="same") batchNormalizationLayer reluLayer convolution2dLayer(3,32,Padding="same") batchNormalizationLayer additionLayer(2,Name="add") reluLayer]; reslayers = addLayers(reslayers,layers); reslayers = connectLayers(reslayers,"split","add/in2"); resblock = networkLayer(reslayers,Name=name); end
The residualBlockLayer
function accepts a layer name and returns a networkLayer
object representing a residual block. The function uses identityLayer
with the connectLayers
function to create a skip connection between the input of the residual block and the second input of its final layer.
Create and Analyze Residual Network
Create a residual network using residualBlockLayer
to generate the residual blocks.
layers = [ imageInputLayer([224 224 3]) convolution2dLayer(7,32,Stride=2,Padding="same") batchNormalizationLayer reluLayer maxPooling2dLayer(3,Stride=2) residualBlockLayer("resBlock1") residualBlockLayer("resBlock2") globalAveragePooling2dLayer fullyConnectedLayer(5) softmaxLayer]; resnet = dlnetwork(layers)
resnet = dlnetwork with properties: Layers: [10×1 nnet.cnn.layer.Layer] Connections: [9×2 table] Learnables: [22×3 table] State: [10×3 table] InputNames: {'imageinput'} OutputNames: {'softmax'} Initialized: 1 View summary with summary.
resnet
is a dlnetwork
object that represents a residual network. resnet
contains two networkLayer
objects corresponding to two residual blocks.
Inspect Network
Use the expandLayers
and analyzeNetwork
functions to inspect the residual block layers in the Deep Network Designer app. The leftmost pane in Deep Network Designer shows the network layers and their connections.
xresnet = expandLayers(resnet); analyzeNetwork(xresnet)
The names of the layers inside the first and second residual blocks begin with resBlock1:
and resBlock2:
, respectively. The first layer inside each block is an identity layer that accepts input from outside the residual block. Each identity layer has a skip connection to an addition layer. The names of the identity layers are resBlock1:split
and resBlock2:split
, and the names of the addition layers are resBlock1:add
and resBlock2:add
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Version History
Introduced in R2024b
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)