Main Content

Build Deep Neural Networks

Build networks using command-line functions or interactively using the Deep Network Designer app

Build networks from scratch using MATLAB® code or interactively using the Deep Network Designer app. Use built-in layers to construct networks for tasks such as classification and regression. To see a list of built-in layers, see List of Deep Learning Layers. You can then analyze your network to understand the network architecture and check for problems before training.

If the built-in layers do not provide the layer that you need for your task, then you can define your own custom deep learning layer. You can specify a custom loss function using a custom output layers and define custom layers with or without learnable parameters. After defining a custom layer, you can check that the layer is valid, GPU compatible, and outputs correctly defined gradients.

For networks that cannot be created using layer graphs, you can define a custom network as a function. For an example showing how to train a deep learning model defined as a function, see Train Network Using Model Function.


Deep Network DesignerProgetta, visualizza e addestra le reti di Deep Learning


espandi tutto

Input Layers

imageInputLayerImage input layer
image3dInputLayer3-D image input layer (Da R2019a)
sequenceInputLayerSequence input layer
featureInputLayerFeature input layer (Da R2020b)

Convolution and Fully Connected Layers

convolution2dLayer2-D convolutional layer
convolution3dLayer3-D convolutional layer (Da R2019a)
groupedConvolution2dLayer2-D grouped convolutional layer (Da R2019a)
transposedConv2dLayerTransposed 2-D convolution layer
transposedConv3dLayerTransposed 3-D convolution layer (Da R2019a)
fullyConnectedLayerFully connected layer

Recurrent Layers

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) (Da R2020a)
lstmProjectedLayerLong short-term memory (LSTM) projected layer for recurrent neural network (RNN) (Da R2022b)
gruProjectedLayerGated recurrent unit (GRU) projected layer for recurrent neural network (RNN) (Da R2023b)

Transformer Layers

selfAttentionLayerSelf-attention layer (Da R2023a)
positionEmbeddingLayerPosition embedding layer (Da R2023b)
sinusoidalPositionEncodingLayerSinusoidal position encoding layer (Da R2023b)
embeddingConcatenationLayerEmbedding concatenation layer (Da R2023b)
indexing1dLayer1-D indexing layer (Da R2023b)

Neural ODE Layers

neuralODELayerNeural ODE layer (Da R2023b)

Activation Layers

reluLayerLivello dell’unità lineare rettificata (ReLU)
leakyReluLayerLeaky Rectified Linear Unit (ReLU) layer
clippedReluLayerClipped Rectified Linear Unit (ReLU) layer
eluLayerExponential linear unit (ELU) layer (Da R2019a)
tanhLayerHyperbolic tangent (tanh) layer (Da R2019a)
swishLayerSwish layer (Da R2021a)
geluLayerGaussian error linear unit (GELU) layer (Da R2022b)
softmaxLayerLivello softmax
sigmoidLayerSigmoid layer (Da R2020b)
functionLayerFunction layer (Da R2021b)

Normalization Layers

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

Utility Layers

dropoutLayerDropout layer
crop2dLayer2-D crop layer
crop3dLayer3-D crop layer (Da R2019b)

Data Manipulation

sequenceFoldingLayerSequence folding layer (Da R2019a)
sequenceUnfoldingLayerSequence unfolding layer (Da R2019a)
flattenLayerFlatten layer (Da R2019a)

Pooling and Unpooling Layers

averagePooling2dLayerAverage pooling layer
averagePooling3dLayer3-D average pooling layer (Da R2019a)
globalAveragePooling2dLayer2-D global average pooling layer (Da R2019b)
globalAveragePooling3dLayer3-D global average pooling layer (Da R2019b)
globalMaxPooling2dLayerGlobal max pooling layer (Da R2020a)
globalMaxPooling3dLayer3-D global max pooling layer (Da R2020a)
maxPooling2dLayerMax pooling layer
maxPooling3dLayer3-D max pooling layer (Da R2019a)
maxUnpooling2dLayerMax unpooling layer

Combination Layers

additionLayerAddition layer
multiplicationLayerMultiplication layer (Da R2020b)
concatenationLayerConcatenation layer (Da R2019a)
depthConcatenationLayerDepth concatenation layer

Output Layers

classificationLayerLivello di output della classificazione
regressionLayerLivello di output della regressione
layerGraphGraph of network layers for deep learning
plotPlot neural network architecture
addLayersAdd layers to layer graph or network
removeLayersRemove layers from layer graph or network
replaceLayerReplace layer in layer graph or network
connectLayersConnect layers in layer graph or network
disconnectLayersDisconnect layers in layer graph or network
DAGNetworkDirected acyclic graph (DAG) network for deep learning
resnetLayersCreate 2-D residual network (Da R2021b)
resnet3dLayersCreate 3-D residual network (Da R2021b)
isequalCheck equality of deep learning layer graphs or networks (Da R2021a)
isequalnCheck equality of deep learning layer graphs or networks ignoring NaN values (Da R2021a)
analyzeNetworkAnalyze deep learning network architecture
resetStateReset state parameters of neural network
dlnetworkDeep learning network for custom training loops (Da R2019b)
addInputLayerAdd input layer to network (Da R2022b)
summaryPrint network summary (Da R2022b)
initializeInitialize learnable and state parameters of a dlnetwork (Da R2021a)
networkDataLayoutDeep learning network data layout for learnable parameter initialization (Da R2022b)
checkLayerCheck validity of custom or function layer
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


Built-In Layers

Custom Layers