Main Content

Layer

Network layer for deep learning

Description

Layers that define the architecture of neural networks for deep learning.

Creation

For a list of deep learning layers in MATLAB®, see List of Deep Learning Layers. To specify the architecture of a neural network with all layers connected sequentially, create an array of layers directly. To specify the architecture of a network where layers can have multiple inputs or outputs, use a dlnetwork object.

Alternatively, you can import layers from Caffe, Keras, and ONNX using importCaffeLayers, importKerasLayers, and importONNXLayers respectively.

To learn how to create your own custom layers, see Define Custom Deep Learning Layers.

Examples

collapse all

Define a convolutional neural network architecture for classification with one convolutional layer, a ReLU layer, and a fully connected layer.

layers = [ ...
    imageInputLayer([28 28 3])
    convolution2dLayer([5 5],10)
    reluLayer
    fullyConnectedLayer(10)
    softmaxLayer
    classificationLayer]
layers = 
  6x1 Layer array with layers:

     1   ''   Image Input             28x28x3 images with 'zerocenter' normalization
     2   ''   2-D Convolution         10 5x5 convolutions with stride [1  1] and padding [0  0  0  0]
     3   ''   ReLU                    ReLU
     4   ''   Fully Connected         10 fully connected layer
     5   ''   Softmax                 softmax
     6   ''   Classification Output   crossentropyex

layers is a Layer object.

Alternatively, you can create the layers individually and then concatenate them.

input = imageInputLayer([28 28 3]);
conv = convolution2dLayer([5 5],10);
relu = reluLayer;
fc = fullyConnectedLayer(10);
sm = softmaxLayer;
co = classificationLayer;

layers = [ ...
    input
    conv
    relu
    fc
    sm
    co]
layers = 
  6x1 Layer array with layers:

     1   ''   Image Input             28x28x3 images with 'zerocenter' normalization
     2   ''   2-D Convolution         10 5x5 convolutions with stride [1  1] and padding [0  0  0  0]
     3   ''   ReLU                    ReLU
     4   ''   Fully Connected         10 fully connected layer
     5   ''   Softmax                 softmax
     6   ''   Classification Output   crossentropyex

Define a convolutional neural network architecture for classification with one convolutional layer, a ReLU layer, and a fully connected layer.

layers = [ ...
    imageInputLayer([28 28 3])
    convolution2dLayer([5 5],10)
    reluLayer
    fullyConnectedLayer(10)
    softmaxLayer];

Display the image input layer by selecting the first layer.

layers(1)
ans = 
  ImageInputLayer with properties:

                      Name: ''
                 InputSize: [28 28 3]
        SplitComplexInputs: 0

   Hyperparameters
          DataAugmentation: 'none'
             Normalization: 'zerocenter'
    NormalizationDimension: 'auto'
                      Mean: []

View the input size of the image input layer.

layers(1).InputSize
ans = 1×3

    28    28     3

Display the stride for the convolutional layer.

layers(2).Stride
ans = 1×2

     1     1

Access the bias learn rate factor for the fully connected layer.

layers(4).BiasLearnRateFactor
ans = 
1

Version History

Introduced in R2016a