Main Content

构建深度神经网络

使用命令行函数或以交互方式使用深度网络设计器构建网络

使用 MATLAB® 代码或以交互方式使用深度网络设计器从头开始构建网络。使用内置层为分类和回归等任务构建网络。要查看内置层的列表,请参阅深度学习层列表。然后,您可以分析您的网络以了解网络架构,并在训练前检查问题。

如果内置层没有提供您的任务所需的层,则您可以定义自己的自定义深度学习层。您可以定义具有可学习参数和状态参数的自定义层。定义自定义层后,您可以检查该层是否有效,是否与 GPU 兼容,以及是否输出正确定义的梯度。

对于无法指定为由层组成的网络的模型,可以将模型定义为函数。有关如何训练定义为函数的深度学习模型的示例,请参阅Train Network Using Model Function

App

深度网络设计器设计和可视化深度学习网络

函数

全部展开

输入层

inputLayerInput layer (自 R2023b 起)
imageInputLayerImage input layer
image3dInputLayer3-D image input layer
sequenceInputLayerSequence input layer
featureInputLayerFeature input layer (自 R2020b 起)

卷积和全连接层

convolution2dLayer2-D convolutional layer
convolution3dLayer3-D convolutional layer
groupedConvolution2dLayer2-D grouped convolutional layer
transposedConv2dLayerTransposed 2-D convolution layer
transposedConv3dLayerTransposed 3-D convolution layer
fullyConnectedLayerFully connected layer

循环层

lstmLayerLong short-term memory (LSTM) layer for recurrent neural network (RNN)
bilstmLayerBidirectional long short-term memory (BiLSTM) layer for recurrent neural network (RNN)
gruLayerGated recurrent unit (GRU) layer for recurrent neural network (RNN) (自 R2020a 起)
lstmProjectedLayerLong short-term memory (LSTM) projected layer for recurrent neural network (RNN) (自 R2022b 起)
gruProjectedLayerGated recurrent unit (GRU) projected layer for recurrent neural network (RNN) (自 R2023b 起)

变换器层

selfAttentionLayerSelf-attention layer (自 R2023a 起)
attentionLayerDot-product attention layer (自 R2024a 起)
positionEmbeddingLayerPosition embedding layer (自 R2023b 起)
sinusoidalPositionEncodingLayerSinusoidal position encoding layer (自 R2023b 起)
embeddingConcatenationLayerEmbedding concatenation layer (自 R2023b 起)
indexing1dLayer1-D indexing layer (自 R2023b 起)

神经 ODE 层

neuralODELayerNeural ODE layer (自 R2023b 起)

激活层

reluLayer修正线性单元 (ReLU) 层
leakyReluLayerLeaky Rectified Linear Unit (ReLU) layer
preluLayerParametrized Rectified Linear Unit (PReLU) layer (自 R2024a 起)
clippedReluLayerClipped Rectified Linear Unit (ReLU) layer
eluLayerExponential linear unit (ELU) layer
tanhLayer双曲正切 (tanh) 层
swishLayerSwish layer (自 R2021a 起)
geluLayerGaussian error linear unit (GELU) layer (自 R2022b 起)
softmaxLayerSoftmax 层
sigmoidLayerSigmoid layer (自 R2020b 起)
functionLayerFunction layer (自 R2021b 起)

归一化层

batchNormalizationLayerBatch normalization layer
groupNormalizationLayerGroup normalization layer (自 R2020b 起)
instanceNormalizationLayerInstance normalization layer (自 R2021a 起)
layerNormalizationLayerLayer normalization layer (自 R2021a 起)
crossChannelNormalizationLayer Channel-wise local response normalization layer

实用工具层

dropoutLayer丢弃层
spatialDropoutLayerSpatial dropout layer (自 R2024a 起)
flattenLayerFlatten layer
crop2dLayer2-D crop layer
crop3dLayer3-D crop layer (自 R2019b 起)
networkLayerNetwork Layer (自 R2024a 起)

池化和去池化层

averagePooling2dLayerAverage pooling layer
averagePooling3dLayer3-D average pooling layer
adaptiveAveragePooling2dLayerAdaptive average pooling 2-D layer (自 R2024a 起)
globalAveragePooling2dLayer2-D global average pooling layer (自 R2019b 起)
globalAveragePooling3dLayer3-D global average pooling layer (自 R2019b 起)
globalMaxPooling2dLayerGlobal max pooling layer (自 R2020a 起)
globalMaxPooling3dLayer3-D global max pooling layer (自 R2020a 起)
maxPooling2dLayerMax pooling layer
maxPooling3dLayer3-D max pooling layer
maxUnpooling2dLayerMax unpooling layer

组合层

additionLayerAddition layer
multiplicationLayerMultiplication layer (自 R2020b 起)
concatenationLayerConcatenation layer
depthConcatenationLayerDepth concatenation layer
dlnetworkDeep learning neural network (自 R2019b 起)
imagePretrainedNetworkPretrained neural network for images (自 R2024a 起)
resnetNetwork2-D residual neural network (自 R2024a 起)
resnet3dNetwork3-D residual neural network (自 R2024a 起)
addLayersAdd layers to neural network
removeLayersRemove layers from neural network
replaceLayerReplace layer in neural network
getLayerLook up a layer by name or path (自 R2024a 起)
connectLayersConnect layers in neural network
disconnectLayersDisconnect layers in neural network
expandLayersExpand network layers (自 R2024a 起)
groupLayersGroup layers into network layers (自 R2024a 起)
analyzeNetworkAnalyze deep learning network architecture
addInputLayerAdd input layer to network (自 R2022b 起)
initializeInitialize learnable and state parameters of a dlnetwork (自 R2021a 起)
networkDataLayoutDeep learning network data layout for learnable parameter initialization (自 R2022b 起)
setL2FactorSet L2 regularization factor of layer learnable parameter
getL2FactorGet L2 regularization factor of layer learnable parameter
setLearnRateFactorSet learn rate factor of layer learnable parameter
getLearnRateFactorGet learn rate factor of layer learnable parameter
dag2dlnetworkConvert SeriesNetwork and DAGNetwork to dlnetwork (自 R2024a 起)
plot绘制神经网络架构
summaryPrint network summary (自 R2022b 起)
analyzeNetworkAnalyze deep learning network architecture
checkLayerCheck validity of custom or function layer
isequalCheck equality of neural networks (自 R2021a 起)
isequalnCheck equality of neural networks ignoring NaN values (自 R2021a 起)

主题

内置层

自定义层